Redis Cheat Sheet
Redis commands for strings, lists, sets, hashes, sorted sets, pub/sub, and expiration, covering the core in-memory data structure operations.
2 PagesIntermediateFeb 28, 2026
Strings & Expiry
Basic key/value operations and TTLs.
bash
redis-cliSET key "value"GET keySETEX key 60 "value" # set with 60s expiryINCR counterEXPIRE key 30 # set TTL in secondsTTL key # seconds remaining, -1 = no expiryDEL key
Data Structures
Lists, sets, hashes, and sorted sets.
bash
LPUSH mylist "a" "b" # listLRANGE mylist 0 -1SADD myset "a" "b" # setSMEMBERS mysetHSET user:1 name "Alice" age 30 # hashHGETALL user:1ZADD leaderboard 100 "alice" # sorted setZRANGE leaderboard 0 -1 WITHSCORES
Common Commands
Frequently used commands beyond basic gets/sets.
- KEYS pattern- finds keys matching a pattern; blocks the server, avoid in production
- SCAN cursor- cursor-based, non-blocking key iteration; production-safe alternative to KEYS
- EXPIRE / PERSIST- set or remove a key's time-to-live
- MULTI / EXEC- queues commands and executes them atomically as a transaction
- PUBLISH / SUBSCRIBE- publish/subscribe messaging between clients
- FLUSHDB- deletes every key in the currently selected database
Pub/Sub & Pipelines
Messaging and batching commands from a client.
python
# Pub/Sub (redis-cli)# SUBSCRIBE channel1# PUBLISH channel1 "hello"# Pipeline example (redis-py)import redisr = redis.Redis()pipe = r.pipeline()pipe.set('a', 1)pipe.incr('a')results = pipe.execute() # batches commands in one round trip
Pro Tip
Never run the KEYS command against a production instance — it scans the entire keyspace and blocks the single-threaded event loop; use SCAN instead for safe, incremental iteration.
Was this cheat sheet helpful?
Explore Topics
#Redis#RedisCheatSheet#Database#Intermediate#StringsExpiry#DataStructures#CommonCommands#PubSubPipelines#Databases#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance