Node Redis

Alternatives To Node Redis
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
a day ago179mitJavaScript
🚀🚀🚀A faster, better and more stable redis desktop manager [GUI client], compatible with Linux, Windows, Mac. What's more, it won't crash when loading massive keys.
Redisson21,241864181a day ago188August 24, 2022362apache-2.0Java
Redisson - Easy Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Go Redis17,341
a day ago200bsd-2-clauseGo
Redis Go client
Node Redis16,19146,4427,7246 days ago131September 06, 2022212mitTypeScript
Redis Node.js client
Ioredis11,9284,9293,14018 days ago220August 23, 2022222mitTypeScript
🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
Redis Py11,52624,7192,137a day ago93June 27, 2022205mitPython
Redis Python Client
Jedis11,12819,7791,043a day ago87August 10, 2022175mitJava
Redis Java client
3 months ago25apache-2.0Java
搜狐视频(sohu tv)Redis私有云平台 :支持Redis多种架构(Standalone、Sentinel、Cluster)高效管理、有效降低大规模redis运维成本,提升资源管控能力和利用率。平台提供快速搭建/迁移,运维管理,弹性伸缩,统计监控,客户端整合接入等功能。(CacheCloud is a Redis cloud management platform. It supports Standalone, Sentinel, and Cluster architectures for Redis, effectively reducing large-scale Redis operation and maintenance costs, and improving resource management and utilization. The platform provides rapid construction/migration, operation and maintenance management, elastic scaling, statistical monitoring, client integration and access and other functions)
Predis7,37311,9992,0815 days ago31September 04, 2022103mitPHP
A flexible and feature-complete Redis client for PHP.
Stackexchange.redis5,5131,6432,255a month ago135September 06, 2022157otherC#
General purpose redis client
Alternatives To Node Redis
Select To Compare

Alternative Project Comparisons


Tests Coverage License

Discord Twitch YouTube Twitter

node-redis is a modern, high performance Redis client for Node.js.


Name Description
redis Downloads Version
@redis/client Downloads Version Docs
@redis/bloom Downloads Version Docs Redis Bloom commands
@redis/graph Downloads Version Docs Redis Graph commands
@redis/json Downloads Version Docs Redis JSON commands
@redis/search Downloads Version Docs RediSearch commands
@redis/time-series Downloads Version Docs Redis Time-Series commands

⚠️ In version 4.1.0 we moved our subpackages from @node-redis to @redis. If you're just using npm install redis, you don't need to do anything—it'll upgrade automatically. If you're using the subpackages directly, you'll need to point to the new scope (e.g. @redis/client instead of @node-redis/client).


Start a redis via docker:

docker run -p 6379:6379 -it redis/redis-stack-server:latest

To install node-redis, simply:

npm install redis

⚠️ The new interface is clean and cool, but if you have an existing codebase, you'll want to read the migration guide.

Looking for a high-level library to handle object mapping? See redis-om-node!


Basic Example

import { createClient } from 'redis';

const client = createClient();

client.on('error', err => console.log('Redis Client Error', err));

await client.connect();

await client.set('key', 'value');
const value = await client.get('key');
await client.disconnect();

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]:

  url: 'redis://alice:[email protected]:6380'

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).

Redis Commands

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.):

// raw Redis commands
await client.HSET('key', 'field', 'value');
await client.HGETALL('key');

// friendly JavaScript commands
await client.hSet('key', 'field', 'value');
await client.hGetAll('key');

Modifiers to commands are specified using a JavaScript object:

