ledgetech / lua-resty-redis-connector

Connection utilities for lua-resty-redis
234 stars 71 forks source link

I have two redis one master and one from use , how to Read and write separation use lua-resty-redis-connector #29

Open sixtool opened 5 years ago

sixtool commented 5 years ago
local rc = require("resty.redis.connector").new({
    connect_timeout = 100,
    keepalive_poolsize = 100
})
local hosts = {
    {host = "127.0.0.1", db = 7, role="master",port = 7379}, --master 
    {host = "127.0.0.1", db = 7, role="slave",port = 18379} --slave  it's not work 
}

local redis, err, previous_errors = rc:try_host(hosts)
redis:set("dog4","1")
ngx.say(cjson.encode(previous_errors)),      why previouse_errors is nil ???

I have two redis one master and one from use , how to Read and write separation use lua-resty-redis-connector

romitmisra1 commented 4 years ago

You can tweak the interface to return the role, when reading from the Sentinels. This way the table includes, the hostip, port and as well as the role. The role can be exposed to the calling API, or a API with exclusive role based responsibility can be constructed around it.