Redis Cheat Sheet
Keys, hashes, lists, expiry, pub/sub, and the server ops commands for the fastest structure store.
Strings
10SET key valueSet a value
SET key value EX 60Set with 60s expiry
SETNX key valueSet only if it doesn't exist
GET keyRead a value
INCR keyIncrement a counter
INCRBY key 50Add a fixed amount
GETSET key newvalueSet and return old value
MSET a 1 b 2Set multiple keys at once
TTL keyTime to live in seconds
EXPIRE key 300Set an expiry
Hashes & Lists
10HSET user:1 name alice role adminSet hash fields
HGET user:1 nameRead one field
HGETALL user:1All fields
HINCRBY user:1 login_count 1Increment a field
LPUSH queue job1Push to the head of a list
RPUSH queue job2Push to the tail
LPOP / RPOP queuePop head or tail
LRANGE queue 0 -1All list items
BLPOP queue 5Blocking pop with 5s timeout
LLEN queueList length
Sets & Sorted Sets
9SADD trackers user:1Add to a set
SMEMBERS trackersAll set members
SISMEMBER trackers user:1Membership check
SINTER online activeIntersection
ZADD scores 95 aliceAdd with a score
ZRANGE scores 0 4 WITHSCORESTop 5 by score
ZREVRANGE scores 0 4Top 5 descending
ZRANK scores aliceRank of a member
ZINCRBY scores 5 aliceBump a score
Pub/Sub & Keyspace
7SUBSCRIBE channelListen to a channel
PUBLISH channel messageSend a message
KEYS 'user:*'Find keys by pattern (avoid on big DBs)
SCAN 0 MATCH 'user:*' COUNT 100Cursor-based scan (safe)
DEL keyDelete a key
EXISTS keyCheck a key exists
TYPE keyData type of a key
Server Ops
10INFOServer stats (sections per arg)
INFO memoryMemory usage
CLIENT LISTConnected clients
CONFIG GET maxmemoryRead a config
CONFIG SET maxmemory 512mbSet a runtime config
DBSIZECount of keys
FLUSHDB / FLUSHALLClear the database / all
SAVE / BGSAVESnapshot now / background
redis-cli --no-auth-warningSuppress the password warning
redis-cli -u redis://user:pass@host:6379Connect with URI