当前位置:网站首页>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 .
边栏推荐
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- Katalon framework tests web (XXI) to obtain element attribute assertions
- LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)
- Katalon使用script实现查询List大小
- 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.
- 智慧地铁| 云计算为城市地铁交通注入智慧
- 三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
- Wechat official account web page authorization
- Defensive programming skills
- Object oriented -- encapsulation, inheritance, polymorphism
猜你喜欢
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
'2'>' 10'==true? How does JS perform implicit type conversion?
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.
JVM family -- monitoring tools
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
Development of digital collection trading platform development of digital collection platform
SQL語句加强練習(MySQL8.0為例)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
mysql数据库的存储
随机推荐
There is a problem that the package cannot be parsed in the like project
[Yugong series] go teaching course 002 go language environment installation in July 2022
The new data center helps speed up the construction of a digital economy with data as a key element
Leetcode51.n queen
Value transfer communication between components (parent to child, child to parent, brother component to value)
postgresql 用户不能自己创建表格配置
Class summation, shortest row
Reduce function under functools
PostgreSQL users cannot create table configurations by themselves
Summary of Chinese remainder theorem
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
[paddleseg source code reading] paddleseg custom data class
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
Sales management system of lightweight enterprises based on PHP
1289_FreeRTOS中vTaskSuspend()接口实现分析
[book club issue 13] packaging format of video files
Getting started with the go language is simple: go implements the Caesar password
Objective C attribute keyword
三年进账35.31亿,这个江西老表要IPO了