
Redis
- 53 installs
- 1 repo stars
- Updated January 5, 2026
- pluginagentmarketplace/custom-plugin-sql
Helps with ai & agent building tasks.
About
redis is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- redis
- AI & Agent Building
- AI-coding skill
Redis by the numbers
- 53 all-time installs (skills.sh)
- +1 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #6,979 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill redisAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 53 |
|---|---|
| repo stars | ★ 1 |
| Last updated | January 5, 2026 |
| Repository | pluginagentmarketplace/custom-plugin-sql ↗ |
What it does
Helps with ai & agent building tasks.
Files
Redis Data Structures
Getting Started
# Start Redis server
redis-server
# Connect to Redis CLI
redis-cli
# Test connection
ping # Returns "PONG"
# Select database
SELECT 0 # Default database
SELECT 1 # Database 1String Operations
// SET and GET
SET key value
SET user:1:name "John Doe"
GET user:1:name
// SET with options
SET key value EX 3600 // Expire in 3600 seconds
SET key value PX 3600000 // Expire in milliseconds
SET key value NX // Only if not exists
SET key value XX // Only if exists
// Numeric operations
SET counter 0
INCR counter // Increment by 1
INCRBY counter 5 // Increment by N
DECR counter // Decrement by 1
DECRBY counter 3 // Decrement by N
INCRBYFLOAT counter 2.5 // Increment by float
// String operations
APPEND key " suffix" // Append to string
STRLEN key // Get length
GETRANGE key 0 3 // Get substring
SETRANGE key 0 "new" // Set substring
// Multiple keys
MSET key1 val1 key2 val2 // Set multiple
MGET key1 key2 // Get multiple
GETSET key newval // Get old value and set newList Operations (Ordered collections)
// Push operations
LPUSH list value1 value2 // Push to left
RPUSH list value1 value2 // Push to right
LPUSHX list value // Push only if exists
RPUSHX list value // Push only if exists
// Pop operations
LPOP list // Remove and get from left
RPOP list // Remove and get from right
LPOP list 2 // Pop multiple (Redis 6.2+)
// List queries
LRANGE list 0 -1 // Get all elements
LRANGE list 0 2 // Get first 3 elements
LINDEX list 1 // Get element at index
LLEN list // Get list length
LSET list 0 newvalue // Set element at index
// Blocking operations
BLPOP list1 list2 10 // Block until pop or timeout
BRPOP list1 list2 10 // Block until right pop
BRPOPLPUSH src dst 10 // Block, pop right, push left
// Trimming
LTRIM list 0 2 // Keep only first 3 elementsHash Operations (Maps/objects)
// SET and GET
HSET hash field value // Set single field
HSET hash f1 v1 f2 v2 // Set multiple fields
HGET hash field // Get field value
HGETALL hash // Get all fields and values
// Existence and length
HEXISTS hash field // Check field exists
HLEN hash // Number of fields
HKEYS hash // Get all field names
HVALS hash // Get all values
HSTRLEN hash field // Get value length
// Update operations
HINCRBY hash field 5 // Increment numeric field
HINCRBYFLOAT hash field 2.5 // Increment by float
HSETNX hash field value // Set only if not exists
// Delete
HDEL hash field1 field2 // Delete fieldsSet Operations (Unordered unique values)
// Add and remove
SADD set member1 member2 // Add members
SREM set member1 member2 // Remove members
SISMEMBER set member // Check membership
SMEMBERS set // Get all members
SCARD set // Count members
// Set operations
SINTER set1 set2 // Intersection
SUNION set1 set2 // Union
SDIFF set1 set2 // Difference
SINTERSTORE dest s1 s2 // Store intersection result
SUNIONSTORE dest s1 s2 // Store union result
SDIFFSTORE dest s1 s2 // Store difference result
// Pop operations
SPOP set // Remove and return random member
SPOP set 2 // Remove and return N members
SRANDMEMBER set // Get random member without removing
SRANDMEMBER set 3 // Get N random membersSorted Set Operations (Ordered by score)
// Add and remove
ZADD zset 1 member1 2 member2 // Add with scores
ZREM zset member1 // Remove members
ZCARD zset // Count members
ZSCORE zset member // Get score
// Range queries by score
ZRANGE zset 0 -1 // Get all by index
ZRANGE zset 0 -1 WITHSCORES // With scores
ZREVRANGE zset 0 -1 // Reverse order
ZREVRANGE zset 0 -1 WITHSCORES // Reverse with scores
ZRANGEBYSCORE zset 10 50 // Get by score range
ZRANGEBYSCORE zset -inf +inf // All scores
ZRANGEBYSCORE zset 10 50 LIMIT 0 5 // Pagination
// Score operations
ZINCRBY zset 5 member // Increment score
ZCOUNT zset 10 50 // Count in score range
// Rank queries
ZRANK zset member // Get rank (0-based)
ZREVRANK zset member // Get reverse rankKey Operations
// Key management
KEYS pattern // Find keys matching pattern
EXISTS key1 key2 // Check key existence
DEL key1 key2 // Delete keys
UNLINK key1 key2 // Async delete
TYPE key // Get key type
// Expiration
EXPIRE key 3600 // Set expiration (seconds)
PEXPIRE key 3600000 // Set expiration (milliseconds)
TTL key // Get TTL (seconds)
PTTL key // Get TTL (milliseconds)
PERSIST key // Remove expiration
// Renaming
RENAME oldkey newkey // Rename key
RENAMENX oldkey newkey // Rename only if new doesn't existTransactions & Atomicity
// Transaction execution
MULTI // Start transaction
SET key1 value1
INCR key2
GET key3
EXEC // Execute all commands atomically
// Discard transaction
MULTI
SET key value
DISCARD // Cancel transaction
// Watch keys
WATCH key1 key2 // Monitor keys for changes
MULTI
SET key1 newvalue
EXEC // Fails if keys changedPub/Sub Messaging
// Publisher
PUBLISH channel "message" // Publish to channel
// Subscriber
SUBSCRIBE channel1 channel2 // Subscribe to channels
PSUBSCRIBE pattern* // Subscribe to pattern
UNSUBSCRIBE channel // Unsubscribe
PUNSUBSCRIBE pattern // Unsubscribe from pattern
// Query subscriptions
PUBSUB CHANNELS // Active channels
PUBSUB NUMSUB ch1 ch2 // Subscribers per channel
PUBSUB NUMPAT // Pattern subscriptions countServer Commands
DBSIZE // Total keys in DB
FLUSHDB // Clear current DB
FLUSHALL // Clear all DBs
SAVE // Synchronous save
BGSAVE // Background save
LASTSAVE // Last save time
INFO // Server statistics
CONFIG GET parameter // Get config value
CONFIG SET parameter value // Set config valueNext Steps
Learn Redis patterns for caching, sessions, rate limiting, and real-time applications in the redis-patterns skill.
sql_skill: redis
Redis Patterns & Use Cases
Caching Patterns
Cache-Aside (Lazy Loading)
// Pseudocode for cache-aside pattern
function getValue(key) {
// Check cache first
const cached = redis.get(key)
if (cached !== null) {
return cached
}
// Cache miss - fetch from database
const value = database.query(key)
// Store in cache with expiration
redis.setex(key, 3600, value) // Cache for 1 hour
return value
}Write-Through Cache
// Write to cache and database together
function setValue(key, value) {
// Write to both cache and database
redis.set(key, value)
database.insert(key, value)
return value
}
// Always read from cache
function getValue(key) {
return redis.get(key)
}Cache Invalidation
// Invalidate on update
SET user:1 '{"name":"John","email":"john@example.com"}'
// Update user
UPDATE users SET name="Jane" WHERE id=1
// Invalidate cache
DEL user:1
// Pattern invalidation
KEYS user:*
// Then DEL each key
// Tag-based invalidation
SADD tags:user:1 "user:1"
SADD tags:user:1 "posts:1"
// Later, invalidate by tag
SMEMBERS tags:user:1
// DEL all returned keysSession Management
// Store session data
function createSession(sessionId, userData) {
const sessionKey = `session:${sessionId}`
redis.hset(sessionKey, 'user_id', userData.id)
redis.hset(sessionKey, 'username', userData.username)
redis.hset(sessionKey, 'created_at', Date.now())
redis.expire(sessionKey, 86400) // 24 hours
return sessionId
}
// Get session data
function getSession(sessionId) {
return redis.hgetall(`session:${sessionId}`)
}
// Update session expiration (on each request)
function refreshSession(sessionId) {
redis.expire(`session:${sessionId}`, 86400)
}
// Logout (delete session)
function logout(sessionId) {
redis.del(`session:${sessionId}`)
}Rate Limiting
Token Bucket Algorithm
function isRateLimited(userId, limit, window) {
const key = `ratelimit:${userId}`
const current = redis.get(key)
if (current === null) {
redis.setex(key, window, 1)
return false
}
const count = parseInt(current) + 1
if (count > limit) {
return true // Rate limited
}
redis.incr(key)
return false
}
// Usage: Check before allowing API request
if (isRateLimited(userId, 100, 60)) {
return "Too many requests"
}Sliding Window Counter
// Increment counter for user in current minute
INCR ratelimit:user:1:2024-01-15-10-30
EXPIRE ratelimit:user:1:2024-01-15-10-30 60
// Check limit
GET ratelimit:user:1:2024-01-15-10-30
// If > 1000, rate limitedLeaderboards & Rankings
// Add or update score
ZADD leaderboard:game1 100 player1
ZADD leaderboard:game1 150 player2
ZADD leaderboard:game1 120 player3
// Get top 10 players
ZREVRANGE leaderboard:game1 0 9 WITHSCORES
// Get player rank
ZREVRANK leaderboard:game1 player2 // Returns 0 (first place)
// Get player score
ZSCORE leaderboard:game1 player1
// Increase player score
ZINCRBY leaderboard:game1 50 player1
// Get rank with score
function getPlayerStats(leaderboard, player) {
const rank = redis.zrevrank(leaderboard, player)
const score = redis.zscore(leaderboard, player)
return { rank: rank + 1, score } // Rank is 1-based
}
// Get players around current player
ZREVRANK leaderboard:game1 player2 // Get rank (5)
ZREVRANGE leaderboard:game1 3 7 WITHSCORES // Get surroundingReal-Time Analytics
Counters
// Track page views
INCR page:views:home
INCR page:views:about
// Track user actions
INCR user:1:logins
INCR user:1:posts
// Get daily stats (auto-expires)
INCRBY stats:2024-01-15:logins 1
EXPIRE stats:2024-01-15:logins 86400 // 1 day
// Increment with multiple metrics
HINCRBY user:1:stats logins 1
HINCRBY user:1:stats posts 1
HINCRBY user:1:stats comments 1Time Series Data
// Store time series with list
LPUSH temperature:sensor1 '{"time":"2024-01-15T10:30:00","value":72.5}'
LPUSH temperature:sensor1 '{"time":"2024-01-15T10:31:00","value":72.3}'
// Get recent readings
LRANGE temperature:sensor1 0 59 // Last 60 readings
// Auto-expire old data
EXPIRE temperature:sensor1 3600 // Keep 1 hour of data
// Using sorted set for range queries
ZADD temperature:sensor1 1705315800 "72.5"
ZADD temperature:sensor1 1705315860 "72.3"
// Get data in time range
ZRANGEBYSCORE temperature:sensor1 1705315000 1705315900Locks & Mutexes
// Simple lock (not recommended for production)
function acquireLock(resource, timeout) {
const lockKey = `lock:${resource}`
const acquired = redis.setnx(lockKey, Date.now())
if (acquired) {
redis.expire(lockKey, timeout)
return true
}
return false
}
// Release lock
function releaseLock(resource) {
redis.del(`lock:${resource}`)
}
// Redlock pattern (safer distributed lock)
// Use RedLock library for multi-instance safety
const RedLock = require('redlock')
const redlock = new RedLock([redis1, redis2, redis3], {
driftFactor: 0.01,
retryCount: 3,
retryDelay: 200,
retryJitter: 200
})
const lock = await redlock.lock('resource:id', 1000)
try {
// Critical section
} finally {
await lock.unlock().catch(err => {})
}Pub/Sub Messaging
// Subscriber
function subscribe() {
const subscriber = redis.createClient()
subscriber.subscribe('notifications', 'alerts', (err, count) => {
console.log(`Subscribed to ${count} channels`)
})
subscriber.on('message', (channel, message) => {
console.log(`${channel}: ${message}`)
})
}
// Publisher
function publish() {
const publisher = redis.createClient()
publisher.publish('notifications', 'User login detected')
publisher.publish('alerts', 'High memory usage')
}
// Pattern subscription
subscriber.psubscribe('user:*:notifications', (err, count) => {
console.log(`Pattern subscribed`)
})Bloom Filters (Approximate Set Membership)
// Check if value exists (with false positives)
// Redis 4.0+ has RedisBloom module
BF.ADD mybloom item1
BF.EXISTS mybloom item1 // Returns 1 (exists)
BF.EXISTS mybloom notexists // Returns 0 (doesn't exist)
// Multi-add
BF.MADD mybloom item2 item3 item4
BF.MEXISTS mybloom item1 item5 item2Best Practices
✅ Use appropriate data structures for use case ✅ Set expiration for temporary data ✅ Monitor memory usage with MEMORY STATS ✅ Use pipelining for multiple commands ✅ Implement circuit breaker for cache failures ✅ Handle cache misses gracefully ✅ Use connection pooling ✅ Plan for cache invalidation strategy ✅ Monitor key performance indicators ✅ Use Redis Cluster for scaling
redis Guide
#!/usr/bin/env python3
import json
print(json.dumps({"skill": "redis"}, indent=2))