当前位置:网站首页>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 .
边栏推荐
- LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)
- mysql数据库的存储
- 渗透实战-SQLServer提权
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- '2'>' 10'==true? How does JS perform implicit type conversion?
- Sales management system of lightweight enterprises based on PHP
- [.NET + mqtt]. Mise en œuvre de la communication mqtt dans l'environnement net 6 et démonstration de code pour l'abonnement et la publication de messages bilatéraux du serveur et du client
- SQL語句加强練習(MySQL8.0為例)
- SQL statement strengthening exercise (MySQL 8.0 as an example)
- Graduation summary
猜你喜欢

Third party login initial version

图解网络:什么是热备份路由器协议HSRP?

What kind of experience is it when the Institute earns 20000 yuan a month!

Go 语言入门很简单:Go 实现凯撒密码

拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。

The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

SQL語句加强練習(MySQL8.0為例)

2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。

JSON string conversion in unity
随机推荐
The property of judging odd or even numbers about XOR.
MySQL backup notes
10 reasons for not choosing to use free virtual hosts
深度优先搜索简要讲解(附带基础题)
投资深度思考
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
vim正确加区间注释
Brief explanation of depth first search (with basic questions)
vue多级路由嵌套怎么动态缓存组件
Katalon中控件的参数化
【罗技】m720
Introduction to asynchronous task capability of function calculation - task trigger de duplication
SQL statement strengthening exercise (MySQL 8.0 as an example)
Third party login initial version
SDP中的SPA
system information
Go 语言入门很简单:Go 实现凯撒密码
【读书会第十三期】多媒体处理工具 FFmpeg 工具集
MySQL is dirty
毕业总结