首页 > 其他 > 详细

lua连接redis集群

时间:2017-11-01 14:04:58      阅读:1184      评论:0      收藏:0      [点我收藏+]

连接redis集群需要用到llua-resty-redis-cluster模块

github地址:https://github.com/cuiweixie/lua-resty-redis-cluster

下载完成后,只需要用到包中2个文件rediscluster.luaredis_slot.c

.c文件无法在nginx配置文件中引入,需要编译成.so文件,编译命令:  gcc SOURCE_FILES -fPIC -shared -o TARGET

技术分享

如下则是连接redis集群代码:

local config = {
                name = "test",
                serv_list = {
                    {ip="127.0.0.1", port = 3100},
                    {ip="127.0.0.1", port = 3101},
                    {ip="127.0.0.1", port = 3102},
                    {ip="127.0.0.1", port = 3200},
                    {ip="127.0.0.1", port = 3201},
                    {ip="127.0.0.1", port = 3202},
                },
            }
            local redis_cluster = require "resty.rediscluster"
            local red = redis_cluster:new(config)
            for i = 1, 2 do
                red:init_pipeline()
                red:set("dog", "an animal")
                red:get("dog")
                red:set("dog", "hello")
                red:get("dog")
                local results = red:commit_pipeline()
                local cjson = require "cjson"
                ngx.say(cjson.encode(results))
            end
            red:close()

 

lua连接redis集群

原文:http://www.cnblogs.com/wangzhisdu/p/7766075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!