Summary of common instructions for Redis


1. Operation for key

1.1 del key [key .. ]: delete one or more specified keys;
1.2 dump key: serialize the given key
1.3 restore key ttl serialized-value: deserialize to key
1.4 exists key: determine whether a key is Exist
1.5 expire key seconds: set the expiration time of the key
① The set command can override the expiration time: operations that do not change the key will not affect the key’s survival time
② rename will not change the key’s expiration time
③ The persist command can delete the key’s expiration time , that is, permanent
④ ttl can view the expiration time of the key in redis
1.6 expireat key timestamp: set the key survival time
1.7 keys pattern: find all keys that match the given pattern pattern
1.8 move key db: move the key in the current database to the database db middle. Use select db to switch databases . 1.9 persist key: remove the survival time
of a given key 1.12 randomkey: return a random key 1.13 rename key newkey: rename the key to newkey, it will be overwritten when newkey exists




1.14 renamenx key newkey: when newkey does not exist, rename the key to newkey
1.15 sort key [by pattern] [get pattern [get pattern]] [limit offset count][asc | desc] [alpha] [store destination] : sort , pattern can have * characters appear
1.16 type key: return the type of the value stored in key none, string, list, set, zset, hash
1.17 scan [db] cursor [MATCH pattern] [COUNT count]: incremental generation. Similar to sscan, hscan, zscan
① The SCAN command is used to iterate the database keys in the current database. The returned result is: a new cursor for the next iteration; all iterated elements
② The SSCAN command is used to iterate over the elements in the set key.
③ The HSCAN command is used to iterate the key-value pairs in the hash key.
④ The ZSCAN command is used to iterate the elements in the ordered set (including element members and element scores)

2. String operation

2.1 append key value: Append value to the end of the original value
2.2 bitcount key [start] [end]: Calculate the data amount of bits set to 1 in a given string.
① Note that the decimal corresponding to the string "1" is 49, and the binary is 00110001.
② You can use setbit key offset value
2.3 bitop operation destkey key [key ...] : perform meta-operation on the binary string of the key, operation can be and, or, not, xor.
2.4 decr key: Decrease the digital value stored in the key by one, which is the opposite of the incr command.
2.5 decrby key decrement: Subtract the decrement from the value stored in the key, which is the opposite of the incrby command.
2.6 get key
2.7 getbit key offset: get the bit on the offset corresponding to the string value stored in the
key 2.8 getrange key start end: return the substring of the string value in the
key 2.9 getset key value: set the value of the key to value , and return the old value of the
key 2.10 mget key [key ...] : return the value of multiple keys specified
2.11 mset key value [key value ...] : set multiple key-value values ​​at the same time
2.12 msetnx key value [ key value ...] : Set multiple key-value pairs at the same time if and only if all keys do not exist.
2.13 set key value [EX second] [PX millisceonds] [NX|XX]
① setex key second value , while setting the key, set the expiration time in seconds
② psetex key millisceonds value , the expiration time in milliseconds
③ setbit key offset value , Set the bit on the specified offset
④ setnx key value , set the value of the key if and only if the key does not exist
⑤ setrange key offset value , starting from the offset, overwrite the value in the key with the value parameter
2.14 strlen key: return to the key the length of the stored string

3. Hash operation

3.1 hdel key field [field ...]: delete one or more specified fields in the hash table key
3.2 hexists key field: check whether the given field in the hash table key exists
3.3 hget key feild: check the hash table The value of the given field in the
key ① hgetall key: View the value of all fields in the hash table key
② hmget key field [field ...] : Return the value of one or more given fields in the hash table key
3.4 hincrby key field increment: add increment to the value of the field in the hash table key
3.5 hkeys key: get all fields in the hash table key
3.6 hlen key: return the number of fields in the hash table key
3.7 hset key field value: set the value of the field in the key of the hash table
① hmset key field value [field value]: set the value of a field at the same time
② hsetnx key field value: when the field does not exist, set the value of the field
3.8 hvals key: return ha The value of all fields in the
hash table key 3.9 hstrlen key field: returns the character length of the associated value of the given field in the hash table key

4. List operation (List is equivalent to stack)

4.1 lpush key value [value ...] : Insert one or more values ​​into the header of the list key
① rpush key value [value ...] : Insert one or more values ​​into the end of the list key
② lpushx key value: insert the value value into the header of the
key if and only if the key exists ③ rpushx key value: insert the value into the tail of the key if and only if the key exists
4.2 lpop key: remove and return the list key The head element of
① rpop key : remove and return the tail element of the list
② blpop key [key ...] timeout: blocking instruction of
lpop ③ brpop key [key ...] timeout: blocking instruction of
rpop ④ rpoplpush source destination :
pops the tail element of the list Source and returns it to the client, and inserts the element into the destination list before|after pivot value: insert the value value into the key, before or after the pivot 4.5 llen key: return the length of the list key 4.6 lrange key start stop: return the elements in the specified interval in the list key




