当前位置:网站首页>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的二进制数组。
️ 感谢大家
如果你觉得这篇内容对你挺有有帮助的话:
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。 - 有不当之处欢迎批评指正。
边栏推荐
- svg上升的彩色气泡动画
- 3. Keras version model training
- C# 读写文件从用户态切到内核态,到底是个什么流程?
- 面试踩坑总结一
- 4 custom model training
- [problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long
- Big talk Domain Driven Design -- presentation layer and others
- AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
- NFT contract basic knowledge explanation
- 7 自定义损失函数
猜你喜欢

NFT合约基础知识讲解

理想路径问题

STEPN 新手入门及进阶

SAP OData development tutorial - from getting started to improving (including segw, rap and CDP)

Handwritten numeral recognition, run your own picture with the saved model

Nanopi duo2 connection WiFi

牛客小白月赛50

El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed

Stepn novice introduction and advanced

Reflection modification final
随机推荐
The first batch in the industry! Tencent cloud security and privacy computing products based on angel powerfl passed CFCA evaluation
js文本滚动分散动画js特效
OpenSea上如何创建自己的NFT(Polygon)
I want to know how to open an account through online stock? Is online account opening safe?
还存在过有键盘的kindle?
svg上升的彩色气泡动画
golang 临时对象池优化
[time complexity and space complexity]
Cookie和Session详解
NFT 平台安全指南(1)
振动式液量检测装置
11 cnn简介
01 backpack DP
5000 word analysis: the way of container security attack and defense in actual combat scenarios
JVM笔记
Everyone is a scientist free gas experience Mint love crash
What is the difference between stm32f1 and gd32f1?
NFT交易原理分析(1)
IntelliJ idea -- Method for formatting SQL files
简单科普Ethereum的Transaction Input Data