Skip to content

13. Cheat Sheet

13.1 Data Type Commands Quick Reference

TypeCommandDescription
StringSET key valSet value
GET keyGet value
MSET / MGETBatch set/get
INCR / DECRIncrement/decrement
INCRBY key nAdd n
SETNX key valSet if not exists
ListLPUSH / RPUSHPush to left/right
LPOP / RPOPPop from left/right
LRANGE start stopRange query
LLEN keyList length
BRPOP key timeoutBlocking pop
HashHSET key field valSet field
HGET key fieldGet field
HGETALL keyGet all fields
HDEL key fieldDelete field
HINCRBY key field nIncrement field by n
SetSADD key memberAdd member
SMEMBERS keyAll members
SISMEMBER key mCheck membership
SINTER key1 key2Intersection
SUNION key1 key2Union
ZSetZADD key score mAdd scored member
ZRANGE key 0 -1Ascending range
ZREVRANGE key 0 2Top N descending
ZSCORE key mGet score
ZINCRBY key n mAdd n to score

13.2 Key Management Quick Reference

CommandDescriptionTime Complexity
EXISTS keyCheck if key existsO(1)
DEL keyDelete keyO(N) N=field count
UNLINK keyAsync delete keyO(1)
EXPIRE key secondsSet expirationO(1)
TTL keyRemaining TTLO(1)
PERSIST keyRemove expirationO(1)
TYPE keyKey data typeO(1)
RENAME old newRename keyO(1)
SCAN cursorIterate key spaceO(1) per call

13.3 Server Management Quick Reference

CommandDescription
INFOServer info (ALL/MEMORY/CPU/REPLICATION/...)
CONFIG GET parameterGet configuration
CONFIG SET parameter valueModify configuration
CONFIG REWRITEPersist config to file
DBSIZEKey count in current DB
FLUSHDBFlush current DB
FLUSHALLFlush all DBs (use with caution!)
MONITORReal-time monitor all commands
CLIENT LISTList client connections
CLIENT KILLDisconnect client
SLOWLOG GET nView slow queries
BGREWRITEAOFTrigger AOF rewrite
BGSAVEBackground RDB snapshot
LASTSAVELast snapshot timestamp

13.4 Development Guidelines Quick Reference

  • 🔑 Key naming convention: business:object:ID:attribute, e.g. user:1001:profile
  • 📏 Key length: Try to keep under 44 bytes (jemalloc memory alignment)
  • 📦 Value size: String no more than 10KB, Hash/Set/ZSet no more than 5000 elements
  • ⏱️ Expiration: All cache keys should have expiration times set to prevent memory leaks
  • 🚫 Disabled commands: KEYS, FLUSHALL, FLUSHDB should be disabled in production
  • 🔌 Connection pool: Use connection pooling to reuse connections, avoid frequent create/destroy
  • 🔄 Pipeline: Prefer Pipeline for batch operations
  • 🧵 Serialization: Use MessagePack/Protobuf instead of JSON for complex objects to save space

13.5 Deployment Architecture Selection

ScenarioArchitectureNode Count
Development/testingSingle node1
Small production (read-heavy)Replication + Sentinel1 master + 2 replicas + 3 sentinels
Medium production (high availability)Replication + Sentinel1 master + 2 replicas + 3 sentinels (per master)
Large production (high data volume)Redis ClusterAt least 6 nodes (3 masters + 3 replicas)
Ultra-large scaleRedis Cluster + ProxyMulti-cluster + Proxy (e.g. Twemproxy)