bit
英[bɪt] 美[bɪt]
n. A little bit, a piece; a small amount, a little; a while, a blink of an eye; [count] bit ( Binary information unit)
adj. very small, insignificant
adv. [colloquial] quite, a little, more or less, how much [a bit to omitted]
vt. To put a bit on (the horse); to put on the bit; to restrain; to restrict
v. to bite, sting (past tense of bite); to sting; to bite bait; to have a bite (or sting) Habit
Third person singular: bits Plural: bits Present participle: bitting Past tense: bitted Past participle: bitted
count
英[kaʊnt ] 美[kaʊnt]
n.Total;count;crime;argument
v.Count;calculate the total;count...in;important
Third person singular: counts Plural: counts Present participle: counting Past tense: counted Past participle: counted
redis BITCOUNT command syntax
Function:Calculate the number of bits set to 1 in the given string.
Syntax: BITCOUNT key [start] [end]
Description: Generally, the entire given string will be counted , by specifying additional start or end parameters, you can count only on specific bits. The settings of the start and end parameters are similar to the GETRANGE command, and negative values can be used: for example, -1 represents the last digit, and -2 represents the second to last digit, and so on. Keys that do not exist are treated as empty strings, so if a BITCOUNT operation is performed on a key that does not exist, the result is 0.
Available versions: >= 2.6.0
Time complexity: O(N)
Returns: The number of bits set to 1.
redis BITCOUNT command example
redis> BITCOUNT bits (integer) 0 redis> SETBIT bits 0 1 # 0001 (integer) 0 redis> BITCOUNT bits (integer) 1 redis> SETBIT bits 3 1 # 1001 (integer) 0 redis> BITCOUNT bits (integer) 2