Lua 具有 'match' 和 'count' 约束的扫描脚本

Lua script for scan with 'match' and 'count' constraints

我正在使用 Jedis。我需要一个 Lua 脚本来扫描具有指定限制的模式。我不知道如何在 Lua 脚本中传递参数。 示例代码:

String script="return     {redis.call('SCAN',KEYS[1],'COUNT',KEYS[2],'MATCH',KEYS[3]}";
List<String> response = (List<String>)jedis.eval(script,cursor,COUNT,pattern);

如何将这些参数传递给脚本?

您的代码有几点需要修复。

  • 在扫描命令中,'match'参数应该放在'count'之前。
  • 当它是Redis key的地方时,你应该只使用KEYS。其他东西要交给ARGV。
  • 您在调用 Jedis.eval() 时忘记指定键数。

所以,你的代码的固定版本是,

String script="return {redis.call('SCAN',ARGV[1],'MATCH',ARGV[2],'COUNT',ARGV[3])}"; List<String> response = (List<String>)jedis.eval(script, 0, cursor, pattern, COUNT);

但我同意 Itamar 改用 Jedis.scan()。

希望对您有所帮助。