data type | Data type stored value | explain |
STRING ( character string ) | It can be a save string 、 Integers and floating point numbers | You can manipulate strings , For example, add characters or substring ; Integers 、 Floating point numbers and so on can be used to calculate self increment |
LIST( list ) | It’s a linked list , Each of its nodes contains a string | Supports inserting and ejecting nodes from both ends of the list , Can be cropped by offset , Can read one or more nodes , You can delete or find nodes according to conditions |
SET( aggregate ) | It’s an unordered set , Every element in it is a string , And it doesn’t repeat . | You can add 、 Read 、 Delete single element ; Check whether the element is in the collection ; Calculate the set of intersection and union differences ; Elements can be read randomly from the collection |
HASH( Hash hash hash table ) | Be similar to java Medium Map, Is an unordered list of key value pairs | You can add, delete, or modify a single key value pair , All key value pairs can be obtained |
ZSET( Ordered set )SortedSet | An orderly collection , Can contain string 、 Integers 、 Floating point numbers 、 The score is 、 The order of elements is determined by the score | You can add, delete, and modify elements , Get the corresponding elements according to the range or members of the score |
HyperLogLog( base )( Not commonly used ) | Calculate the value of repetition , To determine the amount of storage |
Only Radix operations are provided , No return function |
String Some basic command operations
command | explain | remarks |
set key value | Set key value pairs | such as :set k1 v1 Set a pair of keys to k1 The value is v1 The key/value pair |
get key | Get value by key | such as :get k1 Indicates that the get key is k1 Value , If not, it shows (nil) Said is empty |
del key | Delete key value pairs by key | such as :del k1 Indicates that the delete key is k1 The key/value pair ; Other data types can also be used , Will return the number of deletions |
strlen key | return key The string length of the corresponding value | such as : about k1:value Then return to 5 |
getset key value | Modify the original key Corresponding value , And return the original value | If the original value is empty , It returns null , And set the new value |
getrange key start end | Get substring | String length is len, from 0 Start ,start and end The value range of is 0~len-1 |
append key value | New string value Will be added to key The end of the corresponding value | return key The new string length of the corresponding value |
Numeric strings can be used for simple operations
incr key | Add… To the original value 1 | The operation field must be an integer |
incrby key increment | Add an integer… To the original value increment | The operation field must be an integer |
decr key | Subtract… From the original value 1 | The operation field must be an integer |
decrby key increment | Subtract the whole number from the original value increment | The operation field must be an integer |
incrbyfloat key increment | Add floating-point numbers to the original values increment | The operation field must be an integer or floating point number |
List
command | explain | remarks |
lpush key node1[node2…] | Node node1 Add the leftmost part of the list | If the order of joining is 1,2,…n Then the chain list is from left to right n…2,1 |
rpush key node1[node2..] | Node node1 Add the right most side of the list | If the order of joining is 1,2,…n Then the chain list is from left to right 1,2,…n |
lindex key index | Read subscript as index The node of | Returns the node string , Subscript from 0 Start |
llen key | Find the length of the list | Return the number of nodes in the list |
lpop key | Pop up the node from the left side of the list | Return to node , And delete the original node in the list |
rpop key | Pop up the node from the right side of the list | Return to node , And delete the original node in the list |
linsert key befor|after pivot node | The value is pivot The node of front | after Insert node node | if key If it doesn’t exist, it’s wrong , There is no counterpart pivot Then return to -1 |
lpushx key node | If exist key Linked list , Insert… On the left node | If key The list does not exist , The failure |
rpushx key node | If exist key Linked list , Insert… On the right node | If key The list does not exist , The failure |
lrang key start end | Get the list from start To end Node value | contain start and end The value of the subscript |
lrem key count value |
if count by 0, Delete all values equal to value The node of ; If count Not for 0, First of all count Take the absolute value from left to right Delete no more than count One is equal to value The node of |
count Must be an integer , If it is negative, it will take absolute value first |
lset key index node | Set the subscript of the list to index The node value of is node | |
ltrim key start stop | Keep only from start To stop The node of , Delete the rest | contain start and stop The subscript node of |
list The blocking order of
command | explain | remarks |
blpop key timeout |
Move out and get the leftmost element of the list ; If the list has no elements, it will block until the wait timeout or pop-up elements are found |
be relative to lpop command , Its operation is process safe |
brpop key timeout |
Move out and get the rightmost element of the list ; If the list has no elements, it will block until the wait timeout or pop-up elements are found |
be relative to rpop command , Its operation is process safe |
rpoplpush key src dest | Remove and insert the rightmost element of the list to the leftmost | Cannot set timeout |
brpoplpush key src timeout |
Remove the rightmost element of the list and insert it to the leftmost edge |
Timeout can be set |
Set
command | explain | remarks |
sadd key member1[member2..] | The key is key Add members to the collection of | You can add more than one |
scard key | The statistical key is key The number of members of the collection | Return the number |
sdiff key1[key2] | Find the difference between two sets | If only key1 Then return to the whole key1 |
sdiffstore des key1[key2] | Find out the difference set storage of two sets des in | |
sinter key1[key2] | Find the intersection of two sets | If only key1 Then return to the whole key1 |
sinterstore des key1[key2] | Find the intersection of two sets and store them in des in |
|
sismember key member | Judge member Is it key Members of the assembly | If it’s a return 1, Otherwise return to 0 |
smembers key | Return all members of the collection | If the data is too large , We need to consider the problem of iterative traversal |
smove src des member | Will members member From the collection src Move to collection des in | |
spop key | Randomly pop up a member of the collection | Random pop up |
srandmember key [count] | return count Members | count Integers , If it is negative, it will take absolute value first |
srem key member1[member2] | Remove members from collection , You can remove more than one | |
sunion key1[key2] | Find the union of two sets | If only key1 Then return to the whole key1 |
sunionstore des key1 key2 | Find the union of two sets and store them in des in |
ZSet Is ordered , The main difference between unordered sets and unordered sets is that each element, in addition to its value , There will be another score , Sort the size of the scores
Hash The value corresponding to one key is multiple key value pairs , Often used to represent an object
For example, one User class , Then the key is user, The corresponding key value pair is {“id”:1,”username”: Zhang San }
command | explain | remarks |
hdel key field1 [field2…] | Delete hash One of the structures ( some ) Field | Multiple fields can be deleted |
hexists key field | Judge hash Is there… In the structure field Field | There is returned 1, Otherwise return to 0 |
hgetall key | Get all keys as key The corresponding key value pairs of | Return keys and values |
hincrby key field increment | Assign to hash Add an integer… To a field in the structure increment | The field is expected to be an integer string |
hincrbyfloat key field increment | Assign to hash Add a floating-point number to a field in the structure increment | The field is expected to be a numeric string |
hkeys key | return hash All key value pairs in the key | In the example id,username |
hlen key | return hash Number of key value pairs in | In the example is 2 |
hmget key field1[field2…] | return hash The value of the key specified in , It can be more than one | Return values in turn |
hmset key field1 value1[field2 value2…] | Yes hash Structure sets multiple key value pairs | In the example [id 1] For a key value pair |
hset key field value | stay hash Set key value pairs in the structure | Set a single key value pair |
hsetnx key field value | When hash When there is no corresponding key in the structure , Set the value | If it exists, the original value will not be modified |
hvals key | obtain hash All the values in the structure |
The example returns “id” 1,”username” ” Zhang San ” |