We have a requirement that we need to get only the count of the [XRANGE key start end] result as the return value, not all filtered data.

I think there is no way to do it with a redis command.

Comment From: itamarhaber

Hello @burhancetinkaya

You are correct - currently, there isn't such Redis command or subcommand. It could be a useful addition, but the current Stream structure doesn't support this without spiraling into non-scalable linear time complexity lands (see #5473).

While somewhat inefficient, it can be scripted with Lua like this:

local xrange = redis.call('XRANGE', KEYS[1], ARGV[1], ARGV[2])
return #xrange
127.0.0.1:6379> 101 XADD mystream * foo bar
"1548698852073-0"
"1548698852073-1"
(99 more lines like this)
127.0.0.1:6379> EVAL "local xrange = redis.call('XRANGE', KEYS[1], ARGV[1], ARGV[2]) return #xrange" 1 mystream - +
(integer) 101

The above script can be optimized in terms of runtime memory usage with the COUNT subcommand, but would be more complex and may be also slower.

Comment From: madolson

Status: This doesn't seem trivial enough to necessarily justify implementation. As mentioned, this type of command will be difficult to implement and will spill into linear time. The next step here is probably getting consensus if this should be implemented.

Comment From: guybe7

i'm guessing a simple XCOUNT key min max will do the trick... easy to implement

Comment From: itamarhaber

I'd actually consider extending XLEN key [min max], but that would turn it into O(something else).