[qishibo/AnotherRedisDesktopManager]lua脚本运行失败

2024-06-25 711 views
9

Windows

VERSION

1.6.1 最新 Version in settings

ISSUE DESCRIPTION

测试一个清理历史key的lua脚本

-- 获取当前日期
local currentDate = KEYS[1]

-- 定义结果数组
local result = {}

-- 遍历所有键,匹配以 "2023" 开头的 8 位日期字符串
for i, key in pairs(redis.call('KEYS', '2023????')) do
    -- 如果键的日期小于当前日期,删除该键并将其添加到结果数组
    if tonumber(key) < tonumber(currentDate) then
        redis.call('DEL', key)
        table.insert(result, key)
    end
end

-- 设置今天的键为 24 小时过期
redis.call('EXPIRE', currentDate, 86400)

-- 返回被删除的键数组
return result

执行时报错

EVAL "local currentDate = KEYS[1]; local result = {}; for i, key in pairs(redis.call('KEYS', '2023????')) do if tonumber(key) < tonumber(currentDate) then redis.call('DEL', key); table.insert(result, key); end end; redis.call('EXPIRE', currentDate, 86400); return result" 1 20230323 ;

image

回答

4

image

较短的脚本可以执行成功

6

好问题,eval命令是支持的,但还真没对lua优化过,我这也调试一下

6

好问题,eval命令是支持的,但还真没对lua优化过,我这也调试一下

感谢! 这里有几个可能因素, 不确定到底是哪一个

  1. 命令过长
  2. 特殊符号影响了命令, 如lua字符串中的 "<" (小于号)
2

@qishibo any update on this?

2

测试是可以的,执行如下命令 EVAL "local currentDate = KEYS[1]; local result = {}; for i, key in pairs(redis.call('KEYS', '2023????')) do if tonumber(key) < tonumber(currentDate) then redis.call('DEL', key); table.insert(result, key); end end; redis.call('EXPIRE', currentDate, 86400); return result" 1 20230323 ;

image