|Redis Developer Course||Redis Cloud Service||Redis-Gate Server|
Return the number of set bits in a string.
Set bit is 1.
The offsets start and end are byte positions.
It is not a bit position.
Like for the
GETRANGE command start and end can contain negative values
in order to index bytes starting from the end of the string,
where -1 is the last byte, -2 is the penultimate, and so forth.
Non-existent keys are treated as empty strings, so the command will return zero.
BITCOUNT key start end.
Integer reply: The number of bits set to 1.
|command>||set key ABC|
|command>||bitcount key 1 2|
In a example of counting days, even after 10 years the application is online
we still have just 365*10 bits of data per user,
that is just 456 bytes per user.
With this amount of data
BITCOUNT is still as fast as any other O(1)
Redis command like
BITCOUNT key [start end]
- Available since 2.6.0.
- Time complexity(Logical processing time): O(N)
|Related Commands||SETBIT, GETBIT, BITOP, BITPOS|
|Clients for Java||Jedis, Lettuce, Redisson||Clients for C||Hiredis|
To practice the command, click here to run Redis Web Client
|<< BITOP||BITCOUNT||BITPOS >>|
Click for a question or to see comments. Comments : Viewed :