当前位置:网站首页>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 .
边栏推荐
- Pytest multi process / multi thread execution test case
- Aperçu du code source futur - série juc
- [paddleseg source code reading] paddleseg calculates Miou
- Select sorting and bubble sorting template
- warning: LF will be replaced by CRLF in XXXXXX
- Zigzag scan
- 渗透实战-SQLServer提权
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- Katalon中控件的参数化
- JVM family -- heap analysis
猜你喜欢

Add IDM to Google browser

渗透实战-SQLServer提权

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

Sales management system of lightweight enterprises based on PHP

Mindmanager2022 efficient and easy to use office mind map MindManager

postgresql 用户不能自己创建表格配置

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.

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

Storage of MySQL database

There is a problem that the package cannot be parsed in the like project
随机推荐
JDBC advanced
A review of reverse reinforcement learning at Virginia Tech (VT)
Calculate the odd sum of 1~n (1~100 as an example)
JDBC 进阶
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
智慧地铁| 云计算为城市地铁交通注入智慧
Development of digital collection trading platform development of digital collection platform
pytest多进程/多线程执行测试用例
What kind of experience is it when the Institute earns 20000 yuan a month!
Objective C attribute keyword
LevelDB源码解读-SkipList
Mindmanager2022 efficient and easy to use office mind map MindManager
ctf-pikachu-XSS
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Smart subway | cloud computing injects wisdom into urban subway transportation
Objective-C description method and type method
Katalon中控件的参数化
Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool
Easy to win insert sort
Reduce function under functools