{"id":13457822,"url":"https://github.com/redis/node-redis","last_synced_at":"2026-01-15T22:21:06.693Z","repository":{"id":1069064,"uuid":"908893","full_name":"redis/node-redis","owner":"redis","description":"Redis Node.js client","archived":false,"fork":false,"pushed_at":"2025-05-05T09:45:04.000Z","size":120939,"stargazers_count":17148,"open_issues_count":362,"forks_count":1905,"subscribers_count":293,"default_branch":"master","last_synced_at":"2025-05-05T09:57:12.407Z","etag":null,"topics":["node-redis","nodejs","redis","redis-client","redis-cluster"],"latest_commit_sha":null,"homepage":"https://redis.js.org/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2010-09-14T02:05:09.000Z","updated_at":"2025-05-05T09:28:50.000Z","dependencies_parsed_at":"2024-02-19T22:28:06.414Z","dependency_job_id":"ecf28009-087b-4c43-a2fb-62c492fe47cd","html_url":"https://github.com/redis/node-redis","commit_stats":{"total_commits":1768,"total_committers":258,"mean_commits":6.852713178294573,"dds":0.7907239819004525,"last_synced_commit":"ffa7d2525c6d8bdd24faaad527a3ad0aec2cd8e9"},"previous_names":["noderedis/node_redis","noderedis/node-redis"],"tags_count":254,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fnode-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fnode-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fnode-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fnode-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis","download_url":"https://codeload.github.com/redis/node-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252486917,"owners_count":21755835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node-redis","nodejs","redis","redis-client","redis-cluster"],"created_at":"2024-07-31T09:00:37.793Z","updated_at":"2025-12-17T02:46:24.139Z","avatar_url":"https://github.com/redis.png","language":"TypeScript","readme":"# Node-Redis\n\n[![Tests](https://img.shields.io/github/actions/workflow/status/redis/node-redis/tests.yml?branch=master)](https://github.com/redis/node-redis/actions/workflows/tests.yml)\n[![Coverage](https://codecov.io/gh/redis/node-redis/branch/master/graph/badge.svg?token=xcfqHhJC37)](https://codecov.io/gh/redis/node-redis)\n[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://github.com/redis/node-redis/blob/master/LICENSE)\n\n[![Discord](https://img.shields.io/discord/697882427875393627.svg?style=social\u0026logo=discord)](https://discord.gg/redis)\n[![Twitch](https://img.shields.io/twitch/status/redisinc?style=social)](https://www.twitch.tv/redisinc)\n[![YouTube](https://img.shields.io/youtube/channel/views/UCD78lHSwYqMlyetR0_P4Vig?style=social)](https://www.youtube.com/redisinc)\n[![Twitter](https://img.shields.io/twitter/follow/redisinc?style=social)](https://twitter.com/redisinc)\n\nnode-redis is a modern, high performance [Redis](https://redis.io) client for Node.js.\n\n## How do I Redis?\n\n[Learn for free at Redis University](https://university.redis.com/)\n\n[Build faster with the Redis Launchpad](https://launchpad.redis.com/)\n\n[Try the Redis Cloud](https://redis.com/try-free/)\n\n[Dive in developer tutorials](https://developer.redis.com/)\n\n[Join the Redis community](https://redis.com/community/)\n\n[Work at Redis](https://redis.com/company/careers/jobs/)\n\n## Installation\n\nStart a redis via docker:\n\n```bash\ndocker run -p 6379:6379 -d redis:8.0-rc1\n```\n\nTo install node-redis, simply:\n\n```bash\nnpm install redis\n```\n\u003e \"redis\" is the \"whole in one\" package that includes all the other packages. If you only need a subset of the commands,\n\u003e you can install the individual packages. See the list below.\n\n## Packages\n\n| Name                                           | Description                                                                                 |\n| ---------------------------------------------- | ------------------------------------------------------------------------------------------- |\n| [`redis`](https://github.com/redis/node-redis/tree/master/packages/redis)                    | The client with all the [\"redis-stack\"](https://github.com/redis-stack/redis-stack) modules |\n| [`@redis/client`](https://github.com/redis/node-redis/tree/master/packages/client)           | The base clients (i.e `RedisClient`, `RedisCluster`, etc.)                                  |\n| [`@redis/bloom`](https://github.com/redis/node-redis/tree/master/packages/bloom)             | [Redis Bloom](https://redis.io/docs/data-types/probabilistic/) commands                     |\n| [`@redis/json`](https://github.com/redis/node-redis/tree/master/packages/json)               | [Redis JSON](https://redis.io/docs/data-types/json/) commands                               |\n| [`@redis/search`](https://github.com/redis/node-redis/tree/master/packages/search)           | [RediSearch](https://redis.io/docs/interact/search-and-query/) commands                     |\n| [`@redis/time-series`](https://github.com/redis/node-redis/tree/master/packages/time-series) | [Redis Time-Series](https://redis.io/docs/data-types/timeseries/) commands                  |\n| [`@redis/entraid`](https://github.com/redis/node-redis/tree/master/packages/entraid)         | Secure token-based authentication for Redis clients using Microsoft Entra ID                |\n\n\u003e Looking for a high-level library to handle object mapping?\n\u003e See [redis-om-node](https://github.com/redis/redis-om-node)!\n\n\n## Usage\n\n### Basic Example\n\n```typescript\nimport { createClient } from \"redis\";\n\nconst client = await createClient()\n  .on(\"error\", (err) =\u003e console.log(\"Redis Client Error\", err))\n  .connect();\n\nawait client.set(\"key\", \"value\");\nconst value = await client.get(\"key\");\nclient.destroy();\n```\n\nThe above code connects to localhost on port 6379. To connect to a different host or port, use a connection string in\nthe format `redis[s]://[[username][:password]@][host][:port][/db-number]`:\n\n```typescript\ncreateClient({\n  url: \"redis://alice:foobared@awesome.redis.server:6380\",\n});\n```\n\nYou can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in\nthe [client configuration guide](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md).\n\nTo check if the the client is connected and ready to send commands, use `client.isReady` which returns a boolean.\n`client.isOpen` is also available. This returns `true` when the client's underlying socket is open, and `false` when it\nisn't (for example when the client is still connecting or reconnecting after a network error).\n\n### Redis Commands\n\nThere is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed\nusing the raw Redis command names (`HSET`, `HGETALL`, etc.) and a friendlier camel-cased version (`hSet`, `hGetAll`,\netc.):\n\n```typescript\n// raw Redis commands\nawait client.HSET(\"key\", \"field\", \"value\");\nawait client.HGETALL(\"key\");\n\n// friendly JavaScript commands\nawait client.hSet(\"key\", \"field\", \"value\");\nawait client.hGetAll(\"key\");\n```\n\nModifiers to commands are specified using a JavaScript object:\n\n```typescript\nawait client.set(\"key\", \"value\", {\n  EX: 10,\n  NX: true,\n});\n```\n\nReplies will be transformed into useful data structures:\n\n```typescript\nawait client.hGetAll(\"key\"); // { field1: 'value1', field2: 'value2' }\nawait client.hVals(\"key\"); // ['value1', 'value2']\n```\n\n`Buffer`s are supported as well:\n\n```typescript\nconst client = createClient().withTypeMapping({\n  [RESP_TYPES.BLOB_STRING]: Buffer\n});\n\nawait client.hSet(\"key\", \"field\", Buffer.from(\"value\")); // 'OK'\nawait client.hGet(\"key\", \"field\"); // { field: \u003cBuffer 76 61 6c 75 65\u003e }\n\n```\n\n### Unsupported Redis Commands\n\nIf you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use `.sendCommand()`:\n\n```typescript\nawait client.sendCommand([\"SET\", \"key\", \"value\", \"NX\"]); // 'OK'\n\nawait client.sendCommand([\"HGETALL\", \"key\"]); // ['key1', 'field1', 'key2', 'field2']\n```\n\n_Note: the [API is different when using a cluster](https://github.com/redis/node-redis/blob/master/docs/clustering.md#unsupported-redis-commands)._\n\n### Transactions (Multi/Exec)\n\nStart a [transaction](https://redis.io/topics/transactions) by calling `.multi()`, then chaining your commands. When\nyou're done, call `.exec()` and you'll get an array back with your results:\n\n```typescript\nawait client.set(\"another-key\", \"another-value\");\n\nconst [setKeyReply, otherKeyValue] = await client\n  .multi()\n  .set(\"key\", \"value\")\n  .get(\"another-key\")\n  .exec(); // ['OK', 'another-value']\n```\n\nYou can also [watch](https://redis.io/topics/transactions#optimistic-locking-using-check-and-set) keys by calling\n`.watch()`. Your transaction will abort if any of the watched keys change.\n\n\n### Blocking Commands\n\nIn v4, `RedisClient` had the ability to create a pool of connections using an \"Isolation Pool\" on top of the \"main\"\nconnection. However, there was no way to use the pool without a \"main\" connection:\n\n```javascript\nconst client = await createClient()\n  .on(\"error\", (err) =\u003e console.error(err))\n  .connect();\n\nawait client.ping(client.commandOptions({ isolated: true }));\n```\n\nIn v5 we've extracted this pool logic into its own class—`RedisClientPool`:\n\n```javascript\nconst pool = await createClientPool()\n  .on(\"error\", (err) =\u003e console.error(err))\n  .connect();\n\nawait pool.ping();\n```\n\n\n### Pub/Sub\n\nSee the [Pub/Sub overview](https://github.com/redis/node-redis/blob/master/docs/pub-sub.md).\n\n### Scan Iterator\n\n[`SCAN`](https://redis.io/commands/scan) results can be looped over\nusing [async iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator):\n\n```typescript\nfor await (const keys of client.scanIterator()) {\n  console.log(keys, await client.mGet(keys));\n}\n```\n\nThis works with `HSCAN`, `SSCAN`, and `ZSCAN` too:\n\n```typescript\nfor await (const { field, value } of client.hScanIterator(\"hash\")) {\n}\nfor await (const member of client.sScanIterator(\"set\")) {\n}\nfor await (const { score, value } of client.zScanIterator(\"sorted-set\")) {\n}\n```\n\nYou can override the default options by providing a configuration object:\n\n```typescript\nclient.scanIterator({\n  TYPE: \"string\", // `SCAN` only\n  MATCH: \"patter*\",\n  COUNT: 100,\n});\n```\n\n### Disconnecting\n\nThe `QUIT` command has been deprecated in Redis 7.2 and should now also be considered deprecated in Node-Redis. Instead\nof sending a `QUIT` command to the server, the client can simply close the network connection.\n\n`client.QUIT/quit()` is replaced by `client.close()`. and, to avoid confusion, `client.disconnect()` has been renamed to\n`client.destroy()`.\n\n```typescript\nclient.destroy();\n```\n### Client Side Caching\n\nNode Redis v5 adds support for [Client Side Caching](https://redis.io/docs/manual/client-side-caching/), which enables clients to cache query results locally. The Redis server will notify the client when cached results are no longer valid.\n\n```typescript\n// Enable client side caching with RESP3\nconst client = createClient({\n  RESP: 3,\n  clientSideCache: {\n    ttl: 0,             // Time-to-live (0 = no expiration)\n    maxEntries: 0,      // Maximum entries (0 = unlimited)\n    evictPolicy: \"LRU\"  // Eviction policy: \"LRU\" or \"FIFO\"\n  }\n});\n```\n\nSee the [V5 documentation](https://github.com/redis/node-redis/blob/master/docs/v5.md#client-side-caching) for more details and advanced usage.\n\n### Auto-Pipelining\n\nNode Redis will automatically pipeline requests that are made during the same \"tick\".\n\n```typescript\nclient.set(\"Tm9kZSBSZWRpcw==\", \"users:1\");\nclient.sAdd(\"users:1:tokens\", \"Tm9kZSBSZWRpcw==\");\n```\n\nOf course, if you don't do something with your Promises you're certain to\nget [unhandled Promise exceptions](https://nodejs.org/api/process.html#process_event_unhandledrejection). To take\nadvantage of auto-pipelining and handle your Promises, use `Promise.all()`.\n\n```typescript\nawait Promise.all([\n  client.set(\"Tm9kZSBSZWRpcw==\", \"users:1\"),\n  client.sAdd(\"users:1:tokens\", \"Tm9kZSBSZWRpcw==\"),\n]);\n```\n\n### Programmability\n\nSee the [Programmability overview](https://github.com/redis/node-redis/blob/master/docs/programmability.md).\n\n### Clustering\n\nCheck out the [Clustering Guide](https://github.com/redis/node-redis/blob/master/docs/clustering.md) when using Node Redis to connect to a Redis Cluster.\n\n### Events\n\nThe Node Redis client class is an Nodejs EventEmitter and it emits an event each time the network status changes:\n\n| Name                    | When                                                                               | Listener arguments                                        |\n| ----------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------- |\n| `connect`               | Initiating a connection to the server                                              | _No arguments_                                            |\n| `ready`                 | Client is ready to use                                                             | _No arguments_                                            |\n| `end`                   | Connection has been closed (via `.disconnect()`)                                   | _No arguments_                                            |\n| `error`                 | An error has occurred—usually a network issue such as \"Socket closed unexpectedly\" | `(error: Error)`                                          |\n| `reconnecting`          | Client is trying to reconnect to the server                                        | _No arguments_                                            |\n| `sharded-channel-moved` | See [here](https://github.com/redis/node-redis/blob/master/docs/pub-sub.md#sharded-channel-moved-event)                          | See [here](https://github.com/redis/node-redis/blob/master/docs/pub-sub.md#sharded-channel-moved-event) |\n| `invalidate`            | Client Tracking is on with `emitInvalidate` and a key is invalidated               | `(key: RedisItem \\| null)`                                 |\n\n\u003e :warning: You **MUST** listen to `error` events. If a client doesn't have at least one `error` listener registered and\n\u003e an `error` occurs, that error will be thrown and the Node.js process will exit. See the [ \u003e `EventEmitter` docs](https://nodejs.org/api/events.html#events_error_events) for more details.\n\n\u003e The client will not emit [any other events](https://github.com/redis/node-redis/blob/master/docs/v3-to-v4.md#all-the-removed-events) beyond those listed above.\n\n## Supported Redis versions\n\nNode Redis is supported with the following versions of Redis:\n\nSee [Supported Redis Versions](https://github.com/redis/node-redis/blob/master/SUPPORTED_REDIS_VERSIONS.md).\n\n## Migration\n\n- [From V3 to V4](https://github.com/redis/node-redis/blob/master/docs/v3-to-v4.md)\n- [From V4 to V5](https://github.com/redis/node-redis/blob/master/docs/v4-to-v5.md)\n- [V5](https://github.com/redis/node-redis/blob/master/docs/v5.md)\n\n## Contributing\n\nIf you'd like to contribute, check out the [contributing guide](https://github.com/redis/node-redis/blob/master/CONTRIBUTING.md).\n\nThank you to all the people who already contributed to Node Redis!\n\n[![Contributors](https://contrib.rocks/image?repo=redis/node-redis)](https://github.com/redis/node-redis/graphs/contributors)\n\n## License\n\nThis repository is licensed under the \"MIT\" license. See [LICENSE](https://github.com/redis/node-redis/blob/master/LICENSE).\n","funding_links":[],"categories":["TypeScript","Data Management \u0026 Processing","Clients","其他__大数据"],"sub_categories":["Database \u0026 Cloud Management","JavaScript / TypeScript","网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fnode-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis%2Fnode-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fnode-redis/lists"}