日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lua 连接redis集群

發布時間:2024/1/1 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lua 连接redis集群 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.連接redis集群需要用到llua-resty-redis-cluster模塊

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

下載完成后,只需要用到包中2個文件rediscluster.lua和redis_slot.c

2.將lua-resty-redis-cluster/lib/redis_slot.c 拷貝到 openresty/lualib 目錄下
將lua-resty-redis-cluster/lib/resty/rediscluster.lua 拷貝到 openresty/lualib/resty 目錄下

3.cd 到 openresty/lualib目錄下 執行下面命令進行編譯
gcc redis_slot.c -fPIC -shared -o libredis_slot.so

問題:如果出現編譯報錯:failed to set…
找不到lua.h等文件
解決:應該是lua版本不對,自帶的lua應該不好使
方式一:刪除自帶的lua,一般是/usr/lua和/usr/luac ,刪除這兩個文件
方式二:yum install lua-devel 下載一個依賴
方式三:自己重新再lua官網下載一個lua,重新安裝一個lua(這個很好使)

4.在openresty的lualib目錄下 創建文件lua2redis-cluster.lua文件并添加:

local config = {name = "test",serv_list = {{ip="192.168.206.178", port = 7001},{ip="192.168.206.178", port = 7002},{ip="192.168.206.178", port = 7003},{ip="192.168.206.178", port = 7004},{ip="192.168.206.178", port = 7005},{ip="192.168.206.178", port = 7006},}, } local redis_cluster = require "resty.rediscluster" local red = redis_cluster:new(config) for i = 1, 2 dored:init_pipeline()red:set("k1", "hello")red:get("k1")red:set("k2", "world")red:get("k2")local results = red:commit_pipeline()local cjson = require "cjson"ngx.say(cjson.encode(results)) end red:close()

5.將上面的lua2redis-cluster.lua 文件路徑添加到 nginx.conf
6.并重啟nginx
nginx -s reload

7.測試:
在redis集群任一節點都可以 get k1的值 即說明lua連接redis集群成功

總結

以上是生活随笔為你收集整理的lua 连接redis集群的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。