Redis Caching
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Redis is an in-memory data structure store that can be used as a database, cache, message broker, and queue. This skill covers Redis setup, data structures, caching strategies, key naming conventions, TTL management, cache invalidation, distributed caching, pub/sub patterns, session storage, and rate limiting.
Why This Matters
Redis caching is critical because:
- Performance: In-memory operations are extremely fast
- Scalability: Redis supports horizontal scaling through clustering
- Flexibility: Multiple data structures for different use cases
- Real-time: Pub/sub enables real-time messaging
- Reliability: Persistence options prevent data loss
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
Inputs:
- Redis connection configuration
- Key name and value
- TTL value in seconds
- Data structure operations
Outputs:
- Operation results
- Cached values
- Pub/sub messages
- Rate limit status
Contracts:
- Keys must follow naming conventions
- TTL must be set for all cached data
- Operations must handle connection failures
- Pub/sub messages must be serializable
Skill Composition
- Depends on: None
- Compatible with: None
- Conflicts with: None
- Related Skills: None
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions / Constraints / Non-goals
- Assumptions:
- Development environment is properly configured
- Required dependencies are available
- Team has basic understanding of domain
- Constraints:
- Must follow existing codebase conventions
- Time and resource limitations
- Compatibility requirements
- Non-goals:
- This skill does not cover edge cases outside scope
- Not a replacement for formal training
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: redis-caching3description: Redis is an in-memory data structure store that can be used as a database, Use when this capability is needed.4---56# Redis Caching78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Redis is an in-memory data structure store that can be used as a database, cache, message broker, and queue. This skill covers Redis setup, data structures, caching strategies, key naming conventions, TTL management, cache invalidation, distributed caching, pub/sub patterns, session storage, and rate limiting.1819## Why This Matters20Redis caching is critical because:21- **Performance**: In-memory operations are extremely fast22- **Scalability**: Redis supports horizontal scaling through clustering23- **Flexibility**: Multiple data structures for different use cases24- **Real-time**: Pub/sub enables real-time messaging25- **Reliability**: Persistence options prevent data loss2627## Core Concepts & Rules2829### 1. Core Principles30- Follow established patterns and conventions31- Maintain consistency across codebase32- Document decisions and trade-offs3334### 2. Implementation Guidelines35- Start with the simplest viable solution36- Iterate based on feedback and requirements37- Test thoroughly before deployment383940## Inputs / Outputs / Contracts41**Inputs:**42- Redis connection configuration43- Key name and value44- TTL value in seconds45- Data structure operations4647**Outputs:**48- Operation results49- Cached values50- Pub/sub messages51- Rate limit status5253**Contracts:**54- Keys must follow naming conventions55- TTL must be set for all cached data56- Operations must handle connection failures57- Pub/sub messages must be serializable5859## Skill Composition60* **Depends on**: None61* **Compatible with**: None62* **Conflicts with**: None63* **Related Skills**: None6465## Quick Start / Implementation Example66671. Review requirements and constraints682. Set up development environment693. Implement core functionality following patterns704. Write tests for critical paths715. Run tests and fix issues726. Document any deviations or decisions7374```python75# Example implementation following best practices76def example_function():77 # Your implementation here78 pass79```808182## Assumptions / Constraints / Non-goals8384* **Assumptions**:85 - Development environment is properly configured86 - Required dependencies are available87 - Team has basic understanding of domain88* **Constraints**:89 - Must follow existing codebase conventions90 - Time and resource limitations91 - Compatibility requirements92* **Non-goals**:93 - This skill does not cover edge cases outside scope94 - Not a replacement for formal training959697## Compatibility & Prerequisites9899* **Supported Versions**:100 - Python 3.8+101 - Node.js 16+102 - Modern browsers (Chrome, Firefox, Safari, Edge)103* **Required AI Tools**:104 - Code editor (VS Code recommended)105 - Testing framework appropriate for language106 - Version control (Git)107* **Dependencies**:108 - Language-specific package manager109 - Build tools110 - Testing libraries111* **Environment Setup**:112 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)113114115## Test Scenario Matrix (QA Strategy)116117| Type | Focus Area | Required Scenarios / Mocks |118| :--- | :--- | :--- |119| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |120| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |121| **E2E** | User Journey | Critical user flows to test |122| **Performance** | Latency / Load | Benchmark requirements |123| **Security** | Vuln / Auth | SAST/DAST or dependency audit |124| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |125126127## Technical Guardrails & Security Threat Model128129### 1. Security & Privacy (Threat Model)130* **Top Threats**: Injection attacks, authentication bypass, data exposure131- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII132- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager133- [ ] **Authorization**: Validate user permissions before state changes134135### 2. Performance & Resources136- [ ] **Execution Efficiency**: Consider time complexity for algorithms137- [ ] **Memory Management**: Use streams/pagination for large data138- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks139140### 3. Architecture & Scalability141- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection142- [ ] **Modularity**: Decouple logic from UI/Frameworks143144### 4. Observability & Reliability145- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`146- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`147- [ ] **Error Handling**: Standardized error codes, no bare except148- [ ] **Observability Artifacts**:149 - **Log Fields**: timestamp, level, message, request_id150 - **Metrics**: request_count, error_count, response_time151 - **Dashboards/Alerts**: High Error Rate > 5%152153154## Agent Directives & Error Recovery155*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*156157- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.158- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.159- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.160- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.161162163## Definition of Done (DoD) Checklist164165- [ ] Tests passed + coverage met166- [ ] Lint/Typecheck passed167- [ ] Logging/Metrics/Trace implemented168- [ ] Security checks passed169- [ ] Documentation/Changelog updated170- [ ] Accessibility/Performance requirements met (if frontend)171172173## Anti-patterns / Pitfalls174175* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries176* ⚠️ **Watch out for**: Common symptoms and quick fixes177* 💡 **Instead**: Use proper error handling, pagination, and logging178179180## Reference Links & Examples181182* Internal documentation and examples183* Official documentation and best practices184* Community resources and discussions185186187## Versioning & Changelog188189* **Version**: 1.0.0190* **Changelog**:191 - 2026-02-22: Initial version with complete template structure192193---194> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.195<!-- tomevault:4.0:skill_md:2026-04-13 -->