0

I am using Jedis. I need a Lua script to scan for a pattern with a specified limit. I don't know how to pass the parameters inside Lua script. Sample Code:

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);

How do I pass these parameters to the script?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Karthikeyan Gopall
  • 5,469
  • 2
  • 19
  • 35
  • 1
    Why not just call Jedis' `.scan` instead? Anyway, your script should not use the `KEYS` array but the `ARGV` array instead - read about Lua scripting in Redis at http://redis.io/commands/eval – Itamar Haber Aug 18 '15 at 09:05

1 Answers1

0

Your code has several points to fix.

  • In scan command, 'match' parameter should be placed prior to 'count'.
  • You should only use KEYS when it is a place for Redis key. Other things should be represented to ARGV.
  • You forgot to specify key count while calling Jedis.eval().

So, fixed version of your code is,

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);

But I agree Itamar to use Jedis.scan() instead.

Hope this helps.

Jungtaek Lim
  • 1,638
  • 1
  • 12
  • 20