Gathering detailed insights and metrics for redis
Gathering detailed insights and metrics for redis
Gathering detailed insights and metrics for redis
Gathering detailed insights and metrics for redis
redis-errors
Error classes used in node_redis
@redis/client
The source code and documentation for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.
redis-parser
Javascript Redis protocol (RESP) parser
@redis/json
This package provides support for the [RedisJSON](https://redis.io/docs/data-types/json/) module, which adds JSON as a native data type to Redis.
npm install redis
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
100
Quality
95.4
Maintenance
100
Vulnerability
100
License
TypeScript (99.41%)
JavaScript (0.58%)
Dockerfile (0.01%)
Total Downloads
969,591,028
Last Day
280,547
Last Week
4,880,125
Last Month
20,871,551
Last Year
217,503,931
MIT License
17,210 Stars
2,150 Commits
1,908 Forks
294 Watchers
23 Branches
273 Contributors
Updated on Jun 16, 2025
Minified
Minified + Gzipped
Latest Version
5.5.6
Package Id
redis@5.5.6
Unpacked Size
240.75 kB
Size
13.22 kB
File Count
6
NPM Version
10.9.2
Node Version
23.11.0
Published on
Jun 06, 2025
Cumulative downloads
Total Downloads
Last Day
8.9%
280,547
Compared to previous day
Last Week
-3.8%
4,880,125
Compared to previous week
Last Month
2%
20,871,551
Compared to previous month
Last Year
22.3%
217,503,931
Compared to previous year
node-redis is a modern, high performance Redis client for Node.js.
Learn for free at Redis University
Build faster with the Redis Launchpad
Start a redis via docker:
1docker run -p 6379:6379 -d redis:8.0-rc1
To install node-redis, simply:
1npm install redis
"redis" is the "whole in one" package that includes all the other packages. If you only need a subset of the commands, you can install the individual packages. See the list below.
Name | Description |
---|---|
redis | The client with all the "redis-stack" modules |
@redis/client | The base clients (i.e RedisClient , RedisCluster , etc.) |
@redis/bloom | Redis Bloom commands |
@redis/json | Redis JSON commands |
@redis/search | RediSearch commands |
@redis/time-series | Redis Time-Series commands |
@redis/entraid | Secure token-based authentication for Redis clients using Microsoft Entra ID |
Looking for a high-level library to handle object mapping? See redis-om-node!
1import { createClient } from "redis"; 2 3const client = await createClient() 4 .on("error", (err) => console.log("Redis Client Error", err)) 5 .connect(); 6 7await client.set("key", "value"); 8const value = await client.get("key"); 9client.destroy();
The above code connects to localhost on port 6379. To connect to a different host or port, use a connection string in
the format redis[s]://[[username][:password]@][host][:port][/db-number]
:
1createClient({ 2 url: "redis://alice:foobared@awesome.redis.server:6380", 3});
You can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in the client configuration guide.
To check if the the client is connected and ready to send commands, use client.isReady
which returns a boolean.
client.isOpen
is also available. This returns true
when the client's underlying socket is open, and false
when it
isn't (for example when the client is still connecting or reconnecting after a network error).
There is built-in support for all of the out-of-the-box Redis commands. They are exposed
using the raw Redis command names (HSET
, HGETALL
, etc.) and a friendlier camel-cased version (hSet
, hGetAll
,
etc.):
1// raw Redis commands 2await client.HSET("key", "field", "value"); 3await client.HGETALL("key"); 4 5// friendly JavaScript commands 6await client.hSet("key", "field", "value"); 7await client.hGetAll("key");
Modifiers to commands are specified using a JavaScript object:
1await client.set("key", "value", { 2 EX: 10, 3 NX: true, 4});
Replies will be transformed into useful data structures:
1await client.hGetAll("key"); // { field1: 'value1', field2: 'value2' } 2await client.hVals("key"); // ['value1', 'value2']
Buffer
s are supported as well:
1const client = createClient().withTypeMapping({ 2 [RESP_TYPES.BLOB_STRING]: Buffer 3}); 4 5await client.hSet("key", "field", Buffer.from("value")); // 'OK' 6await client.hGet("key", "field"); // { field: <Buffer 76 61 6c 75 65> } 7
If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use .sendCommand()
:
1await client.sendCommand(["SET", "key", "value", "NX"]); // 'OK' 2 3await client.sendCommand(["HGETALL", "key"]); // ['key1', 'field1', 'key2', 'field2']
Start a transaction by calling .multi()
, then chaining your commands. When
you're done, call .exec()
and you'll get an array back with your results:
1await client.set("another-key", "another-value"); 2 3const [setKeyReply, otherKeyValue] = await client 4 .multi() 5 .set("key", "value") 6 .get("another-key") 7 .exec(); // ['OK', 'another-value']
You can also watch keys by calling
.watch()
. Your transaction will abort if any of the watched keys change.
In v4, RedisClient
had the ability to create a pool of connections using an "Isolation Pool" on top of the "main"
connection. However, there was no way to use the pool without a "main" connection:
1const client = await createClient() 2 .on("error", (err) => console.error(err)) 3 .connect(); 4 5await client.ping(client.commandOptions({ isolated: true }));
In v5 we've extracted this pool logic into its own class—RedisClientPool
:
1const pool = await createClientPool() 2 .on("error", (err) => console.error(err)) 3 .connect(); 4 5await pool.ping();
See the Pub/Sub overview.
SCAN
results can be looped over
using async iterators:
1for await (const key of client.scanIterator()) { 2 // use the key! 3 await client.get(key); 4}
This works with HSCAN
, SSCAN
, and ZSCAN
too:
1for await (const { field, value } of client.hScanIterator("hash")) { 2} 3for await (const member of client.sScanIterator("set")) { 4} 5for await (const { score, value } of client.zScanIterator("sorted-set")) { 6}
You can override the default options by providing a configuration object:
1client.scanIterator({ 2 TYPE: "string", // `SCAN` only 3 MATCH: "patter*", 4 COUNT: 100, 5});
The QUIT
command has been deprecated in Redis 7.2 and should now also be considered deprecated in Node-Redis. Instead
of sending a QUIT
command to the server, the client can simply close the network connection.
client.QUIT/quit()
is replaced by client.close()
. and, to avoid confusion, client.disconnect()
has been renamed to
client.destroy()
.
1client.destroy();
Node Redis v5 adds support for 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.
1// Enable client side caching with RESP3 2const client = createClient({ 3 RESP: 3, 4 clientSideCache: { 5 ttl: 0, // Time-to-live (0 = no expiration) 6 maxEntries: 0, // Maximum entries (0 = unlimited) 7 evictPolicy: "LRU" // Eviction policy: "LRU" or "FIFO" 8 } 9});
See the V5 documentation for more details and advanced usage.
Node Redis will automatically pipeline requests that are made during the same "tick".
1client.set("Tm9kZSBSZWRpcw==", "users:1"); 2client.sAdd("users:1:tokens", "Tm9kZSBSZWRpcw==");
Of course, if you don't do something with your Promises you're certain to
get unhandled Promise exceptions. To take
advantage of auto-pipelining and handle your Promises, use Promise.all()
.
1await Promise.all([ 2 client.set("Tm9kZSBSZWRpcw==", "users:1"), 3 client.sAdd("users:1:tokens", "Tm9kZSBSZWRpcw=="), 4]);
See the Programmability overview.
Check out the Clustering Guide when using Node Redis to connect to a Redis Cluster.
The Node Redis client class is an Nodejs EventEmitter and it emits an event each time the network status changes:
Name | When | Listener arguments |
---|---|---|
connect | Initiating a connection to the server | No arguments |
ready | Client is ready to use | No arguments |
end | Connection has been closed (via .disconnect() ) | No arguments |
error | An error has occurred—usually a network issue such as "Socket closed unexpectedly" | (error: Error) |
reconnecting | Client is trying to reconnect to the server | No arguments |
sharded-channel-moved | See here | See here |
:warning: You MUST listen to
error
events. If a client doesn't have at least oneerror
listener registered and anerror
occurs, that error will be thrown and the Node.js process will exit. See the >EventEmitter
docs for more details.
The client will not emit any other events beyond those listed above.
Node Redis is supported with the following versions of Redis:
Version | Supported |
---|---|
8.0.z | :heavy_check_mark: |
7.4.z | :heavy_check_mark: |
7.2.z | :heavy_check_mark: |
< 7.2 | :x: |
Node Redis should work with older versions of Redis, but it is not fully tested and we cannot offer support.
If you'd like to contribute, check out the contributing guide.
Thank you to all the people who already contributed to Node Redis!
This repository is licensed under the "MIT" license. See LICENSE.
7.5/10
Summary
Node-Redis potential exponential regex in monitor mode
Affected Versions
>= 2.6.0, < 3.1.1
Patched Versions
3.1.1
Reason
30 commit(s) and 15 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
7 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More