$npx -y skills add jgamaraalv/ts-dev-kit --skill ioredisioredis v5 reference for Node.js Redis client — connection setup, RedisOptions, pipelines, transactions, Pub/Sub, Lua scripting, Cluster, and Sentinel. Use when: (1) creating or configuring Redis connections (standalone, cluster, sentinel), (2) writing Redis commands with ioredis
| 1 | # ioredis v5 — Node.js Redis Client |
| 2 | |
| 3 | ioredis v5.x. Requires Node.js >= 12, Redis >= 2.6.12. 100% TypeScript. |
| 4 | |
| 5 | <quick_reference> |
| 6 | |
| 7 | ## Critical: Import Style |
| 8 | |
| 9 | ```ts |
| 10 | // CORRECT — named import (required for NodeNext / moduleResolution: "nodenext") |
| 11 | import { Redis } from "ioredis"; |
| 12 | |
| 13 | // For Cluster: |
| 14 | import { Redis, Cluster } from "ioredis"; |
| 15 | ``` |
| 16 | |
| 17 | ## Quick Reference |
| 18 | |
| 19 | | Operation | Code | |
| 20 | | -------------- | -------------------------------------------------------------------------- | |
| 21 | | Connect | `new Redis()` or `new Redis(6379, "host")` or `new Redis("redis://...")` | |
| 22 | | Get/Set | `await redis.set("key", "val")` / `await redis.get("key")` | |
| 23 | | Pipeline | `await redis.pipeline().set("a","1").get("a").exec()` | |
| 24 | | Transaction | `await redis.multi().set("a","1").get("a").exec()` | |
| 25 | | Pub/Sub | `sub.subscribe("ch")` / `sub.on("message", cb)` / `pub.publish("ch", msg)` | |
| 26 | | Lua script | `redis.defineCommand("name", { numberOfKeys: 1, lua: "..." })` | |
| 27 | | Scan | `redis.scanStream({ match: "prefix:*", count: 100 })` | |
| 28 | | Graceful close | `await redis.quit()` | |
| 29 | | Force close | `redis.disconnect()` | |
| 30 | |
| 31 | </quick_reference> |
| 32 | |
| 33 | <gotchas> |
| 34 | |
| 35 | ## Common Gotchas |
| 36 | |
| 37 | 1. **Named import**: Always `import { Redis } from "ioredis"` with NodeNext resolution |
| 38 | 2. **Pub/Sub isolation**: A subscribed client cannot run other commands — use separate instances |
| 39 | 3. **`maxRetriesPerRequest`**: Default is 20. Set to `null` for infinite retries (required by BullMQ) |
| 40 | 4. **Pipeline errors**: `pipeline.exec()` never rejects — errors are in each result's `[0]` position |
| 41 | 5. **`showFriendlyErrorStack`**: Performance cost — never enable in production |
| 42 | 6. **Cluster pipelines**: All keys in a pipeline must hash to slots served by the same node |
| 43 | 7. **`enableAutoPipelining`**: 35-50% throughput improvement, safe to enable globally |
| 44 | |
| 45 | </gotchas> |
| 46 | |
| 47 | <references> |
| 48 | |
| 49 | ## When to Load References |
| 50 | |
| 51 | | Need | Reference file | |
| 52 | | ------------------------------------------------------------------------------ | -------------------------------------------------------------------- | |
| 53 | | Connection setup, RedisOptions, TLS, retryStrategy, lifecycle | [references/connection-options.md](references/connection-options.md) | |
| 54 | | Core API: pipelines, transactions, Pub/Sub, Lua scripting, scanning, events | [references/core-api.md](references/core-api.md) | |
| 55 | | Streams, auto-pipelining, transformers, binary data, error handling, debugging | [references/advanced-patterns.md](references/advanced-patterns.md) | |
| 56 | | Redis Cluster setup, ClusterOptions, Sentinel config, failover | [references/cluster-sentinel.md](references/cluster-sentinel.md) | |
| 57 | |
| 58 | </references> |