What's the easiest way to getting the number (count) of items in Redis set? Preferably without the need to dump whole set and count the lines... So far, I have found only BITCOUNT, which I have not found that useful...
Asked
Active
Viewed 3.8k times
3 Answers
80
The SCARD command returns the cardinality (i.e. number of items) of a Redis set.
http://redis.io/commands/scard
There is a similar command (ZCARD) for sorted sets.

Didier Spezia
- 70,911
- 12
- 189
- 154
-
24For errant seo: if you have a list (not a set) it's `llen`. – scharfmn May 28 '15 at 16:06
0
Also if you have a sorted set, you can use the ZCOUNT
command to get the number of elements in the sorted set at key with a score between min and max.
Example:
ZCOUNT myzset 2 15
return count of elements with score >= 2 and <= 15

Amin Shojaei
- 5,451
- 2
- 38
- 46