String
SET key value EX 3600 | Set with TTL (seconds) |
GET key | Get value |
INCR counter | Atomic increment |
MSET k1 v1 k2 v2 | Set multiple keys |
MGET k1 k2 | Get multiple keys |
SETNX key value | Set if not exists |
Hash
HSET user name Alice age 30 | Set hash fields |
HGET user name | Get hash field |
HGETALL user | Get all fields |
HDEL user age | Delete field |
List
LPUSH queue item | Push to head |
RPUSH queue item | Push to tail |
LPOP queue | Pop from head |
LRANGE queue 0 -1 | Get all elements |
BLPOP queue 10 | Blocking pop (10s timeout) |
Set & Sorted Set
SADD myset a b c | Add to set |
SMEMBERS myset | Get all members |
ZADD rank 100 Alice 200 Bob | Add to sorted set |
ZRANGE rank 0 -1 WITHSCORES | Get sorted set |
ZRANGEBYSCORE rank 100 200 | Range by score |
Key Management
TTL key | Get remaining TTL |
EXPIRE key 3600 | Set TTL |
DEL key | Delete key |
KEYS pattern* | Find keys (avoid in prod) |
SCAN 0 MATCH prefix* COUNT 100 | Iterate keys safely |
Pub/Sub & Transactions
SUBSCRIBE channel | Subscribe to channel |
PUBLISH channel msg | Publish message |
MULTI / EXEC / DISCARD | Transaction |
WATCH key | Optimistic lock |