1. 程式人生 > >Redis中國bit的運算(bitcount,bitop and,bitop or等)

Redis中國bit的運算(bitcount,bitop and,bitop or等)

bitcount只會統計值為1的數,然後求總數

127.0.0.1:6379[2]> get k1
"a"
127.0.0.1:6379[2]> get k2
"c"
127.0.0.1:6379[2]> BITCOUNT k1
(integer) 3
127.0.0.1:6379[2]> BITCOUNT k2
(integer) 4
127.0.0.1:6379[2]> BITOP and k4 k1 k2
(integer) 1
127.0.0.1:6379[2]> get k4
"a"
127.0.0.1:6379[2]> BITOP or k5 k1 k2
(integer) 1
127.0.0.1:6379[2]> get k5
"c"
127.0.0.1:6379[2]> BITOP xor k6 k1 k2
(integer) 1
127.0.0.1:6379[2]> get k6
"\x02"
127.0.0.1:6379[2]>