Redis Cheat Sheet

Quick reference for Redis commands. Strings, hashes, lists, sets, sorted sets, pub/sub, and common operations — all in one page.

Strings Hashes Lists Sets & Sorted Sets Keys & Expiry Pub/Sub & Transactions

Strings

SET key value Set a string value
GET key Get value by key
MSET k1 v1 k2 v2 Set multiple keys
MGET k1 k2 Get multiple values
INCR key / DECR key Increment / decrement integer
INCRBY key 5 Increment by amount
APPEND key "text" Append to string
STRLEN key Get string length
SETNX key value Set only if key does not exist
SETEX key 3600 value Set with TTL (seconds)

Hashes

HSET user:1 name "Alice" Set hash field
HGET user:1 name Get hash field
HMSET user:1 name "Alice" age 30 Set multiple fields
HGETALL user:1 Get all fields and values
HDEL user:1 age Delete hash field
HEXISTS user:1 name Check if field exists
HINCRBY user:1 age 1 Increment hash field
HKEYS user:1 / HVALS user:1 Get all keys / values

Lists

LPUSH list val Push to head (left)
RPUSH list val Push to tail (right)
LPOP list / RPOP list Pop from head / tail
LRANGE list 0 -1 Get all elements
LLEN list Get list length
LINDEX list 0 Get element by index
LREM list 1 val Remove elements matching val
BLPOP list 30 Blocking pop (30s timeout)

Sets & Sorted Sets

SADD myset val Add to set
SMEMBERS myset Get all members
SISMEMBER myset val Check membership
SCARD myset Set size (cardinality)
SUNION s1 s2 / SINTER s1 s2 Union / intersection
ZADD zset 10 val Add to sorted set with score
ZRANGE zset 0 -1 WITHSCORES Get all by score (ascending)
ZRANK zset val Get rank of member
ZRANGEBYSCORE zset 0 100 Get members in score range

Keys & Expiry

DEL key Delete key
EXISTS key Check if key exists
EXPIRE key 3600 Set TTL in seconds
PEXPIRE key 5000 Set TTL in milliseconds
TTL key / PTTL key Get remaining TTL (s / ms)
PERSIST key Remove expiry
KEYS pattern Find keys by pattern (avoid in prod)
SCAN 0 MATCH user:* COUNT 100 Iterate keys safely
TYPE key Get data type of key
RENAME key newkey Rename a key

Pub/Sub & Transactions

PUBLISH channel message Publish message to channel
SUBSCRIBE channel Subscribe to channel
PSUBSCRIBE user:* Pattern subscribe
MULTI Start transaction
EXEC Execute transaction
DISCARD Discard transaction
WATCH key Watch key for optimistic locking

Try It Live

Test these patterns with our free API Tester. No signup needed.

Open API Tester →
Step-by-Step Guide

How to Build Docker Compose

Read Guide →

More Cheat Sheets