await client.set('key', 'value', {
  EX: 10,
  NX: true

Replies will be transformed into useful data structures:

await client.hGetAll('key'); // { field1: 'value1', field2: 'value2' }
await client.hVals('key'); // ['value1', 'value2']

Buffers are supported as well:

await client.hSet('key', 'field', Buffer.from('value')); // 'OK'
await client.hGetAll(
  commandOptions({ returnBuffers: true }),
); // { field: <Buffer 76 61 6c 75 65> }

Unsupported Redis Commands

If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use .sendCommand():

await client.sendCommand(['SET', 'key', 'value', 'NX']); // 'OK'

await client.sendCommand(['HGETALL', 'key']); // ['key1', 'field1', 'key2', 'field2']

Transactions (Multi/Exec)

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:

await client.set('another-key', 'another-value');

const [setKeyReply, otherKeyValue] = await client
  .set('key', 'value')
  .exec(); // ['OK', 'another-value']

You can also watch keys by calling .watch(). Your transaction will abort if any of the watched keys change.

To dig deeper into transactions, check out the Isolated Execution Guide.

Blocking Commands

Any command can be run on a new connection by specifying the isolated option. The newly created connection is closed when the command's Promise is fulfilled.

This pattern works especially well for blocking commands—such as BLPOP and BLMOVE:

import { commandOptions } from 'redis';

const blPopPromise = client.blPop(
  commandOptions({ isolated: true }),

await client.lPush('key', ['1', '2']);

await blPopPromise; // '2'

To learn more about isolated execution, check out the guide.


See the Pub/Sub overview.

Scan Iterator

SCAN results can be looped over using async iterators:

for await (const key of client.scanIterator()) {
  // use the key!
  await client.get(key);

This works with HSCAN, SSCAN, and ZSCAN too:

for await (const { field, value } of client.hScanIterator('hash')) {}
for await (const member of client.sScanIterator('set')) {}
for await (const { score, value } of client.zScanIterator('sorted-set')) {}

You can override the default options by providing a configuration object:

  TYPE: 'string', // `SCAN` only
  MATCH: 'patter*',
  COUNT: 100


Redis provides a programming interface allowing code execution on the redis server.


The following example retrieves a key in redis, returning the value of the key, incremented by an integer. For example, if your key foo has the value 17 and we run add('foo', 25), it returns the answer to Life, the Universe and Everything.

#!lua name=library

redis.register_function {
  function_name = 'add',
  callback = function(keys, args) return'GET', keys[1]) + args[1] end,
  flags = { 'no-writes' }

Here is the same example, but in a format that can be pasted into the redis-cli.

FUNCTION LOAD "#!lua name=library\nredis.register_function{function_name=\"add\", callback=function(keys, args) return'GET', keys[1])+args[1] end, flags={\"no-writes\"}}"

Load the prior redis function on the redis server before running the example below.

import { createClient } from 'redis';

const client = createClient({
  functions: {
    library: {
      add: {
        NUMBER_OF_KEYS: 1,
        transformArguments(key: string, toAdd: number): Array<string> {
          return [key, toAdd.toString()];
        transformReply(reply: number): number {
          return reply;

await client.connect();

await client.set('key', '1');
await client.library.add('key', 2); // 3

Lua Scripts

The following is an end-to-end example of the prior concept.

import { createClient, defineScript } from 'redis';

const client = createClient({
  scripts: {
    add: defineScript({
      NUMBER_OF_KEYS: 1,
        'return"GET", KEYS[1]) + ARGV[1];',
      transformArguments(key: string, toAdd: number): Array<string> {
        return [key, toAdd.toString()];
      transformReply(reply: number): number {
        return reply;

await client.connect();

await client.set('key', '1');
await client.add('key', 2); // 3


There are two functions that disconnect a client from the Redis server. In most scenarios you should use .quit() to ensure that pending commands are sent to Redis before closing a connection.


Gracefully close a client's connection to Redis, by sending the QUIT command to the server. Before quitting, the client executes any remaining commands in its queue, and will receive replies from Redis for each of them.

const [ping, get, quit] = await Promise.all([,
]); // ['PONG', null, 'OK']

try {
  await client.get('key');
} catch (err) {
  // ClosedClient Error


Forcibly close a client's connection to Redis immediately. Calling disconnect will not send further pending commands to the Redis server, or wait for or parse outstanding responses.

await client.disconnect();


Node Redis will automatically pipeline requests that are made during the same "tick".

client.set('Tm9kZSBSZWRpcw==', 'users:1');
client.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().

await Promise.all([
  client.set('Tm9kZSBSZWRpcw==', 'users:1'),
  client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==')


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 .quit() or .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

⚠️ You MUST listen to error events. If a client doesn't have at least one error listener registered and an error 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.

Supported Redis versions

Node Redis is supported with the following versions of Redis:

Version Supported
7.0.z ✔️
6.2.z ✔️
6.0.z ✔️
5.0.z ✔️
< 5.0

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.

Popular Redis Projects
Popular Redis Client Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Redis Client
Redis Cluster