当前位置:网站首页>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 .
边栏推荐
- Class summation, shortest row
- 支持首次触发的 Go Ticker
- 智慧地铁| 云计算为城市地铁交通注入智慧
- Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
- Huawei cloud Kunpeng engineer training (Guangxi University)
- [paddleseg source code reading] paddleseg calculation dice
- vim映射命令
- SDP中的SPA
- Day05 錶格
- CUDA basic knowledge
猜你喜欢
随机推荐
functools下的reduce函数
Smart subway | cloud computing injects wisdom into urban subway transportation
STM32 external DHT11 display temperature and humidity
Database SQL statement summary, continuous update
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
New year's first race, submit bug reward more!
选择排序与冒泡排序模板
用于TCP协议交互的TCPClientDemo
There is a problem that the package cannot be parsed in the like project
渗透实战-SQLServer提权
SDP中的SPA
Zigzag scan
Eh, the log time of MySQL server is less than 8h?
Session learning diary 1
Msgraphmailbag - search only driveitems of file types
Introduction to asynchronous task capability of function calculation - task trigger de duplication
Pytest multi process / multi thread execution test case
Package details_ Four access control characters_ Two details of protected
[PaddleSeg 源码阅读] PaddleSeg计算Dice
vue多级路由嵌套怎么动态缓存组件