lua连接redis集群
连接redis集群需要用到llua-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

如下则是连接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集群的更多相关文章
- redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool
一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...
- 通过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 但是使 ...
- 使用DBeaver Enterprise连接redis集群的一些操作记录
要点总结: 使用DBeaver Enterprise连接redis集群可以通过SQL语句查看key对应的value,但是没法查看key. 使用RedisDesktopManager连接redis集群可 ...
- spring boot下JedisCluster方式连接Redis集群的配置
最近在使用springboot做项目,使用redis做缓存.在外网开发的时候redis服务器没有使用集群配置,所有就是用了RedisTemplate的方式进行连接redis服务器.但是项目代码挪到内网 ...
- Springboot2.x集成lettuce连接redis集群报超时异常Command timed out after 6 second(s)
文/朱季谦 背景:最近在对一新开发Springboot系统做压测,发现刚开始压测时,可以正常对redis集群进行数据存取,但是暂停几分钟后,接着继续用jmeter进行压测时,发现redis就开始突然疯 ...
- java 连接 redis集群时报错:Could not get a resource from the pool
由于弄这个的时候浪费了太多的时间,所以才记录下这个错,给大伙参考下 检查了一下,配置啥的都没问题的,但在redis集群机器上就可以,错误如下: Exception in thread "ma ...
- Java连接redis集群操作存储、删除以及获取值
pom文件添加: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> &l ...
- 最新 laravel5.8 连接redis集群
简介 Redis 是一个开源的,高级键值对存储数据库.由于它包含 字符串 , 哈希 , 列表 , 集合 , 和 有序集合 这些数据类型,所以它通常被称为数据结构服务器. 在使用 Laravel 的 R ...
- 报错:使用java api连接redis集群时报错 READONLY You can't write against a read only slave.
报错: READONLY You can’t write against a read only slave. 报错原因: 因为连接的是从节点,从节点只有读的权限,没有写的权限 解决方案: 进入red ...
随机推荐
- Android - View的绘制你知道多少?
https://github.com/android-cn/android-open-project-analysis/tree/master/tech/viewdrawflow Android-La ...
- Linux命令行介绍
一.Linux命令行结尾的提示符有“#”和“$”两种不同的符号,代码如下所示: [root@localhost ~]# ls anaconda-ks.cfg Desktop Documents min ...
- POJ3304(KB13-C 计算几何)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15335 Accepted: 4862 Descrip ...
- POJ3281(KB11-B 最大流)
Dining Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19170 Accepted: 8554 Descripti ...
- 撩课-Web大前端每天5道面试题-Day1
1. var的变量提升的底层原理是什么? JS引擎的工作方式是: 1) 先解析代码,获取所有被声明的变量: 2)然后在运行.也就是说分为预处理和执行两个阶段. 变量提升:所有变量的声明语句都会被提升到 ...
- php生成word,并下载
1.前端代码 <!DOCTYPE html> <html> <head> <title>PHP生成Word文档</title> <me ...
- 使用PHPExcel实现数据批量导出为excel表格
首先需要下载PHPExecel类文件,帮助文档可以参考PHPExcel中文帮助手册|PHPExcel使用方法. 下面直接上例子,是我自己写的一个简单的批量导出数据为excel的例子 前台页面 比较简单 ...
- Python3.6下的Requests登录及利用Cookies登录
利用Python中的Requests模块可以实现Post,Get等发送功能,我以登录某网站为例,记录使用Post发送用户名.密码及图形验证码,以及通过Cookies直接登录的内容. 1.利用POST发 ...
- 【代码笔记】iOS-字体从右向左滚动
一,效果图. 二,代码. ViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup ...
- 【代码笔记】iOS-UIActionSheet动态添加按钮
一,效果图. 二,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIVi ...