Redis Cheat Sheet
Searchable reference for 200+ Redis commands — strings, hashes, lists, sets, sorted sets, pub/sub, streams, Lua scripting, cluster, ACL, and cli tips with one-click copy
redis-cliConnect to local Redis server
redis-cli -h host -p 6379 -a passwordConnect to remote Redis with auth
redis-cli --tls -h host -p 6380Connect with TLS encryption
PINGTest connection (returns PONG)
AUTH passwordAuthenticate to the server
AUTH username passwordAuthenticate with ACL username (Redis 6+)
SELECT 0Switch to database 0 (0-15)
QUITClose the connection
INFOGet server info and statistics
INFO memoryGet memory usage info
CONFIG GET *Get all configuration parameters
CONFIG SET maxmemory 256mbSet a configuration parameter at runtime
DBSIZEReturn the number of keys in current DB
TIMEReturn server time (seconds + microseconds)
CLIENT LISTList all connected clients
CLIENT SETNAME myappSet a name for the current connection
SLOWLOG GET 10Get last 10 slow queries
MONITORStream all commands received by server (debug)
SET key valueO(1)Set a key to a string value
SET key value EX 60Set with expiry in seconds
SET key value PX 60000Set with expiry in milliseconds
SET key value NXSet only if key does NOT exist (create)
SET key value XXSet only if key already EXISTS (update)
SETNX key valueSet if not exists (returns 1 or 0)
GET keyO(1)Get the value of a key
GETDEL keyGet value and delete the key (Redis 6.2+)
GETSET key newvalueSet new value and return old value
MSET key1 val1 key2 val2O(N)Set multiple keys at once
MGET key1 key2 key3O(N)Get multiple values at once
APPEND key valueAppend to existing string value
STRLEN keyGet length of the string value
INCR keyO(1)Increment integer value by 1
INCRBY key 5Increment by specific integer
INCRBYFLOAT key 1.5Increment by float value
DECR keyDecrement integer value by 1
DECRBY key 5Decrement by specific integer
GETRANGE key 0 3Get substring (inclusive range)
SETRANGE key 0 "Hello"Overwrite part of string at offset
KEYS pattern*Find all keys matching pattern
⚠️ Don't use in production — use SCAN
SCAN 0 MATCH user:* COUNT 100O(1) per callIterate keys safely with cursor
EXISTS keyCheck if key exists (returns 0 or 1)
TYPE keyGet the type of a key
RENAME key newkeyRename a key
RENAMENX key newkeyRename only if newkey doesn't exist
DEL key1 key2O(N)Delete one or more keys (blocking)
UNLINK key1 key2Delete keys asynchronously (non-blocking)
EXPIRE key 60Set TTL in seconds
PEXPIRE key 60000Set TTL in milliseconds
EXPIREAT key 1700000000Set expiry at Unix timestamp
TTL keyGet remaining TTL in seconds (-1 = no expiry, -2 = doesn't exist)
PTTL keyGet remaining TTL in milliseconds
PERSIST keyRemove expiry (make key permanent)
OBJECT ENCODING keyGet the internal encoding of a key
OBJECT IDLETIME keyGet seconds since key was last accessed
DUMP keySerialize a key's value
RESTORE key 0 "\x00..."Deserialize and restore a key
RANDOMKEYReturn a random key from the DB
HSET user:1 name "Alice" age 30O(N)Set one or more hash fields
HGET user:1 nameO(1)Get a single hash field value
HMGET user:1 name age emailGet multiple hash field values
HGETALL user:1O(N)Get all fields and values
HDEL user:1 emailDelete one or more hash fields
HEXISTS user:1 nameCheck if hash field exists
HKEYS user:1Get all field names
HVALS user:1Get all field values
HLEN user:1Get number of fields in hash
HINCRBY user:1 age 1Increment hash field integer by N
HINCRBYFLOAT user:1 score 0.5Increment hash field by float
HSETNX user:1 email "a@b.com"Set field only if it doesn't exist
HSCAN user:1 0 MATCH name* COUNT 10Iterate hash fields with cursor
LPUSH mylist a b cO(N)Push elements to the head (left)
RPUSH mylist x y zPush elements to the tail (right)
LPOP mylistO(1)Remove and return from head
RPOP mylistRemove and return from tail
LPOP mylist 3Pop N elements from head (Redis 6.2+)
LRANGE mylist 0 -1O(S+N)Get all elements (0 to last)
LRANGE mylist 0 9Get first 10 elements
LLEN mylistO(1)Get the length of the list
LINDEX mylist 0Get element at index
LSET mylist 0 newvalueSet element at index
LINSERT mylist BEFORE pivot valueInsert before a pivot element
LINSERT mylist AFTER pivot valueInsert after a pivot element
LREM mylist 2 valueRemove N occurrences of value
LTRIM mylist 0 99Trim list to range (keep 0-99)
RPOPLPUSH src dstPop from src tail, push to dst head
LMOVE src dst LEFT RIGHTMove element between lists (Redis 6.2+)
BLPOP mylist 5Blocking pop from head (5s timeout)
Great for job queues
BRPOP mylist 5Blocking pop from tail (5s timeout)
SADD myset a b cO(N)Add members to a set
SREM myset aRemove members from a set
SMEMBERS mysetO(N)Get all members
SISMEMBER myset aO(1)Check if member exists
SMISMEMBER myset a b cCheck multiple members (Redis 6.2+)
SCARD mysetO(1)Get number of members (cardinality)
SPOP mysetRemove and return random member
SPOP myset 3Remove and return N random members
SRANDMEMBER mysetGet random member (without removing)
SRANDMEMBER myset 3Get N random members
SUNION set1 set2Union of two or more sets
SUNIONSTORE dest set1 set2Store union result in dest
SINTER set1 set2Intersection of sets
SINTERSTORE dest set1 set2Store intersection in dest
SDIFF set1 set2Difference of sets (in set1 but not set2)
SDIFFSTORE dest set1 set2Store difference in dest
SMOVE src dst memberMove member from one set to another
SSCAN myset 0 MATCH a* COUNT 10Iterate set members with cursor
ZADD leaderboard 100 alice 200 bobO(log N)Add members with scores
ZADD leaderboard NX 100 charlieAdd only if member doesn't exist
ZADD leaderboard XX 150 aliceUpdate only if member exists
ZADD leaderboard GT 300 aliceUpdate only if new score > current (Redis 6.2+)
ZSCORE leaderboard aliceO(1)Get score of a member
ZRANK leaderboard aliceGet rank (0-based, low to high)
ZREVRANK leaderboard aliceGet rank (0-based, high to low)
ZINCRBY leaderboard 10 aliceIncrement score of a member
ZRANGE leaderboard 0 -1 WITHSCORESGet all members sorted low→high
ZREVRANGE leaderboard 0 9 WITHSCORESTop 10 members (high→low)
ZRANGEBYSCORE leaderboard 100 200Get members with scores in range
ZRANGEBYSCORE leaderboard -inf +inf LIMIT 0 10Paginated score range query
ZCARD leaderboardGet number of members
ZCOUNT leaderboard 100 200Count members with scores in range
ZREM leaderboard aliceRemove members
ZREMRANGEBYSCORE leaderboard 0 100Remove members by score range
ZREMRANGEBYRANK leaderboard 0 2Remove members by rank range
ZUNIONSTORE dest 2 set1 set2 WEIGHTS 1 2Union sorted sets with weights
ZINTERSTORE dest 2 set1 set2Intersect sorted sets
ZSCAN leaderboard 0 MATCH a* COUNT 10Iterate sorted set with cursor
SUBSCRIBE channel1 channel2Subscribe to channels
PSUBSCRIBE news.*Subscribe with pattern matching
PUBLISH channel1 "Hello!"Publish a message to a channel
UNSUBSCRIBE channel1Unsubscribe from a channel
PUBSUB CHANNELSList active channels
PUBSUB NUMSUB channel1Count subscribers for a channel
XADD stream * field valueAdd entry to stream (auto ID)
Streams (Redis 5+)
XADD stream MAXLEN ~ 1000 * f vAdd with approximate max length cap
XLEN streamGet number of entries in stream
XRANGE stream - +Read all stream entries
XRANGE stream - + COUNT 10Read first 10 entries
XREVRANGE stream + - COUNT 10Read last 10 entries (reverse)
XREAD COUNT 5 BLOCK 0 STREAMS stream 0Read new entries (blocking)
XGROUP CREATE stream grp $ MKSTREAMCreate consumer group
XREADGROUP GROUP grp consumer COUNT 5 BLOCK 0 STREAMS stream >Read as consumer group member
XACK stream grp id1 id2Acknowledge processed entries
XPENDING stream grpShow pending entries summary
XTRIM stream MAXLEN 1000Trim stream to max length
MULTIStart a transaction block
EXECExecute all commands in transaction
DISCARDDiscard all commands in transaction
WATCH keyWatch key for changes (optimistic lock)
UNWATCHUnwatch all keys
EVAL "return redis.call('GET',KEYS[1])" 1 keyRun Lua script
EVALSHA sha1 1 keyRun cached Lua script by SHA1
SCRIPT LOAD "return 1"Load script and return SHA1 hash
SCRIPT EXISTS sha1Check if script is cached
SCRIPT FLUSHRemove all cached scripts
FUNCTION LOAD "#!lua name=mylib\nredis.register_function('myfunc', function(keys, args) return 'ok' end)"Load a Redis Function (Redis 7+)
FCALL myfunc 0Call a loaded Redis Function
SAVESynchronous RDB snapshot (blocking!)
⚠️ Blocks server
BGSAVEBackground RDB snapshot
BGREWRITEAOFBackground AOF rewrite
LASTSAVETimestamp of last successful save
CONFIG SET save "900 1 300 10"Set RDB auto-save rules
CONFIG SET appendonly yesEnable AOF persistence
CONFIG SET appendfsync everysecAOF fsync policy (always/everysec/no)
REPLICAOF host 6379Make this server a replica of another
REPLICAOF NO ONEPromote replica to primary
INFO replicationGet replication status
WAIT 1 5000Wait for N replicas to acknowledge writes
ACL LISTList all ACL rules
ACL GETUSER defaultGet ACL rules for a user
ACL SETUSER alice on >pass ~key:* +get +setCreate user with specific permissions
ACL SETUSER alice offDisable a user
ACL DELUSER aliceDelete a user
ACL WHOAMIShow current authenticated username
ACL CATList all command categories
ACL CAT readList commands in a category
ACL LOG 10Show last 10 ACL denial events
ACL SAVESave ACL rules to file
ACL LOADReload ACL rules from file
CLUSTER INFOGet cluster state info
CLUSTER NODESList all cluster nodes
CLUSTER MEET host 6379Add a node to the cluster
CLUSTER ADDSLOTS 0 1 2 ... 5460Assign hash slots to this node
CLUSTER REPLICATE node-idMake this node a replica
CLUSTER FAILOVERManual failover (replica → primary)
CLUSTER RESETReset cluster configuration
CLUSTER KEYSLOT keyGet the hash slot for a key
CLUSTER SLOTSGet cluster slot mapping
redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-replicas 1Create a new cluster
SENTINEL MASTERSList monitored masters (Sentinel)
SENTINEL GET-MASTER-ADDR-BY-NAME mymasterGet current master address
SENTINEL FAILOVER mymasterForce failover (Sentinel)
PFADD visitors user1 user2 user3Add elements to HyperLogLog
PFCOUNT visitorsGet approximate cardinality
PFMERGE dest hll1 hll2Merge HyperLogLogs
SETBIT mybit 7 1Set bit at offset
GETBIT mybit 7Get bit at offset
BITCOUNT mybitCount bits set to 1
BITOP AND dest key1 key2Bitwise AND between keys
BITPOS mybit 1Find first bit set to 1
GEOADD locations 13.361 38.115 "Palermo"Add geospatial point
GEODIST locations Palermo Catania kmDistance between two points
GEOSEARCH locations FROMMEMBER Palermo BYRADIUS 100 km ASCSearch within radius
GEOPOS locations PalermoGet coordinates of a member
GEOHASH locations PalermoGet Geohash string
FLUSHDBDelete all keys in current database
⚠️ Destructive!
FLUSHDB ASYNCDelete all keys asynchronously
FLUSHALLDelete all keys in ALL databases
⚠️ Very destructive!
DEBUG SLEEP 5Pause the server for 5 seconds (debug)
DEBUG OBJECT keyShow internal encoding info for key
MEMORY USAGE keyEstimate memory usage of a key in bytes
MEMORY DOCTORGet memory usage advice
OBJECT HELPShow OBJECT subcommand help
OBJECT FREQ keyGet access frequency (LFU policy)
LATENCY LATESTShow latest latency events
LATENCY HISTORY eventShow latency history for an event
SHUTDOWN SAVESave and shut down the server
SHUTDOWN NOSAVEShut down without saving
redis-cli --scan --pattern 'user:*'Scan keys matching pattern from CLI
redis-cli --bigkeysFind biggest keys in the database
redis-cli --memkeysSample keys and report memory usage
redis-cli --hotkeysFind hottest keys (requires LFU)
redis-cli --statLive stats (ops/sec, memory, clients)
redis-cli --latencyMeasure latency to server continuously
redis-cli --latency-historyLatency with 15s interval history
redis-cli --pipe < commands.txtMass import with Redis protocol
redis-cli --rdb dump.rdbDownload RDB snapshot from remote
redis-cli --csv LRANGE mylist 0 -1Output in CSV format
redis-cli --json INFO memoryOutput in JSON format (Redis 7+)
redis-cli --eval script.lua key1 , arg1Evaluate Lua script from file
229 Redis commands · hover any command to copy
Continue Exploring
Other Developer Tools you might like...
JSON Formatter
Format, validate, and minify JSON data with syntax highlighting
Base64 Encoder/Decoder
Encode text to Base64 and decode Base64 strings
URL Encoder/Decoder
Encode and decode URL components and query strings
UUID Generator
Generate random UUID v4 identifiers
Hash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes from text
Regex Tester
Test and debug regular expressions with match highlighting
JWT Decoder
Decode and inspect JWT token header and payload
HTML Formatter
Beautify and format HTML code with proper indentation