Redis Cheatsheet - Redis Command Reference
Essential Redis commands for daily cache administration and development. Organized by scenario from data structure operations to memory troubleshooting. Copy and use directly during troubleshooting.
Back to DatabasesConnection 6
redis-cli -h 127.0.0.1 -p 6379 -a passwordConnect to instance, -a specifies password (warns about security)
redis-cli --scan --pattern "user:*"Safely scan matching keys, avoid KEYS (blocking)
redis-cli -r 5 -i 1 INFO memoryCollect memory info every second, 5 times, for monitoring
AUTH passwordAuthenticate after connecting
SELECT 0Switch to database 0 (not supported in cluster mode)
DBSIZEView number of keys in current database
Data Structure 11
SET key value EX 300Set key-value with 300s expiry, atomic operation
GET keyGet string value
MSET k1 v1 k2 v2Batch set, reduces round trips
HSET user:1 name "tom" age 30Set hash fields
HGETALL user:1Get all hash fields and values
LPUSH queue task1Left push to list (head)
BRPOP queue 30Blocking right pop (tail), 30s timeout
ZADD rank 100 "user1" 200 "user2"Add sorted set members with scores
ZRANGE rank 0 -1 WITHSCORESReturn all members sorted by score ascending
SADD tags "python" "redis"Add set members
SINTER set1 set2Intersection of sets
Key Space 8
EXPIRE key 300Set expiry in 300 seconds
TTL keyView remaining TTL (-1 forever, -2 does not exist)
TYPE keyCheck data type of key
DEL key1 key2Delete multiple keys
UNLINK keyAsync delete large key, won't block main thread
RENAME old_key new_keyRename key
RANDOMKEYReturn a random key
OBJECT ENCODING keyView internal encoding (ziplist/hashtable/intset)
Persistence & Memory 7
BGSAVEBackground async RDB snapshot, non-blocking
LASTSAVEView Unix timestamp of last successful RDB save
BGREWRITEAOFBackground async AOF rewrite, compact file size
INFO memoryView memory details, check used_memory_human and mem_fragmentation_ratio
MEMORY USAGE keyCheck memory usage of a single key in bytes
CONFIG GET maxmemoryView max memory limit
CONFIG GET maxmemory-policyView eviction policy (noeviction/allkeys-lru etc.)
Slowlog & Monitor 6
SLOWLOG GET 10View last 10 slow queries
SLOWLOG RESETClear slow query log
CONFIG GET slowlog-log-slower-thanView slow query threshold (microseconds, 0=all, -1=disabled)
CLIENT LISTList all connections, find idle connections and source IPs
CLIENT KILL ID <id>Kill a specific connection
INFO clientsView client statistics, check connected_clients and blocked_clients
Cluster & Replication 5
CLUSTER INFOView cluster status, cluster_state should be ok
CLUSTER NODESView all node roles and connection status
CLUSTER KEYSLOT keyCheck hash slot of a key (0-16383)
INFO replicationView master/slave role and sync status
ROLEQuick check role (master/slave) and offset
💡 Tips
- Never use KEYS * in production — use SCAN instead. KEYS blocks the main thread and causes stuttering.
- Use UNLINK instead of DEL for large keys (lists/hashes/sets) — DEL blocks the main thread.
- mem_fragmentation_ratio > 1.5 indicates high fragmentation — consider restarting or enabling activedefrag.