Multi-Client & Sentinel Redis Setup with NestJS

Multi-Client & Sentinel Redis Setup with NestJS

Setup Multi-Sentinel Multi-client Redis connections with NestJS Server

ยท

1 min read

Table of contents

No heading

No headings in the article.

There's already a package out there nestjs-redis, it is a wrapper around ioredis and quite easy to use.

There is only one issue you'll face with the package is while wrapping over ioredis the devs kept the key name for the sentinel name and the same name is used for client/connection name as per the implementation of the parent package.

I have fixed the same issue in forked repo.

The example config to connect to multi-sentinel name-based setup is below:

[
  {
    "clientName": "sentinelDB5",
    "sentinels": [
      {
        "host": "localhost",
        "port": 6380
      },
      {
        "host": "localhost",
        "port": 6381
      }
    ],
    "db": 5,
    "name": "hahaCluster",
    "password": "topSecret"
  }
]

After connecting with this config you can call the following in your services to get clients for these sentinels

const client = await this.redisService.getClient('sentinelDB5');

That's all, now you can go back to hacking as usual ๐Ÿ––๐Ÿป

ย