当前位置:网站首页>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) 0bitcount命令
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) 2bitcount命令的实现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的二进制数组。
️ 感谢大家
如果你觉得这篇内容对你挺有有帮助的话:
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。 - 有不当之处欢迎批评指正。
边栏推荐
- Handwritten numeral recognition, run your own picture with the saved model
- Svg capital letter a animation JS effect
- 「幹貨」NFT 上中下遊產業鏈全景分析
- What is the process of switching C # read / write files from user mode to kernel mode?
- 如何辨别合约问题
- 牛客小白月赛50
- OpenSea上如何创建自己的NFT(Polygon)
- 全面解析Discord安全问题
- 4 自定义模型训练
- How do I open an account on my mobile phone? Is online account opening safe?
猜你喜欢

人人都当科学家之免Gas体验mint爱死机
![[problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long](/img/31/d14316dca740590c1871efe6587e04.png)
[problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long

『C语言』题集 of ⑩

svg环绕地球动画js特效

NFT交易原理分析(1)

js文本滚动分散动画js特效
Practice of federal learning in Tencent micro vision advertising

若依如何实现接口限流?

JS creative icon navigation menu switch background color

Comprehensive analysis of discord security issues
随机推荐
4 自定义模型训练
油田勘探问题
Svg capital letter a animation JS effect
Beijing University and Tencent jointly build angel4.0, and the self-developed in-depth learning framework "River map" is integrated into the ecology
How to create your own NFT (polygon) on opensea
NFT合约基础知识讲解
I want to know how to open an account through online stock? Is online account opening safe?
现在券商的优惠开户政策是什么?现在在线开户安全么?
NFT 平台安全指南(1)
10 tf. data
【leetcode】331. 验证二叉树的前序序列化
2 three modeling methods
Unlock the value of data fusion! Tencent angel powerfl won the "leading scientific and Technological Achievement Award" at the 2021 digital Expo
AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
【leetcode】701. Insert operation in binary search tree
5000字解析:实战化场景下的容器安全攻防之道
js创意图标导航菜单切换背景色
【蓝桥杯集训100题】scratch辨别质数合数 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第15题
(1) Keras handwritten numeral recognition and recognition of self written numbers
svg野人动画代码