Redis 常用命令指南

  1. 如何在ubuntu18.04上安装和保护redis
  2. 如何连接到Redis数据库
  3. 如何管理Redis数据库和Keys
  4. 如何在Redis中管理副本和客户端
  5. 如何在Redis中管理字符串
  6. 如何在Redis中管理list
  7. 如何在Redis中管理Hashes
  8. 如何在Redis中管理Sets
  9. 如何在Redis中管理Sorted Sets
  10. 如何在Redis中运行事务
  11. 如何使Redis中的Key失效
  12. 如何解决Redis中的故障
  13. 如何从命令行更改Redis的配置
  14. Redis数据类型简介
  15. Redis 中如何使用 lua脚本
  16. Redis 常用命令指南
CommandDescription
APPEND key valueAppend a value to a key
AUTH passwordAuthenticate to the server
BGREWRITEAOFAsynchronously rewrite the append-only file
BGSAVEAsynchronously save the dataset to disk
BITCOUNT key [start end]Count set bits in a string
BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]Perform arbitrary bitfield integer operations on strings
BITOP operation destkey key [key ...]Perform bitwise operations between strings
BITPOS key bit [start] [end]Find first bit set or clear in a string
BLPOP key [key ...] timeoutRemove and get the first element in a list, or block until one is available
BRPOP key [key ...] timeoutRemove and get the last element in a list, or block until one is available
BRPOPLPUSH source destination timeoutPop a value from a list, push it to another list and return it; or block until one is available
CLIENT KILL [ip:port] [ID client-id] [TYPE normal|master|slave|pubsub] [ADDR ip:port] [SKIPME yes/no]Kill the connection of a client
CLIENT LISTGet the list of client connections
CLIENT GETNAMEGet the current connection name
CLIENT PAUSE timeoutStop processing commands from clients for some time
CLIENT REPLY ON|OFF|SKIPInstruct the server whether to reply to commands
CLIENT SETNAME connection-nameSet the current connection name
CLUSTER ADDSLOTS slot [slot ...]Assign new hash slots to receiving node
CLUSTER COUNT-FAILURE-REPORTS node-idReturn the number of failure reports active for a given node
CLUSTER COUNTKEYSINSLOT slotReturn the number of local keys in the specified hash slot
CLUSTER DELSLOTS slot [slot ...]Set hash slots as unbound in receiving node
CLUSTER FAILOVER [FORCE|TAKEOVER]Forces a slave to perform a manual failover of its master.
CLUSTER FORGET node-idRemove a node from the nodes table
CLUSTER GETKEYSINSLOT slot countReturn local key names in the specified hash slot
CLUSTER INFOProvides info about Redis Cluster node state
CLUSTER KEYSLOT keyReturns the hash slot of the specified key
CLUSTER MEET ip portForce a node cluster to handshake with another node
CLUSTER NODESGet Cluster config for the node
CLUSTER REPLICATE node-idReconfigure a node as a slave of the specified master node
CLUSTER RESET [HARD|SOFT]Reset a Redis Cluster node
CLUSTER SAVECONFIGForces the node to save cluster state on disk
CLUSTER SET-CONFIG-EPOCH config-epochSet the configuration epoch in a new node
CLUSTER SETSLOT slot IMPORTING|MIGRATING|STABLE|NODE [node-id]Bind a hash slot to a specific node
CLUSTER SLAVES node-idList slave nodes of the specified master node
CLUSTER SLOTSGet array of Cluster slot to node mappings
COMMANDGet array of Redis command details
COMMAND COUNTGet total number of Redis commands
COMMAND GETKEYSExtract keys given a full Redis command
COMMAND INFO command-name [command-name ...]Get array of specific Redis command details
CONFIG GET parameterGet the value of a configuration parameter
CONFIG REWRITERewrite the configuration file with the in memory configuration
CONFIG SET parameter valueSet a configuration parameter to the given value
CONFIG RESETSTATReset the stats returned by INFO
DBSIZEReturn the number of keys in the selected database
DEBUG OBJECT keyGet debugging information about a key
DEBUG SEGFAULTMake the server crash
DECR keyDecrement the integer value of a key by one
DECRBY key decrementDecrement the integer value of a key by the given number
DEL key [key ...]Delete a key
DISCARDDiscard all commands issued after MULTI
DUMP keyReturn a serialized version of the value stored at the specified key.
ECHO messageEcho the given string
EVAL script numkeys key [key ...] arg [arg ...]Execute a Lua script server side
EVALSHA sha1 numkeys key [key ...] arg [arg ...]Execute a Lua script server side
EXECExecute all commands issued after MULTI
EXISTS key [key ...]Determine if a key exists
EXPIRE key secondsSet a key's time to live in seconds
EXPIREAT key timestampSet the expiration for a key as a UNIX timestamp
FLUSHALL [ASYNC]Remove all keys from all databases
FLUSHDB [ASYNC]Remove all keys from the current database
GEOADD key longitude latitude member [longitude latitude member ...]Add one or more geospatial items in the geospatial index represented using a sorted set
GEOHASH key member [member ...]Returns members of a geospatial index as standard geohash strings
GEOPOS key member [member ...]Returns longitude and latitude of members of a geospatial index
GEODIST key member1 member2 [unit]Returns the distance between two members of a geospatial index
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point
GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member
GET keyGet the value of a key
GETBIT key offsetReturns the bit value at offset in the string value stored at key
GETRANGE key start endGet a substring of the string stored at a key
GETSET key valueSet the string value of a key and return its old value
HDEL key field [field ...]Delete one or more hash fields
HEXISTS key fieldDetermine if a hash field exists
HGET key fieldGet the value of a hash field
HGETALL keyGet all the fields and values in a hash
HINCRBY key field incrementIncrement the integer value of a hash field by the given number
HINCRBYFLOAT key field incrementIncrement the float value of a hash field by the given amount
HKEYS keyGet all the fields in a hash
HLEN keyGet the number of fields in a hash
HMGET key field [field ...]Get the values of all the given hash fields
HMSET key field value [field value ...]Set multiple hash fields to multiple values
HSET key field valueSet the string value of a hash field
HSETNX key field valueSet the value of a hash field, only if the field does not exist
HSTRLEN key fieldGet the length of the value of a hash field
HVALS keyGet all the values in a hash
INCR keyIncrement the integer value of a key by one
INCRBY key incrementIncrement the integer value of a key by the given amount
INCRBYFLOAT key incrementIncrement the float value of a key by the given amount
INFO [section]Get information and statistics about the server
KEYS patternFind all keys matching the given pattern
LASTSAVEGet the UNIX time stamp of the last successful save to disk
LINDEX key indexGet an element from a list by its index
LINSERT key BEFORE|AFTER pivot valueInsert an element before or after another element in a list
LLEN keyGet the length of a list
LPOP keyRemove and get the first element in a list
LPUSH key value [value ...]Prepend one or multiple values to a list
LPUSHX key valuePrepend a value to a list, only if the list exists
LRANGE key start stopGet a range of elements from a list
LREM key count valueRemove elements from a list
LSET key index valueSet the value of an element in a list by its index
LTRIM key start stopTrim a list to the specified range
MGET key [key ...]Get the values of all the given keys
MIGRATE host port key|"" destination-db timeout [COPY] [REPLACE] [KEYS key [key ...]]Atomically transfer a key from a Redis instance to another one.
MONITORListen for all requests received by the server in real time
MOVE key dbMove a key to another database
MSET key value [key value ...]Set multiple keys to multiple values
MSETNX key value [key value ...]Set multiple keys to multiple values, only if none of the keys exist
MULTIMark the start of a transaction block
OBJECT subcommand [arguments [arguments ...]]Inspect the internals of Redis objects
PERSIST keyRemove the expiration from a key
PEXPIRE key millisecondsSet a key's time to live in milliseconds
PEXPIREAT key milliseconds-timestampSet the expiration for a key as a UNIX timestamp specified in milliseconds
PFADD key element [element ...]Adds the specified elements to the specified HyperLogLog.
PFCOUNT key [key ...]Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
PFMERGE destkey sourcekey [sourcekey ...]Merge N different HyperLogLogs into a single one.
PING [message]Ping the server
PSETEX key milliseconds valueSet the value and expiration in milliseconds of a key
PSUBSCRIBE pattern [pattern ...]Listen for messages published to channels matching the given patterns
PUBSUB subcommand [argument [argument ...]]Inspect the state of the Pub/Sub subsystem
PTTL keyGet the time to live for a key in milliseconds
PUBLISH channel messagePost a message to a channel
PUNSUBSCRIBE [pattern [pattern ...]]Stop listening for messages posted to channels matching the given patterns
QUITClose the connection
RANDOMKEYReturn a random key from the keyspace
READONLYEnables read queries for a connection to a cluster slave node
READWRITEDisables read queries for a connection to a cluster slave node
RENAME key newkeyRename a key
RENAMENX key newkeyRename a key, only if the new key does not exist
RESTORE key ttl serialized-value [REPLACE]Rename a key, only if the new key does not exist
RESTORE key ttl serialized-value [REPLACE]Create a key using the provided serialized value, previously obtained using DUMP.
ROLEReturn the role of the instance in the context of replication
RPOP keyRemove and get the last element in a list
RPOPLPUSH source destinationRemove the last element in a list, prepend it to another list and return it
RPUSH key value [value ...]Append one or multiple values to a list
RPUSHX key valueAppend a value to a list, only if the list exists
SADD key member [member ...]Add one or more members to a set
SAVESynchronously save the dataset to disk
SCARD keyGet the number of members in a set
SCRIPT DEBUG YES|SYNC|NOSet the debug mode for executed scripts.
SCRIPT EXISTS sha1 [sha1 ...]Check existence of scripts in the script cache.
SCRIPT FLUSHRemove all the scripts from the script cache.
SCRIPT KILLKill the script currently in execution.
SCRIPT LOAD scriptLoad the specified Lua script into the script cache.
SDIFF key [key ...]Subtract multiple sets
SDIFFSTORE destination key [key ...]Subtract multiple sets and store the resulting set in a key
SELECT indexChange the selected database for the current connection
SET key value [EX seconds] [PX milliseconds] [NX|XX]Set the string value of a key
SETBIT key offset valueSets or clears the bit at offset in the string value stored at key
SETEX key seconds valueSet the value and expiration of a key
SETNX key valueSet the value of a key, only if the key does not exist
SETRANGE key offset valueOverwrite part of a string at key starting at the specified offset
SHUTDOWN [NOSAVE|SAVE]Synchronously save the dataset to disk and then shut down the server
SINTER key [key ...]Intersect multiple sets
SINTERSTORE destination key [key ...]Intersect multiple sets and store the resulting set in a key
SISMEMBER key memberDetermine if a given value is a member of a set
SLAVEOF host portMake the server a slave of another instance, or promote it as master
SLOWLOG subcommand [argument]Manages the Redis slow queries log
SMEMBERS keyGet all the members in a set
SMOVE source destination memberMove a member from one set to another
SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]Sort the elements in a list, set or sorted set
SPOP key [count]Remove and return one or multiple random members from a set
SRANDMEMBER key [count]Get one or multiple random members from a set
SREM key member [member ...]Remove one or more members from a set
STRLEN keyGet the length of the value stored in a key
SUBSCRIBE channel [channel ...]Listen for messages published to the given channels
SUNION key [key ...]Add multiple sets
SUNIONSTORE destination key [key ...]Add multiple sets and store the resulting set in a key
SWAPDB index indexSwaps two Redis databases
SYNCInternal command used for replication
TIMEReturn the current server time
TOUCH key [key ...]Alters the last access time of a key(s). Returns the number of existing keys specified.
TTL keyGet the time to live for a key
TYPE keyDetermine the type stored at key
UNSUBSCRIBE [channel [channel ...]]Stop listening for messages posted to the given channels
UNLINK key [key ...]Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking.
UNWATCHForget about all watched keys
WAIT numslaves timeoutWait for the synchronous replication of all the write commands sent in the context of the current connection
WATCH key [key ...]Watch the given keys to determine execution of the MULTI/EXEC block
ZADD key [NX|XX] [CH] [INCR] score member [score member ...]Add one or more members to a sorted set, or update its score if it already exists
ZCARD keyGet the number of members in a sorted set
ZCOUNT key min maxCount the members in a sorted set with scores within the given values
ZINCRBY key increment memberIncrement the score of a member in a sorted set
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]Intersect multiple sorted sets and store the resulting sorted set in a new key
ZLEXCOUNT key min maxCount the number of members in a sorted set between a given lexicographical range
ZRANGE key start stop [WITHSCORES]Return a range of members in a sorted set, by index
ZRANGEBYLEX key min max [LIMIT offset count]Return a range of members in a sorted set, by lexicographical range
ZREVRANGEBYLEX key max min [LIMIT offset count]Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]Return a range of members in a sorted set, by score
ZRANK key memberDetermine the index of a member in a sorted set
ZREM key member [member ...]Remove one or more members from a sorted set
ZREMRANGEBYLEX key min maxRemove all members in a sorted set between the given lexicographical range
ZREMRANGEBYRANK key start stopRemove all members in a sorted set within the given indexes
ZREMRANGEBYSCORE key min maxRemove all members in a sorted set within the given scores
ZREVRANGE key start stop [WITHSCORES]Return a range of members in a sorted set, by index, with scores ordered from high to low
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]Return a range of members in a sorted set, by score, with scores ordered from high to low
ZREVRANK key memberDetermine the index of a member in a sorted set, with scores ordered from high to low
ZSCORE key memberGet the score associated with the given member in a sorted set
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]Add multiple sorted sets and store the resulting sorted set in a new key
SCAN cursor [MATCH pattern] [COUNT count]Incrementally iterate the keys space
SSCAN key cursor [MATCH pattern] [COUNT count]Incrementally iterate Set elements
HSCAN key cursor [MATCH pattern] [COUNT count]Incrementally iterate hash fields and associated values
ZSCAN key cursor [MATCH pattern] [COUNT count]Incrementally iterate sorted sets elements and associated scores

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×