Redis Redis data types and data type usage scenarios and scenarios using

And data type usage scenarios Redis

 

Redis KV compared to other databases, one major feature is support for rich data types. It supports a total of five kinds of data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set: an ordered set). About each of the five data types and their use internal implementation scenarios below.

String

 

Hash

Here Value is stored in a structured object, more convenient operation is a field therein.

Single sign-making time, is to use this data structure to store user information as to CookieId Key, set the cache expiration time of 30 minutes, can well simulate Session similar effect.

I used in the project:

// Get the token information from redis 
        Map returnMap = hashRedisCache.hget (tokenKey.concat (token ));

 

List

 List data structure, the function can do simple message queue. Another one is, you can use lrange command, do the Redis-based paging functionality, excellent performance, good user experience.

Set

Because Set is a collection of stacked pile of distinct values. So we can do a global deduplication functionality. Why not de-Set comes with JVM weight?

Because our systems are generally clustered deployment, use the built-in JVM Set, too much trouble, do not go for a re-do a global, renewed a public service, too much trouble.

Another is the use of the intersection, union, difference and other operations can be calculated together preferences, all preferences, their own unique preferences and other functions.

Sorted Set

Sorted Set more than a weight parameter Score, elements of a set can be arranged Score.

Charts can be applied, TOP N fetch operation. Sorted Set can be used for delay task. The last application is that you can do to find the range.

Redis KV compared to other databases, one major feature is support for rich data types. It supports a total of five kinds of data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set: an ordered set). About each of the five data types and their use internal implementation scenarios below.

String

 

Hash

Here Value is stored in a structured object, more convenient operation is a field therein.

Single sign-making time, is to use this data structure to store user information as to CookieId Key, set the cache expiration time of 30 minutes, can well simulate Session similar effect.

I used in the project:

// Get the token information from redis 
        Map returnMap = hashRedisCache.hget (tokenKey.concat (token ));

 

List

 List data structure, the function can do simple message queue. Another one is, you can use lrange command, do the Redis-based paging functionality, excellent performance, good user experience.

Set

Because Set is a collection of stacked pile of distinct values. So we can do a global deduplication functionality. Why not de-Set comes with JVM weight?

Because our systems are generally clustered deployment, use the built-in JVM Set, too much trouble, do not go for a re-do a global, renewed a public service, too much trouble.

Another is the use of the intersection, union, difference and other operations can be calculated together preferences, all preferences, their own unique preferences and other functions.

Sorted Set

Sorted Set more than a weight parameter Score, elements of a set can be arranged Score.

Charts can be applied, TOP N fetch operation. Sorted Set can be used for delay task. The last application is that you can do to find the range.

Guess you like

Origin www.cnblogs.com/sdfds99/p/11710619.html