Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Redis Hashes are maps between string fields and string values - perfect for object storage.
Hash Commands
# Basic operations
HSET key field value [field value ...] # O(N)
HGET key field # O(1)
HGETALL key # O(N)
HDEL key field [field ...] # O(N)
HEXISTS key field # O(1)
# Bulk operations
HMSET key field value [field value ...] # Deprecated, use HSET
HMGET key field [field ...] # O(N)
# Numeric operations
HINCRBY key field increment # O(1)
HINCRBYFLOAT key field increment # O(1)
# Metadata
HLEN key # O(1)
HKEYS key # O(N)
HVALS key # O(N)
HSCAN key cursor [MATCH pattern] [COUNT count]
# Advanced (Redis 7.4+)
HSETEX key seconds field value # Set with TTL
HGETEX key field EX seconds # Get with TTL refresh
Sorted Sets Overview
Sorted Sets combine Sets with scores, enabling ranked collections.
Sorted Set Commands
# Add with scores
ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
# Range queries by index
ZRANGE key start stop [BYSCORE|BYLEX] [REV] [LIMIT offset count] [WITHSCORES]
ZREVRANGE key start stop [WITHSCORES] # Deprecated, use ZRANGE REV
# Range by score
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] # Deprecated
ZRANGE key min max BYSCORE [WITHSCORES] [LIMIT offset count]
# Ranking
ZRANK key member # 0-based rank (lowest first)
ZREVRANK key member # 0-based rank (highest first)
ZSCORE key member # Get score
# Modifications
ZINCRBY key increment member # Increment score - O(log N)
ZREM key member [member ...] # Remove - O(M*log N)
# Cardinality
ZCARD key # Total count - O(1)
ZCOUNT key min max # Count in range - O(log N)
# Set operations
ZINTER numkeys key [key ...] # Intersection
ZUNION numkeys key [key ...] # Union
ZDIFF numkeys key [key ...] # Difference
Production Patterns
Pattern 1: User Profile Storage
# Store user as hash
HSET user:123 name "John" email "john@example.com" age "30" status "active"
# Get specific fields (efficient)
HMGET user:123 name email
# Update single field
HSET user:123 status "premium"
# Atomic counter in hash
HINCRBY user:123 login_count 1
HINCRBY user:123 points 100
# Check field exists
HEXISTS user:123 email
Pattern 2: Leaderboard System
# Add/Update scores
ZADD leaderboard 1000 "player:1"
ZADD leaderboard 1500 "player:2"
ZADD leaderboard 800 "player:3"
# Increment score (game points)
ZINCRBY leaderboard 50 "player:1"
# Get top 10 (highest scores)
ZRANGE leaderboard 0 9 REV WITHSCORES
# Get player rank (0-indexed)
ZREVRANK leaderboard "player:1"
# Get player score
ZSCORE leaderboard "player:1"
# Get players around a rank
ZRANGE leaderboard 5 15 REV WITHSCORES
# Count players above threshold
ZCOUNT leaderboard 1000 +inf
Pattern 3: Time-Based Scoring (Activity Feed)
# Add items with timestamp as score
ZADD feed:user:123 1704067200 "post:456"
ZADD feed:user:123 1704153600 "post:789"
# Get recent items
ZRANGE feed:user:123 0 19 REV
# Get items from time range
ZRANGE feed:user:123 1704000000 1704200000 BYSCORE
# Remove old items
ZREMRANGEBYSCORE feed:user:123 -inf 1703980800
Pattern 4: Rate Limiting with Sorted Set
# Sliding window rate limiter
-- Add request with timestamp
ZADD ratelimit:user:123 1704067200.123 "req:uuid1"
-- Remove old entries (outside window)
ZREMRANGEBYSCORE ratelimit:user:123 -inf 1704067140.123
-- Count requests in window
ZCARD ratelimit:user:123
-- Check if under limit
-- If ZCARD < 100, allow request
Pattern 5: Product Inventory with Hash
# Store product
HSET product:sku:ABC123 \
name "Redis T-Shirt" \
price "29.99" \
stock "100" \
category "apparel"
# Decrement stock atomically
HINCRBY product:sku:ABC123 stock -1
# Get product info
HGETALL product:sku:ABC123
# Update price
HSET product:sku:ABC123 price "24.99"
Pattern 6: Session Storage
# Store session data
HSET session:abc123 \
user_id "123" \
created "1704067200" \
ip "192.168.1.1" \
user_agent "Mozilla/5.0"
# Set session TTL
EXPIRE session:abc123 3600
# Update last access
HSET session:abc123 last_access "1704070800"
# Get specific session data
HMGET session:abc123 user_id created
Command Complexity
Command
Complexity
Notes
HSET/HGET
O(1)
Single field
HMSET/HMGET
O(N)
N = fields
HGETALL
O(N)
Returns all
HINCRBY
O(1)
Atomic
ZADD
O(log N)
Per member
ZRANGE
O(log N + M)
M = returned
ZRANK
O(log N)
Binary search
ZINCRBY
O(log N)
Update + reorder
ZCARD
O(1)
Stored metadata
Memory Optimization
Hash Ziplist Encoding
# redis.conf - Use ziplist for small hashes
hash-max-ziplist-entries 512
hash-max-ziplist-value 64