Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Redis Cluster support - Local changes working #19

Open
sekarpdkt opened this issue Jul 21, 2019 · 0 comments
Open

Redis Cluster support - Local changes working #19

sekarpdkt opened this issue Jul 21, 2019 · 0 comments

Comments

@sekarpdkt
Copy link

sekarpdkt commented Jul 21, 2019

Hi
I am able to used redis cluster.

Step 1: Store cluster nodes as an array in a variable like

config.TELEGRAM_SESSION_REDIS_CLUSTER_DETAILS=[
  {
    port: 7000,
    host: "192.168.1.17"
  },
  {
    port: 7001,
    host: "192.168.1.17"
  },
  {
    port: 7002,
    host: "192.168.1.17"
  },
  {
    port: 7003,
    host: "192.168.1.17"
  }
]

Step 2: Initiate session like

    let session = new RedisSession({
    store: config.TELEGRAM_SESSION_REDIS_CLUSTER_DETAILS,ttl: 1800
    })

Step3: In telegraf-session-redis, use ioredis instead of redis like

const redis = require('ioredis')

Step4: In telegraf-session-redis, handle connection like below

  constructor (options) {
    this.options = Object.assign({
      property: 'session',
      getSessionKey: (ctx) => ctx.from && ctx.chat && `${ctx.from.id}:${ctx.chat.id}`,
      store: {}
    }, options)
    this.client={};
    console.log(options.store.length)
    if(this.options.store.length>1)
        this.client = new redis.Cluster(this.options.store)
    else{
        this.client = new redis.createClient({
            host: this.options.store[0].host,
            port: this.options.store[0].port
        })
    }   
  }


Note: if you don't have rediscluster, we need to add only one host in the array and above code will choose between createClient and Cluster to establish the connection.

I can generate a PR if required.

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant