BITCOUNT

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Count bits that are 1

Usage is bitcount key start end.
start and end are byte offsets starting from 0.
Negative values can be used for start or end. In that case the last byte is -1, the previous one is -2, and so on.

Example

Command>set key ABC
Result>OK
Command>bitcount key
Result>7
Command>bitcount key 1 2
Result>5

View animation



Syntax

BITCOUNT key [start end]

  • Available since version 2.6.0.
  • Time complexity is O(N).
Related commands SETBIT, GETBIT, BITOP, BITPOS
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< BITOP BITCOUNT BITFIELD >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.