For lists I can do the operation:
LLEN KeyName
and it will return the size of a list in Redis. What is the equivalent command for sets? I can't seem to find this in any documentation.
To get the size of a database in Redis, use the DBSIZE command. This returns the total number of keys stored in the currently selected database. The previous command returns the number of keys in the database at index 0. Another command you can use to get the database size is the info command.
The Redis “get set” (GETSET) command allows you to set a key to a specified value and return the old value that was stored at the key. The Redis GETSET command is often used in conjunction with the INCR command to handle counting.
Redis can handle up to 2^32 keys, and was tested in practice to handle at least 250 million keys per instance. Every hash, list, set, and sorted set, can hold 2^32 elements.
Redis Sets are an unordered collection of unique strings. Unique means sets does not allow repetition of data in a key. In Redis set add, remove, and test for the existence of members in O(1) (constant time regardless of the number of elements contained inside the Set).
You are looking for the SCARD
command:
SCARD key
Returns the set cardinality (number of elements) of the set stored at
Return value
Integer reply: the cardinality (number of elements) of the set, or 0 if key does not exist.
You can view all of the set commands on the documentation webpage.
If it's a sorted set, you can use
ZCOUNT myset -inf +inf
or
ZCARD myset
zCard
is short for cardinality (cardinality is the number of elements in a set). It gives you total number of members inside of a "sorted set".
Sometimes you might wanna extract how many members are inside of a range in a sorted set. For that you can use zCount
.
ZCOUNT cars 0 50 // inclusive
this will include 0 and 55. 0 <= .... <=50. But if you do not want to include them
ZCOUNT cars (0 (50
if it is regular set
SCARD cars
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With