当前位置:网站首页>redis的二进制数组命令
redis的二进制数组命令
2022-06-26 15:50:00 【华为云】
redis的二进制数组命令
redis的二进制数组是用SDS来表示的,sds的len属性的值表示SDS保存了多少字节长的位数组,buf数组每个字节用一行来表示,每行8位而且数组是通过逆序来保存位数组的
getbit 命令
getbit命令显然是返回位数组指定偏移量的二进制位的值,
redis> GETBIT bit 10086(integer) 1
执行过程是对偏移量除以8计算出偏移量指定的二进制位保存在位数组的那个字节中,然后偏移量mod8再加一计算出在第几二进制位中,获取到这个位的值进行返回
setbit命令
setbit命令就是对指定的偏移量设置新值,并返回旧值。如果偏移量大于当前的就会进行扩展
redis> SETBIT bit 10086 1(integer) 0
bitcount命令
bitcount命令是用来统计数组中值是1的个数
redis> BITCOUNT bits(integer) 0redis> SETBIT bits 0 1 # 0001(integer) 0redis> BITCOUNT bits(integer) 1redis> SETBIT bits 3 1 # 1001(integer) 0redis> BITCOUNT bits(integer) 2
bitcount命令的实现redis使用了查表法和汉明算法,二进制位的数量大于等于128位使用汉明算法,小于128位使用查表法。
bitop and 是进行与操作
bitop or是进行或操作
bitop xor是进行异或操作
bitop not是进行非操作
总结
这篇文章主要介绍了redis的二进制数组的相关内容,redis的二进制数组用SDS来表示,getbit命令返回位数组指定偏移量的二进制位的值,setbit命令对指定的偏移量设置新值,并返回旧值,bitcount命令统计数组中值是1的个数,当二进制位的数量大于等于128位的时候使用的是汉明算法,小于128位的时候使用的是查表法,bitop命令对二进制数组进行位操作,它有各种的参数,and表示与操作,or表示或操作,xor表示异或操作,not表示非操作,这些命令都是对二进制数组的操作命令,熟练掌握二进制数组命令可以让我们更加熟悉redis的二进制数组。
️ 感谢大家
如果你觉得这篇内容对你挺有有帮助的话:
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂
,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。 - 有不当之处欢迎批评指正。
边栏推荐
猜你喜欢
Ideal path problem
HW safety response
Analyse panoramique de la chaîne industrielle en amont, en aval et en aval de la NFT « Dry goods»
Comprehensive analysis of discord security issues
The first batch in the industry! Tencent cloud security and privacy computing products based on angel powerfl passed CFCA evaluation
Simple use of tensor
Svg canvas canvas drag
【蓝桥杯集训100题】scratch辨别质数合数 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第15题
9 use of tensorboard
Unlock the value of data fusion! Tencent angel powerfl won the "leading scientific and Technological Achievement Award" at the 2021 digital Expo
随机推荐
4 custom model training
Svg canvas canvas drag
Tweenmax+svg switch color animation scene
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
C language reading data
Selenium chrome disable JS disable pictures
NFT transaction principle analysis (2)
Canvas three dot flashing animation
AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
svg上升的彩色气泡动画
Panoramic analysis of upstream, middle and downstream industrial chain of "dry goods" NFT
【leetcode】331. Verifying the preorder serialization of a binary tree
【leetcode】701. Insert operation in binary search tree
Tencent Peking University's sparse large model training acceleration program het was selected into the VLDB of the international summit
3. Keras version model training
2 three modeling methods
js文本滚动分散动画js特效
人人都当科学家之免Gas体验mint爱死机
NFT transaction principle analysis (1)
10 tf.data