Redis Cheat Sheet
Practical Redis cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
redis queries schema performance
Redis cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the MongoDB Cheat Sheet and Django Cheat Sheet.
Setup and Connection
Goal: Connect to database shell or endpoint
# Run connection or version command
redis-cli
# Run connection or version command
redis-cli -h 127.0.0.1 -p 6379
# Run connection or version command
redis-cli PING
Schema and Data Modeling
Goal: Create a table/index/schema foundation
# Write and expire cache entries
SET session:123 '{"userId":42}' EX 3600
SETNX lock:job:daily $(date +%s)
Core Queries and Mutations
Goal: Run practical read/write operations
# Read key values and data structures
GET session:123
HSET user:42 name "Rem" role "admin"
HGETALL user:42
Performance and Optimization
Goal: Add indexes and inspect query plans
# Inspect keyspace and memory usage
SCAN 0 MATCH session:* COUNT 100
MEMORY USAGE session:123
INFO memory
Automation and Backups
Goal: Create backup and restore routines
# Export data snapshot before risky migrations
pg_dump "$DATABASE_URL" > backup.sql || mysqldump appdb > backup.sql || true
# Compress backup artifact for storage
gzip -f backup.sql || true
# Verify backup file exists and has content
ls -lh backup.sql.gz || ls -lh backup.sql
Debugging and Troubleshooting
Goal: Inspect slow-query symptoms
# Check active connections/sessions
psql -c "SELECT now();" || mysql -e "SELECT NOW();" || true
# Inspect query plans for heavy statements
psql -c "EXPLAIN SELECT 1;" || mysql -e "EXPLAIN SELECT 1;" || true
# Search migration files for destructive statements
rg "DROP TABLE|TRUNCATE|DELETE FROM" prisma migrations sql -n
Common Gotchas
- Use transactions for multi-step Redis data changes that must stay consistent.
- Create indexes for frequent WHERE and JOIN columns, then verify with query plans.
- Back up production data before schema migrations.
- Separate read-only credentials from write credentials in app environments.
- Monitor connection pool limits to avoid timeout spikes under load.
Related Sheets
- MongoDB Cheat Sheet — daily MongoDB commands and production-ready examples.
- Django Cheat Sheet — daily Django commands and production-ready examples.
- Elixir Cheat Sheet — daily Elixir commands and production-ready examples.
Related Cheat Sheets
Django Cheat Sheet
Practical Django cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Elixir Cheat Sheet
Practical Elixir cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
MongoDB Cheat Sheet
Practical MongoDB cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.