Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failure check into redis cluster implemenation #60

Closed
wants to merge 5 commits into from

Conversation

zhduan
Copy link

@zhduan zhduan commented Jun 5, 2015

I need the redis cluster support for my project asap. So I went ahead to try the work h4lflife submitted in #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 )

@agentzh
Copy link
Member

agentzh commented Jun 13, 2015

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

@byliu byliu mentioned this pull request Nov 24, 2016
@jzh800
Copy link

jzh800 commented Apr 1, 2017

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

@jzh800
Copy link

jzh800 commented Apr 1, 2017

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

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

Successfully merging this pull request may close these issues.

5 participants