redis

简明手册

查询

CommandDescription
scan 0 match *pattern* count number迭代数据库中的数据库键,产用于模糊搜索某 key ,非全量搜索
keys *pattern*查询当前库指定 key
dbsize当前数据库的 key 的数量。

info

memory 内存信息

CommandDescription
used_memory内存总量,以字节(byte)为单位
used_memory_human内存总量,以人类可读的格式展示
used_memory_rss已分配的内存总量(常驻内存大小,单位为 byte )。这个值和 top、ps 等命令的输出一致。
used_memory_rss_human与 used_memory_rss 相同,以人类可读的格式展示
used_memory_peak内存消耗峰值(以字节为单位)
used_memory_peak_humanused_memory_rss/used_memory 的比例。一般情况下,used_memory_rss 略高于 used_memory,当内存碎片较多时,则 mem_fragmentation_ratio 会较大,可以反映内存碎片是否很多

Strings


CommandDescription
APPEND keyvalueAppend
BITCOUNT key [ start stop ]Count #of set bits
BITOP AND dest[src]+Bitwise AND
BITOP OR dest[src]+Bitwise OR
BITOP XOR dest[src]+Bitwise XOR
BITOP NOT destsrcBitwise NOT
BITPOS keybit[startstop]Find first set bit
DECR keyDecrement integer
DECRBY keybySubtract from integer
GET keyGet by key
GETBIT keyoffsetGet bit by index
GETRANGE keystartendGet substring
GETSET keyvalueSet,returning old value
INCR keyIncrement integer
INCRBY keybyAdd to integer
INCRBYFLOAT keybyAdd to float
MGET [key]+Get multiple
MSET [keyvalue]+Set multiple
MSETNX [keyvalue]+Set multiple if doesn’texist
PSETEX keymsvalueSet with expiry(ms)
SET keyvalueSet
SETBIT keyoffsetvalueSet bit by index
SETEX keysecsvalueSet with expiry(s)
SETNX keyvalueSet if doesn’t exist
SETRANGE keyoffsetvalueSet substring
STRLEN keyGet length

Strings can be used as numbers,arrays,bit sets and binary data

Databases


CommandDescription
DEL [ key ]+Delete item (s)
DUMP keySerialise item
EXISTS [ key ]+Check for key
EXPIRE keysSet timeout on item
EXPIREAT keytsSet timeout by timestamp
KEYS patternGet keys matching pattern
MIGRATETransfer item between instances
MOVE keydbTransfer item between databases
OBJECTInspect item
PERSIST keyRemove timeout
PEXPIRE keymsSet timeout(ms)
PEXPIREAT keytsSet timeout(timestamp)
PTTL keyGet item TTL(ms)
RANDOMKEYGet random key
RENAME key newChange item’skey
RENAMENX keynewChange key if new key doesn’t exist
RESTORE keyDeserialise
SCAN keycursor[MATCH pattern][countcount]Iterate keys
SORTGet or store sorted copy
TTL keyGet item TTL (s)
TYPE keyGet type of item

  • Times are specified in seconds(s) or milliseconds(ms)*
  • Timestamps(s) are specified as seconds since January1,1970*

Hashes


Hashes
HDEL key [ field ]+Delete field(s)
HEXISTS key fieldCheck for field
HGET key fieldGet item
HGETALL keyReturn all fields/values
HINCRBY key field byAdd to integer value
HINCRBYFLOAT key field byAdd to float value
HKEYS keyReturn all fields
HLEN keyGet number of fields
HMGET key[field] +Get multiple items
HMSET key[field value] +Set multiple items
HSCAN key cursor[MATCH pattern][countcount]Iterate fields
HSET key field valueSet field
HSETNX key field valueSet field if doesn’t exist
HSTRLEN key fieldGet string length of field
HVALS keyReturn all values

Sets


Sets
SADD key [ member ]+向集合添加一个或多个成员
SCARD key获取集合的成员数
SDIFF [key]+返回第一个集合与其他集合之间的差异
SDIFFSTORE dest [key]+Store difference
SINTER [key]+Intersection
SINTERSTORE dest [key]+Store intersection
SISMEMBER keymemberCheck for item
SMEMBERS keyGet all
SMOVE srcdest memberMove item to another set
SPOP key[count]?Pop random item
SRANDMEMBER key[count]Get random item
SREM key[member]+Remove matching
SSCAN key cursor[MATCH pattern][countcount]Iterate items
SUNION[key]+Union
SUNIONSTORE dest [key]+Store union

SortedSets


SortedSets
ZADD key[options][score additem item] +Add item
ZCARD keyGet number of items
ZCOUNT key min maxNumber of items with score range
ZINCRBY key incrmemberAdd to score
ZINTERSTOREStore intersection
ZLEXCOUNT key min maxLexicographical range count
ZRANGE key start stop [WITHSCORES]Get items within rank range
ZRANGEBYLEX key min max[ LIMIT offset count]Get items within lexicographical range
ZRANGEBYSCORE key min max [WITHSCORES][limit offset count]Get items within score range
ZRANK key memberGet item rank
ZREM key [member]+Remove item(s)
ZREMRANGEBYLEX key min maxRemove items within lexicographical range
ZREMRANGEBYRANK key start stopRemove items within rank range
ZREMRANGEBYSCORE key min maxRemove items within score range
ZREVRANGEZRANGE inreverse order
ZREVRANGEBYLEXZRANGEBYLEX inreverse order
ZREVRANGEBYSCOREZRANGEBYSCORE inreverse order
ZREVRANKZRANK inreverse order
ZSCAN key cursor [MATCH pattern][count count]Iterate items
ZSCORE keymemberGet item score
ZUNIONSTORE dest numkeys [ key ]+ [ WEIGHTS [ weight ]+ ] [ AGGREGATE SUM[MIN][MAX] ]Store union

Lists


Lists
BLPOP [key]+timeoutBlocking left pop
BLPOP [key]+timeoutBlocking left pop
BRPOP [key]+timeoutBlocking right pop
BRPOPLPUSH src dest timeoutBlocking rotate
LINDEX key indexAccess by index
LINSERT key BEFORE[AFTER] pivot valueInsert next to
LLEN keyGet length
LPOP keyPop from start
LPUSH key[value]+Push onto start
LPUSHX key valuePush if list exists
LRANGE key start stopAccess range
LREM key count valueRemove occurrences
LSET key index valueSet item by index
LTRIM list start stopRemoves tart/end items
RPOP keyPop from end
RPOPLPUSH src destRotate
RPUSH key[value]+Push onto end
RPUSHX key valuePush onto end if list exists

Client/Server


Scripts
AUTH passwordRequest authentication
ECHO messageReturn message
PINGTest connection
QUITClose connection
SELECT indexSet current database by index

Scripts


Scripts
EVALRun
EVALSHARun cached
SCRIPT EXISTSCheck by hash
SCRIPT FLUSHClear cache
SCRIPT KILLKill running script
SCRIPT LOADAdd to cache