lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

Add failure check into redis cluster implemenation

Open zhduan opened this issue 9 years ago • 3 comments

I need the redis cluster support for my project asap. So I went ahead to try the work h4lflife submitted in https://github.com/openresty/lua-resty-redis/pull/45 and made some changes to deal with redis failure scenario. It works well for my needs ( basic redis command get/set with a redis cluster by keep live option )

zhduan avatar Jun 05 '15 17:06 zhduan

Maybe you can cooperate with @pintsized in his lua-resty-redis-connector project or alike?

Please see https://groups.google.com/d/topic/openresty-en/0yr32RqZ8L0/discussion

agentzh avatar Jun 13 '15 08:06 agentzh

Whether to support with password access? please give a simple usage demo with auth and clsuter!

jzh800 avatar Apr 01 '17 07:04 jzh800

I have hacker the redis_cluster.lua file to support the password access. now it is could work with cluster set or get.

maybe we need public the auth interface with redis_cluster?

local function get_redis_link(host, port, timeout) local r = redis:new()

r:set_timeout(timeout)
r:connect(host, port)
r:auth("XXX-XXX")
	
return r

end

only change the redis host ip and port Example:

local redis_cluster = require("redis_cluster")

local cluster_id = "test_cluster"

-- Subset of nodes within the cluster local startup_nodes = { {"127.0.0.1", 7004}, {"127.0.0.1", 7000}, {"127.0.0.1", 7001} }

local opt = { timeout = 100, keepalive_size = 100, keepalive_duration = 60000 }

local rc = redis_cluster:new(cluster_id, startup_nodes, opt)

rc:initialize()

local ok, err = rc:set("key1", "val1") if not ok then ngx.say("Unable to set key1: ", err) else ngx.say("key1 set result: ", ok) end

local res, err = rc:get("key1") if not res then ngx.say("Failed to get key1: ", err) else ngx.say("key1:", res) end

-- (same as above, slightly faster) res, err = rc:send_cluster_command("get", "key1") if not res then ngx.say("Failed to get key1 with send_cluster_command: ", err) else ngx.say("key1 using send_cluster_command:", res) end

jzh800 avatar Apr 01 '17 08:04 jzh800