redis
БесплатноБез исполняемых скриптовНе проверенRedis is an in-memory data store used as a cache, session store, message broker and counter service. Use when adding a cache layer, storing sessions, rate…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Redis
Overview
Redis keeps data structures (strings, hashes, sets, sorted sets, streams) in memory and answers commands over TCP on port 6379. Typical uses: a cache in front of a database, expiring sessions, counters and rate limits, queues and event streams, locks, and leaderboards. Licensing: Redis 7.2 and earlier are BSD; Redis 8 is released under RSALv2, SSPLv1 or AGPLv3 at your option. Valkey is a BSD-licensed fork with the same protocol; every command below works on both.
Instructions
Run it locally
Publish the port on loopback only, require a password, and pass the password through the environment so it does not sit in the process list or shell history:
export REDIS_PASSWORD="$(openssl rand -hex 16)"
docker run -d --name redis-dev -p 127.0.0.1:6379:6379 -e REDIS_PASSWORD \
-v redis-data:/data redis:8-alpine \
sh -c 'exec redis-server --appendonly yes --requirepass "$REDIS_PASSWORD"'
docker exec redis-dev sh -c 'redis-cli -a "$REDIS_PASSWORD" --no-auth-warning ping'
The last command prints PONG. Never publish Redis on 0.0.0.0 or the public internet; Redis has no TLS or access control worth trusting without configuration.
Connect
import os
import redis
# One client per process: it owns a connection pool (default is unlimited, so cap it).
r = redis.Redis(host="127.0.0.1", port=6379, password=os.environ["REDIS_PASSWORD"],
decode_responses=True, max_connections=20)
r.ping() # True
import Redis from 'ioredis';
const redis = new Redis({
host: '127.0.0.1', port: 6379, password: process.env.REDIS_PASSWORD,
maxRetriesPerRequest: 3,
retryStrategy: (times) => Math.min(times * 50, 2000),
});
The official client for Node.js is redis (node-redis): createClient({ url }), then await client.connect(); commands take options such as client.set(k, v, { expiration: { type: 'EX', value: 60 } }) (the flat { EX: 60 } form is deprecated).
Cache-aside
Read the cache first, fall back to the database, store with a TTL, and delete the key on writes:
import json
def get_user(user_id: int) -> dict:
key = f"user:{user_id}"
cached = r.get(key)
if cached:
return json.loads(cached)
user = db.fetch_user(user_id) # your data layer
r.set(key, json.dumps(user), ex=3600) # SET ... EX replaces the older SETEX
return user
def update_user(user_id: int, fields: dict):
db.update_user(user_id, fields)
r.delete(f"user:{user_id}") # next read repopulates
Write-through (write the database, then r.set(key, ..., ex=7200)) keeps the cache warm but the two writes are not atomic; if the cache write fails the entry stays stale until the TTL ends, so always set a TTL.
Sessions
GETEX reads and refreshes the TTL in one command (sliding expiry); a per-user set allows "log out everywhere":
import json, secrets, time
SESSION_TTL = 86400
def create_session(user_id: int, metadata: dict | None = None) -> str:
token = secrets.token_urlsafe(32)
data = {"user_id": user_id, "created_at": time.time(), **(metadata or {})}
pipe = r.pipeline()
pipe.set(f"session:{token}", json.dumps(data), ex=SESSION_TTL)
pipe.sadd(f"user_sessions:{user_id}", token)
pipe.expire(f"user_sessions:{user_id}", SESSION_TTL)
pipe.execute()
return token
def get_session(token: str) -> dict | None:
data = r.getex(f"session:{token}", ex=SESSION_TTL)
return json.loads(data) if data else None
def destroy_all_sessions(user_id: int):
tokens = r.smembers(f"user_sessions:{user_id}")
if tokens:
r.delete(*[f"session:{t}" for t in tokens])
r.delete(f"user_sessions:{user_id}")
Sliding-window rate limit
The member must be unique per request, or two requests in the same instant collapse into one entry. Rejected requests are also counted, which is usually what you want against abuse:
import time, uuid
def is_rate_limited(key: str, limit: int, window_seconds: int) -> bool:
now = time.time()
rk = f"ratelimit:{key}"
pipe = r.pipeline() # runs as MULTI/EXEC
pipe.zremrangebyscore(rk, 0, now - window_seconds)
pipe.zadd(rk, {f"{now}:{uuid.uuid4().hex[:8]}": now})
pipe.zcard(rk)
pipe.expire(rk, window_seconds)
return pipe.execute()[2] > limit
For a cheaper fixed window use INCR plus EXPIRE ... NX on a per-window key.
Pub/sub
Pub/sub is fire-and-forget: a subscriber that is offline misses the message. run_in_thread handles the listener loop; call thread.stop() to shut down (it closes the subscription itself):
pubsub = r.pubsub(ignore_subscribe_messages=True)
pubsub.psubscribe(**{"notifications:*": lambda m: print(m["channel"], json.loads(m["data"]))})
thread = pubsub.run_in_thread(sleep_time=0.05, daemon=True)
r.publish("notifications:user:123", json.dumps({"type": "invoice_paid"}))
Streams with consumer groups
Use Streams when messages must survive
Установить redis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл redis?
Redis is an in-memory data store used as a cache, session store, message broker and counter service. Use when adding a cache layer, storing sessions, rate limiting an API, running pub/sub or Streams with consumer groups, taking a distributed lock, building a leaderboard, or configuring Redis for production (persistence, maxmemory, eviction).
Как установить скилл redis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл redis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic