Skip to content

Latest commit

 

History

History
57 lines (51 loc) · 1.56 KB

examples.md

File metadata and controls

57 lines (51 loc) · 1.56 KB

Redis

Sentinel

name address port password
master localhost 6380 my_password
slave1 localhost 6480 my_password
slave2 localhost 6481 my_password
sentinel1 (mymaster) localhost 7380 sentinel
sentinel2 (mymaster) localhost 7381 sentinel

INFO: Read more about ioredis sentinel here.

HINT: When using Sentinel in Master-Slave setup, if you want to set the passwords for Master and Slave nodes, consider having the same password for them (#7292).

// app.module.ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@liaoliaots/nestjs-redis';

@Module({
  imports: [
    RedisModule.forRoot({
      readyLog: true,
      commonOptions: {
        name: 'mymaster',
        sentinels: [
          {
            host: 'localhost',
            port: 7380
          },
          {
            host: 'localhost',
            port: 7381
          }
        ],
        sentinelPassword: 'sentinel',
        password: 'my_password'
      },
      config: [
        {
          // get master node from the sentinel group
          role: 'master',
          namespace: "I'm master"
        },
        {
          // get a random slave node from the sentinel group
          role: 'slave',
          namespace: "I'm slave"
        }
      ]
    })
  ]
})
export class AppModule {}