Use Redis data structures (strings, hashes, lists, sets, sorted sets)
✓Works with OpenClaudeYou are a Redis developer. The user wants to efficiently use all five core Redis data structures (strings, hashes, lists, sets, sorted sets) with practical examples and correct syntax.
What to check first
- Run
redis-cli pingto confirm Redis server is running and accessible - Check your Redis client library version with
npm list redis(or equivalent for your language) - Verify Redis is listening on the expected host/port (default: localhost:6379)
Steps
- Connect to Redis using a client library (redis-py, node-redis, or ioredis) with proper error handling
- Use strings with
SET,GET,INCR,APPENDfor simple key-value caching and counters - Use hashes with
HSET,HGET,HGETALLto store object-like data with multiple fields per key - Use lists with
LPUSH,RPUSH,LPOP,RPOP,LRANGEfor ordered collections and queue operations - Use sets with
SADD,SMEMBERS,SISMEMBER,SINTER,SUNIONfor unique values and membership testing - Use sorted sets with
ZADD,ZRANGE,ZRANK,ZREMfor ranked data, leaderboards, and time-series with scores - Pipeline commands using client library methods to reduce round-trips for bulk operations
- Set appropriate TTLs with
EXPIREorPEXPIREto auto-evict cached data
Code
import redis
from datetime import timedelta
# Connect to Redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
# STRING: Simple caching, counters, session data
r.set('user:1:name', 'Alice')
r.set('page:views', 100, ex=3600) # Expire in 1 hour
r.incr('page:views') # Atomic increment
print(f"String GET: {r.get('user:1:name')}")
# HASH: User profiles, configuration objects
r.hset('user:1', mapping={'name': 'Alice', 'email': 'alice@example.com', 'age': 30})
r.hget('user:1', 'email')
r.hmget('user:1', ['name', 'age'])
print(f"Hash HGETALL: {r.hgetall('user:1')}")
# LIST: Message queues, activity feeds, real-time logs
r.lpush('notifications:user:1', 'You have a new message')
r.lpush('notifications:user:1', 'Your post was liked')
r.rpush('job:queue', 'send_email_job_123', 'generate_report_456')
print(f"List LRANGE: {r.lrange
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Database Skills
Other Claude Code skills in the same category — free to download.
Migration Generator
Generate database migration files
Query Optimizer
Analyze and optimize slow database queries
Schema Designer
Design database schema from requirements
Seed Data Generator
Generate database seed/sample data
Index Advisor
Suggest database indexes based on query patterns
ORM Model Generator
Generate ORM models from database schema
SQL to ORM
Convert raw SQL queries to ORM syntax
Database Backup Script
Create database backup and restore scripts
Want a Database skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.