-
String common operations
1. The key-value pair into a string
SET key value
2. The batch storage string key pair
MSET key value [key value ...]
3. Obtain a string key
GET key
4. Get string key Batch
MGET key [key ...]
5. Delete a key
DEL key [key ...]
6. Set a key expiration time (sec)
EXPIRE key seconds
-
Atomic addition and subtraction
1. The digital values stored in the key plus a
INCR key
2. The key digital value stored minus one
DECR key
3. The value of the stored key plus increment
INCRBY key increment
4. The value of the decrement is subtracted the stored key
DECRBY key decrement
-
Single-value cache
SET key value
GET key
-
Object Caching
1.SET user: 1 value (json format data)
2.MSET user:1:name test user:1:balance 10086
MGET user:1:name user:1:balance
-
Distributed Lock
SETNX product: 10001 true // returns 1 representative for the lock success SETNX product: 10001 true // returns 0 for failure to obtain a lock .... perform business operations DEL product: 10001 // executing the service releasing the lock SET product: 10001 true ex 10 nx // prevent the program terminated unexpectedly lead to deadlock
-
counter
INCR article:readcount:{文章id}
GET article:readcount:{文章id}
-
Web cluster shared session
spring session + redis achieve shared session
-
Global Distributed System serial number
// redis volume generated sequence number to improve performance INCRBY orderId 1000
hash
-
hash common operations
1. store a hash table key keys
HSET key field value
2. Obtain a key that does not exist in the hash table key
HSETNX key field value
3. A plurality of key-value pairs stored in a key in the hash table
HMSET key field value [field value ...]
4. Get the hash table key corresponding to the key field
HGET key field
5. Get Bulk hash table key field in a plurality of keys
HMGET key field [field ...]
6. Remove the key field in the hash table key
HDEL key field [field ..]
7. Return key in the hash table number field
SELECT key
8. Return key hash table all keys
HGETALL key
9. hash table key value in the key field plus the delta increment
HINCRBY key field increment
-
Object Caching (similar map)
HMSET user {userId}:name test {userId}:age 10 HMGET user 1:name 1:age
list
-
list common operations
1. The values of one or more key value is inserted into the list header (leftmost)
LPUSH key value [value ...]
2. The values of one or more key value is inserted into the end of the list of tables (rightmost)
RPUSH key value [value ...]
3. Remove the key and returns the first element of the list
LPOP key
4. Remove and returns a list of key elements Bito
RPOP key
5. Return the list of key elements in the specified interval, the interval to the specified start and stop offset
LRANGE key start stop
6. A key element from a pop up list header, if there are no elements in the list, blocking wait timeout seconds, if the timeout = 0, has been blocked waiting for
BLPOP key [key ...] timeout
7. pop up a list of key elements from the end of the table, if there are no elements in the list, block waiting timeout seconds, if the timeout = 0, has been blocked waiting for
BRPOP key [key ...] timeout
set
-
set common actions
1. The key to the collection is stored in the element, the element is ignored there is, if key does not exist, create a new SADD key member [member ...]
2. Delete key elements from the collection in SREM key member [member ...]
3. Get all the key elements in the collection of SMEMBERS key
4. Get the number of elements of the set of key SCARD key
5. Analyzing member element exists in the key set in SISMEMBER key member
6. elect count elements from the collection key, the key element is not is not removed from the SRANDMEMBER key [count]
7. elect count elements from the collection key, the key element is not removed from the SPOP key [count]
-
arithmetic operation set
1. intersecting operation SINTER [key ...]
2. The intersection results into a new set of destination in SINTERSTORE destination key [key ...]
And 3. Set operation SUNION key [key ...]
4. The result is stored and set in the new set destination SUNIONSTORE destination key [key ...]
The set difference operation SDIFF key [key ...]
6. The difference between the result set is stored in the new set destination SDIFFSTORE destionation key [key ...]
sorted Set(zSet)
Ordered set ( sorted set
) and set ( set
) do not allow duplicate members; the difference is a double score will be associated with each type of element; redis it is to small to large order of collection members by scores; orderly is the only member of the collection, the fraction ( score
), but may be repeated; zSet
the api and Set
the api is substantially the same;
1. Adding to the ordered set of one or more members, or update an existing member of the score
Key score1 the member1 Zadd [member2 is score2] 2. index interval returned by an ordered set of members in the specified range ZRANGE key start stop [WITHSCORES]
3. Remove ordered set of one or more members
ZREM key member [member ...]
4. Return members in the ordered set of the designated section by score
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT]
5. Return the index in the ordered set of specified members
ZRANK key member, wherein the member is incremented by the value of score (from ⼩ to max.)