BITCOUNT

Since 1.1.0Bitmaps

Syntax

BITCOUNT key [start end [BYTE | BIT]]
  • Flags: readonly
  • ACL categories: @bitmap, @read, @slow
  • Arity: -2

Counts the bits set to 1 in the string at key, or in a part of it. start and end are byte offsets, both included, unless BIT is given; negative offsets count from the end.

Reply

  • The count; 0 if the key does not exist.

Examples

> SET s foobar
OK
> BITCOUNT s
(integer) 26
> BITCOUNT s 1 1
(integer) 6
> BITCOUNT s 5 30 BIT
(integer) 17