【发布时间】:2021-06-27 06:10:00
【问题描述】:
我需要一个关于在 Redis 中修改对象的 LUA 脚本的简短建议。 我有这样的实体的 Redis 列表:
{
"@class": "com.myproject.model.Book",
"bookId": "someId",
"author": "someAuthor"
}
现在,我需要更改我的实体以允许某本书有多个作者,并为此创建迁移脚本:
{
"@class": "com.myproject.model.Book",
"bookId": "someId",
"authors": [
"java.util.ArrayList",
[
"someAuthor"
]
]
}
我认为我需要用 LUA 做什么:
local book
local cacheName --cache name in my case
local authorId;
local size = redis.call('LLEN', cacheName)
if size == 0
then
return -1
end
while size > 0
do
book = redis.call('LPOP', cacheName)
-- modify entity here
affectedEntitiesCount = affectedEntitiesCount + 1
redis.call('RPUSH', cacheName, book)
size = size - 1
end
return affectedEntitiesCount
但我不知道如何根据要求修改书。 有人可以看看并建议吗?
【问题讨论】: