0

I got several sorted sets with a common prefix (itemmovements:) in Redis.

I know we can use ZCOUNT to get the number of items for a single (sorted set) key like this:

127.0.0.1:6379> zcount itemmovements:8 0 1000000000
(integer) 23

(I am able to do this, since I know the range of the item scores.)

How to run this in a loop for all keys prefixed itemmovements:?

Taking hint from How to atomically delete keys matching a pattern using Redis I tried this:

127.0.0.1:6379> EVAL "return redis.call('zcount', unpack(redis.call('keys', ARGV[1])), 0, 1000000000)" 0 itemmovements:*
(integer) 150

but as you can see it just returns a single number (which happens to be the size of itemmovements:0, the first value returned by keys).

Community
  • 1
  • 1
arun
  • 10,685
  • 6
  • 59
  • 81

1 Answers1

0

I realized I did not understand what that lua code in EVAL was doing. The code below works fine:

eval "local a = {}; for _,k in ipairs(redis.call('keys', 'itemmovements:*')) do table.insert(a, k); table.insert(a, redis.call('zcount', k, 0, 1000000000)); end; return a" 0
arun
  • 10,685
  • 6
  • 59
  • 81