redis /ioredis
🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
★ 15,350⑂ 1,274
15,350
stars
+-4+-5+13
1,274
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions
README
A robust, performance-focused and full-featured Redis client for Node.js.
Supports Redis = 2.6.12. Completely compatible with Redis 7.x.
ioredis is a stable project and maintenance is done on a best-effort basis for relevant issues (contributions to ioredis will still be evaluated, reviewed, and merged when they benefit the project). For new projects, node-redis is the recommended client library. node-redis is the open-source (MIT license) Redis JavaScript client library redesigned from the ground up and actively maintained. node-redis supports new (hash-field expiration) and future commands and the capabilities available in Redis Stack and Redis 8 (search, JSON, time-series, probabilistic data structures).
Features
ioredis is a robust, full-featured Redis client that is
used in the world's biggest online commerce company Alibaba and many other awesome companies.
0. Full-featured. It supports Cluster, Sentinel, Streams, Pipelining, and of course Lua scripting, Redis Functions, Pub/Sub (with the support of binary messages).
1. High performance 🚀.
2. Delightful API 😄. It works with Node callbacks and Native promises.
3. Transformation of command arguments and replies.
4. Transparent key prefixing.
5. Abstraction for Lua scripting, allowing you to define custom commands.
6. Supports binary data.
7. Supports TLS 🔒.
8. Supports offline queue and ready checking.
9. Supports ES6 types, such as Map and Set.
10. Supports GEO commands 📍.
11. Supports Redis ACL.
12. Sophisticated error handling strategy.
13. Supports NAT mapping.
14. Supports autopipelining.
100% written in TypeScript and official declarations are provided:
Versions
| Version | Branch | Node.js Version | Redis Version |
| -------------- | ------ | --------------- | --------------- |
| 6.x.x (latest) | main | = 20 | 6.2 ~ latest |
| 5.x.x | v5 | = 12 | 2.6.12 ~ latest |
| 4.x.x | v4 | = 8 | 2.6.12 ~ 7 |
Refer to CHANGELOG.md for features and bug fixes introduced in v5.
🚀 Upgrading from v5 to v6
🚀 Upgrading from v4 to v5
Links
- API Documentation (Redis, Cluster)
- Changelog
Quick Start
Install
shell
npm install ioredis
In a TypeScript project, you may want to add TypeScript declarations for Node.js:
shell
npm install --save-dev @types/node
Basic Usage
javascript
// Import ioredis.
// You can also use import { Redis } from "ioredis"
// if your project is a TypeScript project,
// Note that import Redis from "ioredis" is still supported,
// but will be deprecated in the next major version.
const Redis = require("ioredis");
// Create a Redis instance.
// By default, it will connect to localhost:6379.
// We are going to cover how to specify connection options soon.
const redis = new Redis();
redis.set("mykey", "value"); // Returns a promise which resolves to "OK" when the command succeeds.
// ioredis supports the node.js callback style
redis.get("mykey", (err, result) = {
if (err) {