exam1:
redis 4表存放一个list,从4表弹出最老的一个值,然后到redis 1表中删除相应值。
local ctn_key = "ctn-001"
local cin_key = ""
local cin_value = ""
local i = 1
local table = 0
local cin_temp = ""
local result = ""
while(i<=80) do
table = 4
result = redis.call("select", table)
cin_temp = redis.call("rpop", ctn_key)
table = 1
result = redis.call("select", table)
result = redis.call("del", cin_temp)
i = i + 1
end
return result,cin_temp
exam2:
将数据写入redis 1表之后,插入redis 4表的list结构中。
local ctn_key = "ctn-001"
local cin_key = ""
local cin_value = ""
local i = 1
local table = 0
local result = ""
while(i<=100) do
cin_key = "cin-" .. i
cin_value = "value-" .. i
table = 1
result = redis.call("select", table)
result = redis.call("set", cin_key, cin_value)
table = 4
result = redis.call("select", table)
result = redis.call("lpush", ctn_key, cin_key)
i = i + 1
end
return result
最后用redis-cli命令执行这两个脚本,达到通过lua操作redis的效果:
./../redis-3.2.11/src/redis-cli --eval ./delete_cin.lua