4.7 lrem key count value: According to the value of count, remove the elements in the list that are equal to the parameter value
4.8 lset key index value: Set the value of the element value of the index in the following table of the list key as value
4.9 ltrim key start stop: perform a sequence on a list trim

5. Set operation (non-repeatable)

5.1 sadd keymember [member ...] : add elements to the set key, some have been ignored
5.2 scard key: return the number of elements of the set key
5.3 sdiff key [key ...]: return all members of a set, The set is the difference between all the given sets
5.4 sdiffstore destination key [key ...]: put back the difference between sets and save it in the destination set
5.5 sinter key [key ...] : Returns the intersection of the given sets in the set
5.6 sinterstore destination key [key ...]: Returns the difference between the given sets and saves it in the destination set
5.7 sismember key member: Determines whether the member element is a member of the set key
5.8 smembers key: return all members in the set
5.9 smove source destination member: move the member element from the source set to the destination set
5.10 spop key: remove and return a random element in the set
5.11 srandmember key [count] : return the specified count A set of numbers, count is a positive number means it cannot be repeated, and a negative number can be repeated
5.12 srem key member [member ...]: remove multiple elements in the set key
5.13 sunion key [key ...]: return all specified keys Union of
5.14 sunionstore destination key [key...] 

Six, ZADD operation (ordered set)

6.1 zadd key source member [[source member] [...]]: Add one or more member elements and their score values ​​to the sorted set key
6.2 zcard key: Return the number of elements of the sorted set key
6.3 zcount key min max: Returns the number of elements with a score value between min and max in the
sorted set key 6.4 zincrby key increment member: adds an increment to the score value of the member member of the sorted set key
6.5 zrange key start stop : Returns the members in the ordered set key in the specified subscript range
① zrevrange key start stop [withscores] : Returns the descending order of the members in the specified range
② zrevrangebyrank key max min [withscores] [limit offset count]
6.6 zrangebyscore key min max [withscopes] [limit offset count]: Returns the set whose score value is between min and max
6.7 zrank key member: Returns the ranking of members in the key of the ordered set
① zrevrank key member: Returns the number of members in the key of the ordered set Descending rank
6.8 zrem key member [member ...]: removes multiple members from an ordered set key

① zremrangebyrank key start stop: removes all members in the ordered set key within the specified ranking interval
② zremrangebyscore key min max , removes the ordered set key and specifies the members within the score range
6.9 zscore key member: returns the member of the member score value

Seven, pub/sub (publish, subscribe)

7.1 psubscribe pattern [pattern ...]: Subscribe to one or more channels matching the given pattern
7.2 publish channel message: Send information message to the specified channel channel
7.3 pubsub <subcommand> [argument ...]: View subscription and Introspection commands for publishing system state
eg pubsub channels [pattern] : List currently active channels, clients in subscription mode are not counted
eg pubsub numsub [channel-1 ...] : Returns the number of subscribers for a given channel , clients with subscription patterns do
not count [channel ...] : Instructs the client to unsubscribe from the given channel

Eight, Transaction (transaction)

8.1 discard: cancel the execution of all commands within a transaction block
8.2 exec: execute commands within a transaction block
8.3 multi: mark the beginning of a transaction block
8.4 unwatch: cancel the watch command to monitor all keys
8.5 watch key [key ...]: Monitor one or more keys, if the key is moved by other commands before the transaction is executed, the transaction is interrupted

Nine, Connection (connection)

9.1 auth password: enter the password when logging in to redis
9.2 echo message: print a specific message, use
9.3 ping: test the connection with the server, if normal, return pong
9.4 quit: request the server to close the connection with the current client
9.5 select index: switch to the specified database

10. Server

10.1 bgsave: asynchronously save data to the hard disk in the background
10.2 client setname/client getname: set and get the name for the connection
10.3 client kill ip:port: close the client whose address is ip:port
10.4 client list: return in a human-readable way All connected client information and statistics
10.5 config get parameter: get the configuration parameters of the running redis server
10.6 config set parameter value: set the configuration parameters of the redis server
10.7 config resetstat: reset some statistics of the info command
10.8 dbsize: return The number of keys in the current database
10.9 flushall: clears the data of the entire redis server (deletes all keys in all databases)
10.10 flushdb: clears all keys in the current database
10.11 info [section]: returns various information and statistics of the redis server
10.12 lastsave: returns the last time when redis successfully saved data to disk
10.13 monitor: prints out the commands received by the redis server in real time
10.14 save saves all data snapshots of the current Redis: instance to the hard disk in the form of RDB
files slaveof host port: Turn the current server into a slave server of the specified server
10.16 slowlog subcommand [argument] : The log system used by Redis to record query execution time


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325217942&siteId=291194637
Recommended