一键导入
redis-master
Leverage Redis for caching, sessions, pub/sub, queues, rate limiting, and real-time features. Design Redis data structures for optimal performance.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Leverage Redis for caching, sessions, pub/sub, queues, rate limiting, and real-time features. Design Redis data structures for optimal performance.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Professional Ai Content Filter Expert skill. Integrate LLM API workflows, safe system prompt guidelines, and agentic workflows.
Professional Ai Engineer skill. Integrate LLM API workflows, safe system prompt guidelines, and agentic workflows.
Professional Ai Product Manager Expert skill. Integrate LLM API workflows, safe system prompt guidelines, and agentic workflows.
Professional Ai Safety Guard Expert skill. Implement enterprise-grade web application security controls and encryption standards.
Professional Chain Of Thought Expert skill. Build performant, secure, and scalable backend logic and RESTful or GraphQL APIs.
Professional Context Optimizer Expert skill. Build performant, secure, and scalable backend logic and RESTful or GraphQL APIs.
| name | redis-master |
| description | Leverage Redis for caching, sessions, pub/sub, queues, rate limiting, and real-time features. Design Redis data structures for optimal performance. |
| category | php-frameworks |
| tags | ["redis","cache","pub-sub","session","queue"] |
| complexity | advanced |
| risk | low |
| compatibility | ["claude-code","antigravity","gemini-cli","cursor","copilot","codex-cli","autohand","kiro"] |
| source | antigravity-official |
| version | 1.0.0 |
| date_added | 2026-07-10 |
| last_updated | 2026-07-10 |
Use Redis effectively as a cache, message broker, session store, queue, and real-time data structure server.
You are a Redis expert who selects appropriate data structures, implements patterns correctly, and avoids common pitfalls like memory bloat and cache stampedes.
| Structure | Best For | Example Use Case |
|---|---|---|
| String | Simple values, counters | Cache, rate limiting |
| Hash | Objects, records | User sessions, config |
| List | Queues, activity feeds | Job queues, recent items |
| Set | Unique collections | Tags, permissions |
| Sorted Set | Ranked data | Leaderboards, rate windows |
| Stream | Event log | Activity stream, audit log |
| Bitmap | Boolean flags at scale | Feature flags, presence |
| HyperLogLog | Cardinality estimates | Unique visitor counts |
// Cache-Aside (Lazy Loading) - Most common
$user = Cache::remember("user:{$id}", 3600, function () use ($id) {
return User::find($id);
});
// Write-Through: Update cache on every write
public function updateUser(User $user, array $data): User
{
$user->update($data);
Cache::put("user:{$user->id}", $user, 3600);
return $user;
}
// Cache stampede prevention (atomically set cache)
$value = Cache::lock("lock:user:{$id}", 10)->block(5, function () use ($id) {
return Cache::remember("user:{$id}", 3600, fn() => User::find($id));
});
// Tagging for bulk invalidation
Cache::tags(['posts', 'user:123'])->put("post:{$postId}", $post, 3600);
Cache::tags(['user:123'])->flush(); // Invalidate all user's cached data
// Sliding window rate limiter using Sorted Set
function checkRateLimit(string $key, int $limit, int $windowSeconds): bool
{
$now = microtime(true);
$windowStart = $now - $windowSeconds;
$redis = Redis::connection();
$redis->zRemRangeByScore($key, '-inf', $windowStart);
$count = $redis->zCard($key);
if ($count >= $limit) {
return false; // Rate limited
}
$redis->zAdd($key, $now, $now);
$redis->expire($key, $windowSeconds);
return true;
}
// Laravel rate limiter
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
// Publisher (broadcasting events)
Redis::publish('notifications', json_encode([
'user_id' => $userId,
'type' => 'order_ready',
'message' => 'Your order #123 is ready!',
]));
// Subscriber (in a separate process)
Redis::subscribe(['notifications'], function ($message, $channel) {
$data = json_decode($message, true);
// Process notification...
WebSocket::send($data['user_id'], $data);
});
// Add/update player score
Redis::zAdd('leaderboard:weekly', $score, $userId);
// Get top 10 with scores
$leaderboard = Redis::zRevRangeWithScores('leaderboard:weekly', 0, 9);
// Get player rank
$rank = Redis::zRevRank('leaderboard:weekly', $userId);
// Get player score
$score = Redis::zScore('leaderboard:weekly', $userId);
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=null
SET key value without expiryapp:users:123 not just userredis-cli info memorymaxmemory-policy allkeys-lru for cache-only Redis instances