redis-patterns
實作 Redis 快取與速率限制
應用程式需要高效的快取機制和防濫用措施,但缺乏明確的實作模式。本技能提供生產環境可用的 Upstash Redis 模式,適用於快取、速率限制、工作階段儲存和發布/訂閱訊息傳遞。
스킬 ZIP 다운로드
Claude에서 업로드
설정 → 기능 → 스킬 → 스킬 업로드로 이동
토글을 켜고 사용 시작
테스트해 보기
"redis-patterns" 사용 중입니다. How do I cache user data with Redis?
예상 결과:
- Check cache first using redis.get(key)
- If cached, return cached data
- If not cached, fetch from database
- Store result in Redis with setex(key, ttl, value)
- Return the data
- Key pattern: user:{id} for easy invalidation
"redis-patterns" 사용 중입니다. I need to limit API requests per user
예상 결과:
- Create a Ratelimit instance with sliding window
- Pass unique identifier (IP or userId) to limit function
- Check success boolean in response
- Return 429 status with headers when limit exceeded
- Include X-RateLimit headers for client awareness
"redis-patterns" 사용 중입니다. How do I invalidate cached data?
예상 결과:
- Use redis.del(key) for single key removal
- Delete all related cache keys when data updates
- Consider cache versioning for complex invalidation
- Use TTL as fallback for automatic expiration
보안 감사
안전This skill contains only markdown documentation with code examples. No executable code, no file system access, no network calls, and no external command execution. The static scanner flagged standard patterns as threats: JavaScript template literals (misidentified as shell backticks), process.env configuration (misidentified as credential access), and crypto.randomUUID (misidentified as weak crypto). All findings are false positives. This is purely instructional material for Redis patterns.
위험 요인
🌐 네트워크 접근 (1)
⚙️ 외부 명령어 (21)
🔑 환경 변수 (4)
품질 점수
만들 수 있는 것
快取資料庫查詢
透過自動到期和失效機制快取頻繁查詢,以減少資料庫負載。
防止 API 濫用
實作速率限制以保護端點免受過多請求和 DDoS 攻擊。
管理使用者工作階段
為使用者驗證系統安全地儲存工作階段資料,並具有自動到期功能。
이 프롬프트를 사용해 보세요
Show me how to cache a database query result in Upstash Redis with a 5-minute TTL. Include cache-aside pattern.
Implement rate limiting for an API route using @upstash/ratelimit. Allow 10 requests per 10 seconds per IP.
Create session storage functions using Upstash Redis. Include create, get, and delete operations with 7-day expiration.
Show how to use Redis pub/sub for real-time event publishing. Include publisher and subscriber examples.
모범 사례
- 使用描述性的鍵前綴(user:、session:、cache:)來組織資料
- 當底層資料變更時,永遠使相關快取失效
- 根據資料新鮮度要求設定適當的 TTL 值
- 使用 redis.del() 進行快取失效,而非等待 TTL 到期
피하기
- 在 Redis 中儲存敏感資料而不進行加密
- 使用極長的 TTL 阻止資料更新傳播
- 不快處理快取未命中,沒有回退到資料庫
- 儲存整個大型物件而非參照它們