在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):steve0511/resty-redis-cluster开源软件地址(OpenSource Url):https://github.com/steve0511/resty-redis-cluster开源编程语言(OpenSource Language):Perl 51.6%开源软件介绍(OpenSource Introduction):resty-redis-clusterOpenresty lua client for redis cluster. Why we build this client?Openresty has no official client which can support redis cluster. (We could see discussion at openresty/lua-resty-redis#43). Also, looking around other 3rd party openresty redis cluster client , we do't find one can completely support redis cluster features as our project requirement. Resty-redis-cluster is a new build openresty module which can currently support most of redis-cluster features. While building the client, thanks for https://github.com/cuiweixie/lua-resty-redis-cluster which gave us some good reference. feature list
installation
Sample usage
local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster", --rediscluster name
serv_list = { --redis cluster node list(host and port),
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000, --redis connection pool idle timeout
keepalive_cons = 1000, --redis connection pool size
connect_timeout = 1000, --timeout while connecting
max_redirection = 5, --maximum retry attempts for redirection
max_connection_attempts = 1 --maximum retry attempts for connection
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
local v, err = red_c:get("name")
if err then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(v)
end authentication: local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster", --rediscluster name
serv_list = { --redis cluster node list(host and port),
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000, --redis connection pool idle timeout
keepalive_cons = 1000, --redis connection pool size
connect_timeout = 1000, --timeout while connecting
read_timeout = 1000, --timeout while reading
send_timeout = 1000, --timeout while sending
max_redirection = 5, --maximum retry attempts for redirection,
max_connection_attempts = 1, --maximum retry attempts for connection
auth = "pass" --set password while setting auth
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
local v, err = red_c:get("name")
if err then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(v)
end
local cjson = require "cjson"
local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster",
serv_list = {
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000,
keepalive_cons = 1000,
connect_timeout = 1000,
read_timeout = 1000,
send_timeout = 1000,
max_redirection = 5,
max_connection_attempts = 1
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
red_c:init_pipeline()
red_c:get("name")
red_c:get("name1")
red_c:get("name2")
local res, err = red_c:commit_pipeline()
if not res then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(cjson.encode(res))
end
local cjson = require "cjson"
local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster",
enable_slave_read = true,
serv_list = {
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000,
keepalive_cons = 1000,
connect_timeout = 1000,
read_timeout = 1000,
send_timeout = 1000,
max_redirection = 5,
max_connection_attempts = 1
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
local v, err = red_c:get("name")
if err then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(v)
end
local cjson = require "cjson"
local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster",
enable_slave_read = true,
serv_list = {
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000,
keepalive_cons = 1000,
connect_timeout = 1000,
read_timeout = 1000,
send_timeout = 1000,
max_redirection = 5,
max_connection_attempts = 1
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
red_c:init_pipeline()
red_c:get("item100:sub1{100}")
red_c:get("item100:sub2{100}")
red_c:get("item100:sub3{100}")
local res, err = red_c:commit_pipeline()
if not res then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(cjson.encode(res))
end
local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster", --rediscluster name
serv_list = { --redis cluster node list(host and port),
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000, --redis connection pool idle timeout
keepalive_cons = 1000, --redis connection pool size
connect_timeout = 1000, --timeout while connecting
read_timeout = 1000, --timeout while reading
send_timeout = 1000, --timeout while sending
max_redirection = 5, --maximum retry attempts for redirection
max_connection_attempts = 1 --maximum retry attempts for connection
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
local step = 2
local v, err = red_c:eval("return redis.call('incrby',KEYS[1],ARGV[1])",1,"counter",step)
if err then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(v)
end
Note: local config = {
dict_name = "test_locks", --shared dictionary name for locks, if default value is not used
refresh_lock_key = "refresh_lock", --shared dictionary name prefix for lock of each worker, if default value is not used
name = "testCluster", --rediscluster name
serv_list = { --redis cluster node list(host and port),
{ ip = "127.0.0.1", port = 7001 },
{ ip = "127.0.0.1", port = 7002 },
{ ip = "127.0.0.1", port = 7003 },
{ ip = "127.0.0.1", port = 7004 },
{ ip = "127.0.0.1", port = 7005 },
{ ip = "127.0.0.1", port = 7006 }
},
keepalive_timeout = 60000, --redis connection pool idle timeout
keepalive_cons = 1000, --redis connection pool size
connect_timeout = 1000, --timeout while connecting
max_redirection = 5, --maximum retry attempts for redirection
max_connection_attempts = 1, --maximum retry attempts for connection
connect_opts = {
ssl = true,
ssl_verify = true,
server_name = "test-cluster.redis.myhost.com",
pool = "redis-cluster-connection-pool",
pool_size = 20,
backlog = 10
}
}
local redis_cluster = require "rediscluster"
local red_c = redis_cluster:new(config)
local v, err = red_c:get("name")
if err then
ngx.log(ngx.ERR, "err: ", err)
else
ngx.say(v)
end Limitation
Copyright and LicenseThis module is licensed under the Apache License Version 2.0 . Copyright (C) 2017, by steve.xu [email protected] All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论