Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
DatabaseintermediateNew

Redis Data Structures

Share

Use Redis data structures (strings, hashes, lists, sets, sorted sets)

Works with OpenClaude

You 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 ping to 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

  1. Connect to Redis using a client library (redis-py, node-redis, or ioredis) with proper error handling
  2. Use strings with SET, GET, INCR, APPEND for simple key-value caching and counters
  3. Use hashes with HSET, HGET, HGETALL to store object-like data with multiple fields per key
  4. Use lists with LPUSH, RPUSH, LPOP, RPOP, LRANGE for ordered collections and queue operations
  5. Use sets with SADD, SMEMBERS, SISMEMBER, SINTER, SUNION for unique values and membership testing
  6. Use sorted sets with ZADD, ZRANGE, ZRANK, ZREM for ranked data, leaderboards, and time-series with scores
  7. Pipeline commands using client library methods to reduce round-trips for bulk operations
  8. Set appropriate TTLs with EXPIRE or PEXPIRE to 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

Quick Info

CategoryDatabase
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
redisdata-structurescaching

Install command:

curl -o ~/.claude/skills/redis-data-structures.md https://clskills.in/skills/database/redis-data-structures.md

Related Database Skills

Other Claude Code skills in the same category — free to download.

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.