Redis
Database has no name , The default is 16 individual , adopt 0-15 To mark , Connect redis The first database is selected by default
select 5 choice 5 The database
Key value pair
key : character string
value : character string 、 Hash 、 list 、 aggregate 、 Ordered set
string type
set name zhang
setex name 3 zhang # Set expiration time
mset name zhang name h... # Set multiple key values
append key value # Additional
Key command :
keys *
exists key # Judge key Whether there is
type key # see key type
del key1 key2... # Delete key
expire key 3 # Set expiration time
ttl key # View effective time
hash type
For storing objects , The object structure is an attribute , value
The type of value is string
hset key field value
hmset key field1 value1 field2 value2... # Set multiple properties
hkeys key1 # View the properties of the specified key
hget key field # Get the value of the property
hmget key field1 field2 # Get values for multiple properties
hvals key # Get the values of all properties
del # Delete the whole hash Key value
hdel key field field2 # Delete attribute , The value corresponding to the property will also be deleted
list type
The element type of the list is string
Sort by insertion order
lpush key value1 value2 # Insert data on the left
lrange key start stop # see
rpush key value1 value2 # Insert data on the right
linsert key before perhaps after Existing elements , The new element # Insert the element before or after the specified element
lset key index value # Set the element value of the specified index location ( The index can be negative )
lrem key count value # Put the list before count The value of the second occurrence is value Element delete
count>0, Remove from the beginning to the end
count<0, Remove from the tail to the head
count=0, Remove all
set type
unordered set
Element is string type
Element is unique , No repetition
There is no modification operation for the collection
sadd key member1 member2... # Additive elements
smembers key # Get elements
srem key Elements # Deletes the specified element
zset type
Ordered set
Element is string type
Element is unique , No repetition
Each element is associated with a doouble Type of score, Said the weight , Sort elements from small to large by weight
There are no modifications
zadd key score1 member1 score2 member2... # add to
zadd a4 5 wangwu 3 zhangsan
zrange key start stop # Specifies to get the elements in the scope ,start,stop Is the subscript index of the element
zrangebyscore key min max # obtain score Values in min and max Between the elements
zscore key member # Get the weight of members in the collection
zrem key member1 member2... # Deletes the specified element
zremrangebyscore key min max # Delete the element whose weight is within the specified range