Upstash Redis SDK - Complete Skills Guide
This directory contains comprehensive guides for using the @upstash/redis SDK. These skill files are designed to help developers and AI assistants understand and use the SDK effectively.
Installation
Quick Start
Basic Initialization
Environment Variables
Set these in your .env file:
Skill Files Overview
Data Structures (skills/data-structures/)
Redis data types with auto-serialization examples:
- strings.md - GET, SET, INCR, DECR, APPEND with automatic type handling
- hashes.md - HSET, HGET, HMGET with object serialization
- lists.md - LPUSH, RPUSH, LRANGE with array handling
- sets.md - SADD, SMEMBERS, set operations
- sorted-sets.md - ZADD, ZRANGE, ZRANK, leaderboard patterns
- json.md - JSON.SET, JSON.GET, JSONPath queries for nested objects
- streams.md - XADD, XREAD, XGROUP, consumer groups
Advanced Features (skills/advanced-features/)
Complex operations and optimizations:
- auto-pipeline.md - Automatic request batching, performance optimization
- pipeline-and-transactions.md - Manual pipelines, MULTI/EXEC, WATCH for atomic operations
- scripting.md - Lua scripts, EVAL, EVALSHA for server-side logic
Patterns (skills/patterns/)
Common use cases and architectural patterns:
- caching.md - Cache-aside, write-through, TTL strategies
- rate-limiting.md - Integration with @upstash/ratelimit package
- session-management.md - Session storage and user state management
- distributed-locks.md - Lock implementations, deadlock prevention
- leaderboard.md - Sorted set leaderboards, real-time rankings
Optimization techniques and best practices:
- batching-operations.md - MGET, MSET, batch operations
- pipeline-optimization.md - When to use pipelines, performance tips
- ttl-expiration.md - Key expiration strategies, memory management
- data-serialization.md - Deep dive into auto serialization, custom serializers, edge cases
- error-handling.md - Error types, retry strategies, timeout handling, debugging tips
- redis-replicas.md - Global database setup, read replicas, read-your-writes consistency
Search (skills/search/)
Full-text search, filtering, and aggregation extension for Redis:
- overview.md - Schema definition, field types, pitfalls, package overview
- commands/querying.md - Query and count with filters, pagination, sorting, highlighting
- commands/aggregating.md - Metric aggregations ($avg, $sum, $stats), bucket aggregations ($terms, $range, $histogram, $facet)
- commands/index-management.md - Create, describe, drop indexes, waitIndexing
- commands/aliases.md - Index aliases for zero-downtime reindexing
- adapters.md - Using search with node-redis and ioredis via @upstash/search-redis and @upstash/search-ioredis
Migrations (skills/migrations/)
Migration guides from other libraries:
- from-ioredis.md - Migration from ioredis, key differences, serialization changes
- from-redis-node.md - Migration from node-redis, API differences
Common Mistakes (Especially for LLMs)
❌ Mistake 1: Treating Everything as Strings
❌ Mistake 2: Manual JSON Serialization
Quick Command Reference
Best Practices
- Use environment variables for credentials, never hardcode
- Leverage auto-serialization - pass native JavaScript types
- Use TypeScript types for better type safety
- Set appropriate TTLs to manage memory
- Use pipelines for multiple operations
- Namespace your keys (e.g.,
user:123, session:abc)
Resources
Getting Help
For detailed information on specific topics, refer to the individual skill files in the skills/ directory. Each file contains comprehensive examples, use cases, and best practices for its topic.