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.

Databases·43 commands·Last updated 2026-07-21
Back to Databases

Connection 6

redis-cli -h 127.0.0.1 -p 6379 -a password
Connect 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 memory
Collect memory info every second, 5 times, for monitoring
AUTH password
Authenticate after connecting
SELECT 0
Switch to database 0 (not supported in cluster mode)
DBSIZE
View number of keys in current database

Data Structure 11

SET key value EX 300
Set key-value with 300s expiry, atomic operation
GET key
Get string value
MSET k1 v1 k2 v2
Batch set, reduces round trips
HSET user:1 name "tom" age 30
Set hash fields
HGETALL user:1
Get all hash fields and values
LPUSH queue task1
Left push to list (head)
BRPOP queue 30
Blocking right pop (tail), 30s timeout
ZADD rank 100 "user1" 200 "user2"
Add sorted set members with scores
ZRANGE rank 0 -1 WITHSCORES
Return all members sorted by score ascending
SADD tags "python" "redis"
Add set members
SINTER set1 set2
Intersection of sets

Key Space 8

EXPIRE key 300
Set expiry in 300 seconds
TTL key
View remaining TTL (-1 forever, -2 does not exist)
TYPE key
Check data type of key
DEL key1 key2
Delete multiple keys
UNLINK key
Async delete large key, won't block main thread
RENAME old_key new_key
Rename key
RANDOMKEY
Return a random key
OBJECT ENCODING key
View internal encoding (ziplist/hashtable/intset)

Persistence & Memory 7

BGSAVE
Background async RDB snapshot, non-blocking
LASTSAVE
View Unix timestamp of last successful RDB save
BGREWRITEAOF
Background async AOF rewrite, compact file size
INFO memory
View memory details, check used_memory_human and mem_fragmentation_ratio
MEMORY USAGE key
Check memory usage of a single key in bytes
CONFIG GET maxmemory
View max memory limit
CONFIG GET maxmemory-policy
View eviction policy (noeviction/allkeys-lru etc.)

Slowlog & Monitor 6

SLOWLOG GET 10
View last 10 slow queries
SLOWLOG RESET
Clear slow query log
CONFIG GET slowlog-log-slower-than
View slow query threshold (microseconds, 0=all, -1=disabled)
CLIENT LIST
List all connections, find idle connections and source IPs
CLIENT KILL ID <id>
Kill a specific connection
INFO clients
View client statistics, check connected_clients and blocked_clients

Cluster & Replication 5

CLUSTER INFO
View cluster status, cluster_state should be ok
CLUSTER NODES
View all node roles and connection status
CLUSTER KEYSLOT key
Check hash slot of a key (0-16383)
INFO replication
View master/slave role and sync status
ROLE
Quick 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.