连接redis集群需要用到 lua-resty-redis-cluster模块
github地址: https://github.com/cuiweixie/lua-resty-redis-cluster
下载完成之后,只需要用到包中的2个文件rediscluster.lua和redis_slot.c
.c文件无法在Nginx配置文件中引入,需要编译成**.so**文件,编译命令
gcc SOURCE_FILES -fPIC -shared -o TARGET
# centos自带lua需要执行此命令再编译,自己安装过lua不需要
yum install lua-devel
#编译命令
gcc redis_slot.c -fPIC -shared -o libredis_slot.so
[hadoop@slave2 lualib]$ ls
cjson.so libredis_slot.so lua2redis.lua ngx rds redis redis_slot.c resty
如下是连接redis集群代码:
local