当前位置:网站首页>Redis cluster uses Lua script. Lua script can also be used for different slots
Redis cluster uses Lua script. Lua script can also be used for different slots
2022-07-04 04:04:00 【BanFS】
In the project , Need to use lua Script operation redis cluster In the multiple key, But not the same slot I will make a mistake , For example, the following test3、test6 In the same node, But it's not the same slot.redis Use lua Scripts can be like this redis-cli -a xxxxx--eval demo.lua key1 key2 , val1 val2
[email protected]:~/redis-cluster$ redis-cli -p 16380 -c
192.168.88.7:6379> set test3 3333
-> Redirected to slot [13026] located at 192.168.88.3:6379
OK
192.168.88.6:6379> set test5 3333
-> Redirected to slot [4644] located at 192.168.88.5:6379
OK
192.168.88.5:6379> set test6 3333
-> Redirected to slot [8775] located at 192.168.88.3:6379
OK
192.168.88.3:6379> cluster keyslot test3
(integer) 13026
192.168.88.3:6379> cluster keyslot test6
(integer) 8775
192.168.88.3:6379>
adopt key Pass in
Generally in redis cluster Use in lua Script , You'll come across (error) CROSSSLOT Keys in request don't hash to the same slot
[email protected]:~/test$ cat get.lua
local key1 = KEYS[1]
local key1 = KEYS[2]
local value1 = redis.call("GET", key1)
local value2 = redis.call("GET", key2)
return {
value1, value2}
[email protected]:~/test$ redis-cli -p 16380 -c --eval get.lua test3 test6
(error) CROSSSLOT Keys in request don't hash to the same slot
adopt value Pass in
In the official instructions ,redis Use lua Scripts are limited to one node The use of , But here is clearly the same node, But I can't use , But if we change the script to the following
[email protected]:~/test$ cat get.lua
local key1 = ARGV[1]
local key2 = ARGV[2]
local value1 = redis.call("GET", key1)
local value2 = redis.call("GET", key2)
return {
value1, value2}
[email protected]:~/test$ redis-cli -p 16380 -c --eval get.lua , test6 test3
1) "3333"
2) "3333"
This will solve .
summary
It should be according to KEY When it comes in ,redis In order to prevent key Not in the same node On , Yes key Conduct slot Judge , If it's not the same slot I'm going straight back , But it supports the same node Of ,** As long as we know what we need to do key To classify , The same node Of key adopt value Pass in , Can be in lua For the same node Of key operation .** In our design redis cluster When , Is to know every node Of slot Of , Every key Of solt The following calculations can be used
192.168.88.3:6379> cluster keyslot test3
(integer) 13026
We just need to judge first slot In a certain range , Belong to a node, Batch operation can be carried out .
边栏推荐
- 图解网络:什么是热备份路由器协议HSRP?
- 三年进账35.31亿,这个江西老表要IPO了
- Illustrated network: what is the hot backup router protocol HSRP?
- “软硬皆施”,助力建成新型云计算数据中心
- Katalon框架测试web(二十一)获取元素属性断言
- JDBC 进阶
- 新型数据中心,助力加快构建以数据为关键要素的数字经济
- EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
- Package details_ Four access control characters_ Two details of protected
- Katalon框架测试web(二十六)自动发邮件
猜你喜欢
Sales management system of lightweight enterprises based on PHP
ctf-pikachu-XSS
1289_FreeRTOS中vTaskSuspend()接口实现分析
MySQL is dirty
Audio and video technology development weekly | 232
Easy to win insert sort
ctf-pikachu-CSRF
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
Penetration practice - sqlserver empowerment
2022-07-03: there are 0 and 1 in the array. Be sure to flip an interval. Flip: 0 becomes 1, 1 becomes 0. What is the maximum number of 1 after turning? From little red book. 3.13 written examination.
随机推荐
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
[PaddleSeg 源码阅读] PaddleSeg计算 mIoU
JSON string conversion in unity
图解网络:什么是热备份路由器协议HSRP?
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
Future源碼一觀-JUC系列
选择排序与冒泡排序模板
Katalon framework tests web (XXI) to obtain element attribute assertions
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
SDP中的SPA
数据库SQL语句汇总,持续更新......
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Class summation, shortest row
[PaddleSeg 源码阅读] PaddleSeg计算Dice
微信公众号网页授权
Add IDM to Google browser
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Day05 錶格
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
Objective-C string class, array class