这个是SETBIT使用方法的简单说明

在redis中,存储的字符串都是以二级制的进行存在的。
举例:
设置一个 key-value ,键的名字叫“andy” 值为字符‘a‘

我们知道 ‘a‘ 的ASCII码是 97。转换为二进制是:01100001。offset的学名叫做“偏移” 。二进制中的每一位就是offset值啦,比如在这里 offset 0 等于 ‘0’ ,offset 1等于‘1‘ ,offset2等于‘1‘,offset 6 等于‘1‘ ,没错,offset是从左往右计数的,也就是从高位往低位。
我们通过SETBIT 命令将 andy中的 ‘a‘ 变成 ‘b‘ 应该怎么变呢?
也就是将 01100001 变成 01100010 (b的ASCII码是98),这个很简单啦,也就是将‘a‘中的offset 6从0变成1,将offset 7 从1变成0 。

大家可能也发现了,每次SETBIT完毕之后,有一个(integer) 0或者(integer)1的返回值,这个是在你进行SETBIT 之前,该offset位的比特值。
这个时候,我们再get andy 一下,看看结果:

果然,就从‘a‘ 变成 ‘b‘了。
这就是redis 中 “SETBIT” 的基本用法。
BITCOUNT 就是统计字符串的二级制码中,有多少个‘1‘。 所以在这里,
BITCOUNT andy 得到的结果就是 3 啦。
以上。