-
Notifications
You must be signed in to change notification settings - Fork 76
BITCOUNT
Count the number of set bits (population counting) in a string. By default all the bytes contained in the string are examined. It is possible to specify the counting operation only in an interval passing the additional arguments start and end. 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.
Integer reply
The number of bits set to 1.
> SET mykey "foobar"
OK
> BITCOUNT mykey
(integer) 26
> BITCOUNT mykey 0 0
(integer) 4
> BITCOUNT mykey 1 1
(integer) 6
APPEND, BITCOUNT, BITOP, BITPOS, DBSIZE, DECR, DECRBY, DEL, EXISTS, EXPIRE, EXPIREAT, FLUSHDB, GET, GETBIT, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, KEYS, MGET, MSET, MSETNX, PDEL, PERSIST, PEXPIRE, PEXPIREAT, PTTL, RENAME, RENAMENX, SET, SETBIT, SETRANGE, STRLEN, TTL