Redis data types and commands

1. Five common data types

string string type
hash Hash tables are mainly used to store objects
list list list, sorted by insertion order
set Unordered collection, no duplicate elements
sorted set An ordered collection with no duplicate elements

2. Commonly used commands for operating data

1、string

set key value Store the value in redis
get key Get the specified value
setex key seconds value Set the specified value and set the expiration time
setnx key value Store the specified value only when the key does not exist

2、hash

hset key field value Assign the value of the field field in the key to value
hget key field Get the specified field in the hash table
hdel key filed Delete the specified field in the hash table
hkeys key get all fields
hvals key get all values
hgetall key Get all fields and values ​​of the specified key

3、list

lpush key value1 value2 … Insert one or more values ​​at the head of the list
lrange key start stop Get the specified range of elements in the list
rpop key Remove and get the last element of the list
llen key get list length
brpop key1 key2 timeout Remove and get the last element of the list. If the list has no elements, it will block the list until the wait times out or a pop-up element is found

4、set

sadd key member1 menber2 … add elements to the collection
smembers key Return all members of the set
scard key Get the number of members of the collection
sinter key1 key2 … Returns the intersection of the specified collections
sunion key1 key2 … Returns the union of the specified collections
sdiff key1 key2 … Returns the difference of the specified sets
srem key member1 member2 Remove one or more elements from a collection

5、sorted set

zadd key score1 member1 score2 member2 … Add one or more members to a sorted set, or update the score of an existing member
zrange key start stop withscores Returns the members in the specified range in the sorted set through the index range
zincrby key increment member Adds the specified value to the squad member's score in an ordered set
zrem key member1 member2 … remove one or more members

3. Common commands

keys pattern Query all keys of a specified type
exists key Check if the specified key exists
type key View the type of key
ttl key Check how long the key expires
cell key Delete the specified key

Guess you like

Origin blog.csdn.net/chenxingxingxing/article/details/125066887