redis BITOP命令


  翻译结果:

bit

英 [bɪt]   美 [bɪt]  

n.一点,一块;少量,少许;一会儿,一转眼;[计] 比特(二进位制信息单位)

adj.很小的,微不足道的

adv.[口语]相当,有点儿,或多或少,多少[a bit to的省略]

vt.给(马)上嚼子;上衔铁;抑制;制约

v.咬,叮( bite的过去式);刺痛;咬饵;有咬(或叮)的习性

第三人称单数: bits 复数: bits 现在分词: bitting 过去式: bitted 过去分词: bitted

op

英 [ɒp]   美 [ɑ:p]  

n.工作,操作

复数: ops

redis BITOP命令 语法

作用:对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上。

语法:BITOP operation destkey key [key ...]

说明:当 BITOP 处理不同长度的字符串时,较短的那个字符串所缺少的部分会被看作 0 。空的 key 也被看作是包含 0 的字符串序列。

可用版本:>= 2.6.0

时间复杂度:O(N)

返回:保存到 destkey 的字符串的长度,和输入 key 中最长的字符串长度相等。

redis BITOP命令 示例

redis> SETBIT bits-1 0 1        # bits-1 = 1001
(integer) 0
redis> SETBIT bits-1 3 1
(integer) 0
redis> SETBIT bits-2 0 1        # bits-2 = 1011
(integer) 0
redis> SETBIT bits-2 1 1
(integer) 0
redis> SETBIT bits-2 3 1
(integer) 0
redis> BITOP AND and-result bits-1 bits-2
(integer) 1
redis> GETBIT and-result 0      # and-result = 1001
(integer) 1
redis> GETBIT and-result 1
(integer) 0
redis> GETBIT and-result 2
(integer) 0
redis> GETBIT and-result 3
(integer) 1
目录

首页

视频

问答