连接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 = },
{ip="127.0.0.1", port = },
{ip="127.0.0.1", port = },
{ip="127.0.0.1", port = },
{ip="127.0.0.1", port = },
{ip="127.0.0.1", port = },
},
}
local redis_cluster = require "resty.rediscluster"
local red = redis_cluster:new(config)
for i = , 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集群的更多相关文章

  1. redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool

    一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...

  2. 通过jedis连接redis单机成功,使用redis客户端可以连接集群,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool

    一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...

  3. 使用DBeaver Enterprise连接redis集群的一些操作记录

    要点总结: 使用DBeaver Enterprise连接redis集群可以通过SQL语句查看key对应的value,但是没法查看key. 使用RedisDesktopManager连接redis集群可 ...

  4. spring boot下JedisCluster方式连接Redis集群的配置

    最近在使用springboot做项目,使用redis做缓存.在外网开发的时候redis服务器没有使用集群配置,所有就是用了RedisTemplate的方式进行连接redis服务器.但是项目代码挪到内网 ...

  5. Springboot2.x集成lettuce连接redis集群报超时异常Command timed out after 6 second(s)

    文/朱季谦 背景:最近在对一新开发Springboot系统做压测,发现刚开始压测时,可以正常对redis集群进行数据存取,但是暂停几分钟后,接着继续用jmeter进行压测时,发现redis就开始突然疯 ...

  6. java 连接 redis集群时报错:Could not get a resource from the pool

    由于弄这个的时候浪费了太多的时间,所以才记录下这个错,给大伙参考下 检查了一下,配置啥的都没问题的,但在redis集群机器上就可以,错误如下: Exception in thread "ma ...

  7. Java连接redis集群操作存储、删除以及获取值

    pom文件添加: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> &l ...

  8. 最新 laravel5.8 连接redis集群

    简介 Redis 是一个开源的,高级键值对存储数据库.由于它包含 字符串 , 哈希 , 列表 , 集合 , 和 有序集合 这些数据类型,所以它通常被称为数据结构服务器. 在使用 Laravel 的 R ...

  9. 报错:使用java api连接redis集群时报错 READONLY You can't write against a read only slave.

    报错: READONLY You can’t write against a read only slave. 报错原因: 因为连接的是从节点,从节点只有读的权限,没有写的权限 解决方案: 进入red ...

随机推荐

  1. nginx命令(持续更新)

    关闭服务:nginx -s stop | service nginx stop 启动服务:nginx | service nginx start 重新加载配置文件:nginx -s reload |  ...

  2. BZOJ5289: [Hnoi2018]排列

    传送门 第一步转化,令 \(q[p[i]]=i\),那么题目变成: 有一些 \(q[a[i]]<q[i]\) 的限制,\(q\) 必须为排列,求 \(max(\sum_{i=1}^{n}w[i] ...

  3. canvas绘画交叉波浪

    做个记录,自己写的动态效果,可能以后用的着呢: <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  4. ionic1项目中 ion-slide轮播用ng-repeat遍历数据后自动循环出问题

    <ion-slide-box>属性中循环播放:dose-continue=‘true’,但是在项目遇到这样一个问题,从后台获取数据后将数据ng-repeat到<ion-slide&g ...

  5. 字符串匹配常见算法(BF,RK,KMP,BM,Sunday)

    今日了解了一下字符串匹配的各种方法. 并对sundaysearch算法实现并且单元. 字符串匹配算法,是在实际工程中经常遇到的问题,也是各大公司笔试面试的常考题目.此算法通常输入为原字符串(strin ...

  6. 分享一个android debug模式,出现 waiting for debugger把界面卡住,取巧的解决办法

    使用android studio开发程序时,有时会出现 waiting for debugger 卡住界面,软件无法正常debug运行的情况,很多网友分享了一些解决办法,比如: 1 打开cmd进入命令 ...

  7. sql server 存储过程的学习

    存储过程学习笔记 存储过程就是一条或者多条sql语句的集合,为了实现特定任务,而将一些需要多次调用的固定操作语句编写成程序段,这些程序段存储在服务器上,有数据库服务器通过程序来调用.T_SQL:存储过 ...

  8. [Windows] [Firewall] 增加进入规则

    netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP l ...

  9. python selenium爬取自如租房数据保存到TXT文件

    # -*- coding: utf-8 -*-"""Created on Fri Aug 31  2018 @author: chenlinlab"" ...

  10. CSS| font property

    字體屬性 常用的CSS字体名称 宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 P ...