{"name":"upstash-redis-js","url":"https://skills.sh/upstash/skills/upstash-redis-js","install":"npx skills add upstash/skills --skill upstash-redis-js","sdk":"upstash","key":"upstash/upstash-redis-js","description":"Work with the Upstash Redis TypeScript/JavaScript SDK for serverless Redis operations. Use for caching, session storage, rate limiting, leaderboards, full-text search (querying, filtering, aggregating) with Upstash Redis Search (different from regular FT.SEARCH), and all Redis data structures. Supports automatic serialization/deserialization of JavaScript types. Upstash Redis Search also available via @upstash/search-redis and @upstash/search-ioredis adapters for TCP clients.","hasContent":true,"content":"---\nname: upstash-redis-js\ndescription: Work with the Upstash Redis TypeScript/JavaScript SDK for serverless Redis operations. Use for caching, session storage, rate limiting, leaderboards, full-text search (querying, filtering, aggregating) with Upstash Redis Search (different from regular FT.SEARCH), and all Redis data structures. Supports automatic serialization/deserialization of JavaScript types. Upstash Redis Search also available via @upstash/search-redis and @upstash/search-ioredis adapters for TCP clients.\n---\n\n# Upstash Redis SDK - Complete Skills Guide\n\nThis 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.\n\n## Installation\n\n```bash\nnpm install @upstash/redis\n```\n\n## Quick Start\n\n### Basic Initialization\n\n```typescript\nimport { Redis } from \"@upstash/redis\";\n\n// Initialize with explicit credentials\nconst redis = new Redis({\n  url: \"UPSTASH_REDIS_REST_URL\",\n  token: \"UPSTASH_REDIS_REST_TOKEN\",\n});\n\n// Or initialize from environment variables\nconst redis = Redis.fromEnv();\n```\n\n### Environment Variables\n\nSet these in your `.env` file:\n\n```bash\nUPSTASH_REDIS_REST_URL=https://your-redis.upstash.io\nUPSTASH_REDIS_REST_TOKEN=your-token-here\n```\n\n> **No credentials yet?** If you're an agent that needs scratch Redis and the user hasn't provided a database, you can mint a temporary one with a single POST to `https://upstash.com/start-redis` (3-day TTL, no signup).\n\n## Skill Files Overview\n\n### Data Structures (data-structures/)\n\nRedis data types with auto-serialization examples:\n\n- **strings.md** - GET, SET, INCR, DECR, APPEND with automatic type handling\n- **hashes.md** - HSET, HGET, HMGET with object serialization\n- **lists.md** - LPUSH, RPUSH, LRANGE with array handling\n- **sets.md** - SADD, SMEMBERS, set operations\n- **sorted-sets.md** - ZADD, ZRANGE, ZRANK, leaderboard patterns\n- **json.md** - JSON.SET, JSON.GET, JSONPath queries for nested objects\n- **streams.md** - XADD, XREAD, XGROUP, consumer groups\n\n### Advanced Features (advanced-features/)\n\nComplex operations and optimizations:\n\n- **auto-pipeline.md** - Automatic request batching, performance optimization\n- **pipeline-and-transactions.md** - Manual pipelines, MULTI/EXEC for atomic operations\n- **scripting.md** - Lua scripts, EVAL, EVALSHA for server-side logic\n\n### Patterns (patterns/)\n\nCommon use cases and architectural patterns:\n\n- **caching.md** - Cache-aside, write-through, TTL strategies\n- **rate-limiting.md** - Integration with @upstash/ratelimit package\n- **session-management.md** - Session storage and user state management\n- **distributed-locks.md** - Lock implementations, deadlock prevention\n- **leaderboard.md** - Sorted set leaderboards, real-time rankings\n\n### Performance (performance/)\n\nOptimization techniques and best practices:\n\n- **batching-operations.md** - MGET, MSET, batch operations\n- **pipeline-optimization.md** - When to use pipelines, performance tips\n- **ttl-expiration.md** - Key expiration strategies, memory management\n- **data-serialization.md** - Deep dive into auto serialization, custom serializers, edge cases\n- **error-handling.md** - Error types, retry strategies, timeout handling, debugging tips\n- **redis-replicas.md** - Global database setup, read replicas, read-your-writes consistency\n\n### Search (search/)\n\nFull-text search, filtering, and aggregation extension for Redis:\n\n- **overview.md** - Schema definition, field types, pitfalls, package overview\n- **commands/querying.md** - Query and count with filters, pagination, sorting, highlighting\n- **commands/aggregating.md** - Metric aggregations ($avg, $sum, $stats), bucket aggregations ($terms, $range, $histogram, $facet)\n- **commands/index-management.md** - Create, describe, drop indexes, waitIndexing\n- **commands/aliases.md** - Index aliases for zero-downtime reindexing\n- **adapters.md** - Using search with node-redis and ioredis via @upstash/search-redis and @upstash/search-ioredis\n\n### Migrations (migrations/)\n\nMigration guides from other libraries:\n\n- **from-ioredis.md** - Migration from ioredis, key differences, serialization changes\n- **from-redis-node.md** - Migration from node-redis, API differences\n\n## Common Mistakes (Especially for LLMs)\n\n### ❌ Mistake 1: Treating Everything as Strings\n\n```typescript\n// ❌ WRONG - Don't do this with @upstash/redis\nawait redis.set(\"count\", \"42\"); // Stored as string \"42\"\nconst count = await redis.get(\"count\");\nconst incremented = parseInt(count) + 1; // Manual parsing needed\n\n// ✅ CORRECT - Let the SDK handle it\nawait redis.set(\"count\", 42); // Stored as number\nconst count = await redis.get(\"count\");\nconst incremented = count + 1; // Just use it\n```\n\n### ❌ Mistake 2: Manual JSON Serialization\n\n```typescript\n// ❌ WRONG - Unnecessary with @upstash/redis\nawait redis.set(\"user\", JSON.stringify({ name: \"Alice\" }));\nconst user = JSON.parse(await redis.get(\"user\"));\n\n// ✅ CORRECT - Automatic handling\nawait redis.set(\"user\", { name: \"Alice\" });\nconst user = await redis.get(\"user\");\n```\n\n## Quick Command Reference\n\n```typescript\n// Strings\nawait redis.set(\"key\", \"value\");\nawait redis.get(\"key\");\nawait redis.incr(\"counter\");\nawait redis.decr(\"counter\");\n\n// Hashes\nawait redis.hset(\"user:1\", { name: \"Alice\", age: 30 });\nawait redis.hget(\"user:1\", \"name\");\nawait redis.hgetall(\"user:1\");\n\n// Lists\nawait redis.lpush(\"tasks\", \"task1\", \"task2\");\nawait redis.rpush(\"tasks\", \"task3\");\nawait redis.lrange(\"tasks\", 0, -1);\n\n// Sets\nawait redis.sadd(\"tags\", \"javascript\", \"redis\");\nawait redis.smembers(\"tags\");\n\n// Sorted Sets\nawait redis.zadd(\"leaderboard\", { score: 100, member: \"player1\" });\nawait redis.zrange(\"leaderboard\", 0, -1);\n\n// JSON\nawait redis.json.set(\"user:1\", \"$\", { name: \"Alice\", address: { city: \"NYC\" } });\nawait redis.json.get(\"user:1\");\n\n// Expiration\nawait redis.setex(\"session\", 3600, { userId: \"123\" });\nawait redis.expire(\"key\", 60);\nawait redis.ttl(\"key\");\n```\n\n## Best Practices\n\n1. **Use environment variables** for credentials, never hardcode\n2. **Leverage auto-serialization** - pass native JavaScript types\n3. **Use TypeScript types** for better type safety\n4. **Set appropriate TTLs** to manage memory\n5. **Use pipelines** for multiple operations\n6. **Namespace your keys** (e.g., `user:123`, `session:abc`)\n\n## Resources\n\n- [Official Documentation](https://upstash.com/docs/redis)\n- [GitHub Repository](https://github.com/upstash/redis-js)\n- [API Reference](https://upstash.com/docs/redis/sdks/ts/overview)\n- [Examples](https://github.com/upstash/redis-js/tree/main/examples)\n\n## Getting Help\n\nFor 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.\n","contentSource":"https://raw.githubusercontent.com/upstash/skills/main/skills/upstash-redis-js/SKILL.md","contentFetchedAt":"2026-07-27T09:00:58.187Z"}