Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of items in Redis set

Tags:

count

redis

set

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...

like image 285
Pavel S. Avatar asked Aug 05 '13 10:08

Pavel S.


People also ask

What command will return the number of elements in a set Redis?

The SCARD command returns the cardinality (i.e. number of items) of a Redis set.

How do I count in Redis?

The first command you can use to get the total number of keys in a Redis database is the DBSIZE command. This simple command should return the total number of keys in a selected database as an integer value. The above example command shows that there are 203 keys in the database at index 10.

What is a Redis set?

Redis sets are unordered collections of unique strings that act like the sets from your favorite programming language (for example, Java HashSets, Python sets, and so on). With a Redis set, you can add, remove, and test for existence O(1) time (in other words, regardless of the number of set elements).


1 Answers

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.

like image 97
Didier Spezia Avatar answered Oct 14 '22 10:10

Didier Spezia