【问题标题】:Use LUA script with SCAN command to obtain the list?使用带有 SCAN 命令的 LUA 脚本来获取列表?
【发布时间】:2018-09-04 22:25:55
【问题描述】:

我想使用 SCAN 命令通过 MATCH 和 count 参数查询列表,因为我是 redis 和 lua 的新手,我怎么能写这样的脚本? 下面的脚本对吗?

local cursor = "0";
local list = {};
repeat
    local result = redis.call("SCAN", cursor, "MATCH", KEYS[1], "COUNT", 10);
    cursor = result[1];
    list += result[2]; **// How can I appened the list ?**
    end;
    cursor = t[1];
until cursor == "0";
return list;

【问题讨论】:

    标签: lua redis


    【解决方案1】:

    粗略扫描,脚本看起来不错。我假设您在问如何在 Lua 中连接表。据我所知,直到 Lua 5.1,这样做的方法是一个简单的循环:

    for _, v in ipairs(result[2]) do
      list[#list+1] = v
    end
    

    【讨论】:

      猜你喜欢
      • 2014-08-19
      • 2018-07-04
      • 2017-09-03
      • 2021-02-18
      • 2019-02-17
      • 2016-11-08
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多