当前位置:网站首页>Execute Lua script in redis
Execute Lua script in redis
2022-06-26 10:30:00 【Xianghan collection】
Redis In the implementation of Lua Script
grammar :
grammar : eval script numkeys keys args
Parameters : eval — redis Provide parsing lua The command of the script
script — lua Script
numkeys — Specify the key name parameter set (keys) The number of
keys — Key name parameter set , adopt Global variables KEYS An array of said , Starting subscript is 1
args — Key value parameter set , Through global variables ARGV Array Express , Starting subscript is 1
Case study :
# Sign in redis Set a value after
set kojon 10
To write lua Script
adopt key Multiply the value of by a value
KEYS[1]: Parameters 1, Express key
KEYS[2]: Parameters 2, Express multiple
local curval =redis.call("get",KEYS[1])
if curval==false then
curval=0
else
curval=tonumber(curval)
end
curval=curval * tonumber(KEYS[2])
redis.call("set",KEYS[1],curval)
return curval
perform
# grammar redis-cli -a auth --eval lua file Parameters 1 Parameters 2
# No password -a auth
/usr/local/redis/bin/redis-cli -a KS6IxTDg7Q1gqhnWec9s --eval multiply.lua kojon 2
result
shell /usr/local/redis/bin/redis-cli -a KS6IxTDg7Q1gqhnWec9s --eval jisuan.lua kojon 2
(integer) 20
describe : EVAL The semantics of the command requires that the literal quantity should not be written directly in lua Script , It is recommended to use variables to define lua Script , And put the literal in the key name parameter set keys And key value parameter set args in , Through global variables KEYS and ARGV To get , The advantage of this is that it can be cached ! stay lua Script , You can use two functions to perform redis command , Namely :redis.call() and redis.pcall()
边栏推荐
猜你喜欢
Quantitative investment learning - Introduction to classic books
3行3列整形二维数组,求对角之和
Servlet learning notes II
MySQL 11th job - view application
MySQL 10th job - View
MySQL第十次作业-视图
全渠道、多场景、跨平台,App如何借助数据分析渠道流量
What should the preview do?
String constant pool, class constant pool, and runtime constant pool
Full introduction to flexboxlayout (Google official flexible implementation of flow layout control)
随机推荐
Jar version conflict resolution
118. 杨辉三角
Function run time
118. Yanghui triangle
看我在Map<String, String>集合中,存入Integer类型数据
Blog article index Summary - wechat games
MySQL第九次作业-连接查询&子查询
Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
Quantitative investment learning - Introduction to classic books
Introduction to libmagic
創建對象的時候堆內存的分配
Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL第七次作业-更新数据
The sixth MySQL job - query data - multiple conditions
Global and Chinese market for baked potato chips 2022-2028: Research Report on technology, participants, trends, market size and share
Hcia-dhcp experiment
LSP 是什么
libmagic 介绍
Global and Chinese markets in hair conditioner 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL第十一作業-視圖的應用