ioredis
Feature-rich Redis client for Node.js with clustering, pipelining, pub/sub, Lua scripts, and automatic reconnection for caches and queues.
Official Documentation ↗v6.0.0. Check the official docs for the latest API surface.Installation
npm install ioredispnpm add ioredisyarn add ioredisMethods
No methods match this filter.
ioredis is a Redis client with clustering, pipelining, pub/sub, and Lua support. It is a transport and command API, not a cache policy. TTLs, eviction, key naming, and failure behavior remain application decisions.
Connections and errors
Attach an error listener. ioredis emits connection errors that can otherwise surface as unhandled events. Configure connect and command timeouts so a Redis outage does not hang every request. Use a dedicated duplicated connection for subscriptions and blocking commands.
Keys and memory
Use explicit key prefixes and TTLs. A cache with no TTL depends entirely on invalidation; one missed delete can serve stale data indefinitely. Monitor memory, evictions, and slow commands. For rate limiting, use atomic commands or Lua rather than a read-modify-write sequence.
Errors
The following points are quoted verbatim from the official documentation (https://github.com/redis/ioredis). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Standalone and Sentinel clients report them through the error event; Cluster clients report them through node error. (https://github.com/redis/ioredis)
- A dependent managed HIMPORT SET retries preparation and rejects if recovery fails. (https://github.com/redis/ioredis)
- By default, all pending commands will be flushed with an error every 20 retry attempts. (https://github.com/redis/ioredis)
FAQ
- Should I use one Redis client for the whole process?
- A shared client is fine for ordinary commands, but subscriptions and blocking commands need dedicated connections. Use duplicate() for those cases.
- Does ioredis retry failed commands automatically?
- It reconnects and can retry depending on options and command safety. Non-idempotent writes need an idempotency key; do not rely on automatic retries alone.
- How should I handle Redis being unavailable?
- Decide per use case: fail the request for a required store, or degrade to a database or cached default for a cache. Log and alert on connection errors.
Report a problem with this API docOpens a pre-filled issue on GitHub.