Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

BITCOUNT

Josh Baker edited this page Oct 11, 2016 · 9 revisions

BITCOUNT key [start end]

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.

Return value

Integer reply
The number of bits set to 1.

Examples

> SET mykey "foobar"
OK
> BITCOUNT mykey
(integer) 26
> BITCOUNT mykey 0 0
(integer) 4
> BITCOUNT mykey 1 1
(integer) 6

Related Commands

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

Clone this wiki locally