Redis Cheat Sheet
Redis Cheat Sheet
Cheat Sheet
Strings Hashes Lists
APPEND key value Append HDEL key [ field ]+ Delete field(s) BLPOP [ key ]+ timeout Blocking left pop
BITCOUNT key [ start stop ] Count # of set bits HEXISTS key field Check for field BRPOP [ key ]+ timeout Blocking right pop
BITOP AND dest [ src ]+ Bitwise AND HGET key field Get item BRPOPLPUSH src dest timeout Blocking rotate
BITOP OR dest [ src ]+ Bitwise OR HGETALL key Return all fields / values LINDEX key index Access by index
BITOP XOR dest [ src ]+ Bitwise XOR HINCRBY key field by Add to integer value LINSERT key BEFORE|AFTER pivot Insert next to
BITOP NOT dest src Bitwise NOT HINCRBYFLOAT key field by Add to float value value
BITPOS key bit [ start stop ] Find first set bit HKEYS key Return all fields LLEN key Get length
DECR key Decrement integer HLEN key Get number of fields LPOP key Pop from start
DECRBY key by Subtract from integer HMGET key [ field ]+ Get multiple items LPUSH key [ value ]+ Push onto start
GET key Get by key HMSET key [ field value ]+ Set multiple items LPUSHX key value Push if list exists
GETBIT key offset Get bit by index HSCAN key cursor [ MATCH Iterate fields LRANGE key start stop Access range
GETRANGE key start end Get substring pattern ] [ COUNT count ] LREM key count value Remove occurrences
GETSET key value Set, returning old value HSET key field value Set field LSET key index value Set item by index
INCR key Increment integer HSETNX key field value Set field if doesn’t exist LTRIM list start stop Remove start/end items
INCRBY key by Add to integer HSTRLEN key field Get string length of field RPOP key Pop from end
INCRBYFLOAT key by Add to float HVALS key Return all values RPOPLPUSH src dest Rotate
MGET [ key ]+ Get multiple RPUSH key [ value ]+ Push onto end
MSET [ key value ]+ Set multiple RPUSHX key value Push onto end if list exists
Sets
MSETNX [ key value ]+ Set multiple if doesn’t exist
SADD key [ member ]+ Add item
PSETEX key ms value Set with expiry (ms)
SCARD key Get size of set
SET key value Set
SETBIT key offset value Set bit by index
SDIFF [ key ]+ Get difference
SDIFFSTORE dest [ key ]+ Store difference
SETEX key secs value Set with expiry (s)
SINTER [ key ]+ Intersection
SETNX key value Set if doesn’t exist
SINTERSTORE dest [ key ]+ Store intersection
SETRANGE key offset value Set substring
SISMEMBER key member Check for item
STRLEN key Get length
SMEMBERS key Get all
SMOVE src dest member Move item to another set
Strings can be used as numbers, arrays, bit sets and binary data
SPOP key [ count ]? Pop random item
SRANDMEMBER key [ count ] Get random item
SREM key [ member ]+ Remove matching
SSCAN key cursor [ MATCH Iterate items
pattern ] [ COUNT count ]
SUNION[ key ]+ Union
SUNIONSTORE dest [ key ]+ Store union
Databases Sorted Sets
DEL [ key ]+ Delete item(s) ZADD key [ options ] [ score Add item Client/Server
DUMP key Serialise item item ]+ AUTH password Request authentication
EXISTS [ key ]+ Check for key ZCARD key Get number of items ECHO message Return message
EXPIRE key s Set timeout on item ZCOUNT key min max Number of items with score range PING Test connection
EXPIREAT key ts Set timeout by timestamp ZINCRBY key incr member Add to score QUIT Close connection
KEYS pattern Get keys matching pattern ZINTERSTORE Store intersection SELECT index Set current database by index
MIGRATE Transfer item between instances ZLEXCOUNT key min max Lexicographical range count
MOVE key db Transfer item between databases ZRANGE key start stop Get items within rank range
[ WITHSCORES ]
Scripts
OBJECT Inspect item
ZRANGEBYLEX key min max [ Get items within lexicographical EVAL Run
PERSIST key Remove timeout
LIMIT offset count ] range EVALSHA Run cached
PEXPIRE key ms Set timeout (ms)
ZRANGEBYSCORE key min max Get items within score range SCRIPT EXISTS Check by hash
PEXPIREAT key ts Set timeout (timestamp)
[ WITHSCORES ] [ LIMIT offset SCRIPT FLUSH Clear cache
PTTL key Get item TTL (ms)
count ] SCRIPT KILL Kill running script
RANDOMKEY Get random key
ZRANK key member Get item rank SCRIPT LOAD Add to cache
RENAME key new Change item’s key
RENAMENX key new Change key if new key doesn’t exist ZREM key [ member ]+ Remote item(s)
ZREMRANGEBYLEX key min Remove items within lexicographical
RESTORE key Deserialise
max range
SCAN key cursor [ MATCH Iterate keys
ZREMRANGEBYRANK key start Remove items within rank range
pattern ] [ COUNT count ]
stop
SORT Get or store sorted copy
ZREMRANGEBYSCORE key min Remove items within score range
TTL key Get item TTL (s)
max
TYPE key Get type of item
ZREVRANGE ZRANGE in reverse order
ZREVRANGEBYLEX ZRANGEBYLEX in reverse order
Times are specified in seconds (s) or milliseconds (ms) ZREVRANGEBYSCORE ZRANGEBYSCORE in reverse order
Timestamps (s) are specified as seconds since January 1, 1970 ZREVRANK ZRANK in reverse order
ZSCAN key cursor [ MATCH Iterate items
pattern ] [ COUNT count ]
ZSCORE key member Get item score
ZUNIONSTORE dest numkeys [ Store union
key ]+ [ WEIGHTS [ weight ]+ ] [
AGGREGATE SUM|MIN|MAX ]
Lexicographical commands require items to have the same score