redis基本数据结构-字符串

 

reids字符串数据结构相关命令  

 

 
序号 命令 命令实例 意义  
 1 set key value set bar 1 设置key为bar的值为"1"  
incr key incr bar 键bar的值加1,此时bar为"2"  
get key get bar 获取键为bar的值,为"2"  
incrby key increment  incr bar 10  键bar的值加10,此时bar为"12"  
decr key decr bar 键bar的值减1,此时bar为"11"  
decrby key decrement decrby bar 5 键bar的值减去5,此时bar为"6" 可以减到负数 
incrbyfloat key increment incrbyfloat bar 1.5 键bar的值加上1.5,此时为"7.5" 没有decrbyfloat命令
append key sub_str append bar hello  键bar的值追加字符串hello,此时为"7.5hello"   
strlen key strlen bar  获取键bar的值字符串长度(字节数),此时为8(8个字符,同时也是8个字节)   注意中文字符串长度区别于英文字符串长度,在utf8编码中,hello中国,长度为5+2*2==11 bytes
10   mset key1 value1 [key2 value2 ...] mset name zhangsan age 20 

同时设置key name 为zhangsan,key age为20

同理有mget 
11   mget key1 [key2 ...] mget name age bar  返回zhangsan 20  7.5hello  三个键值  
12  getbit key offset 

set bar a

getbit bar 2

 a的ascii码为97,对应二进制为01100001,getbit bar 即为获取bar的位置为2的比特位的值,返回1  
13  setbit key offset value setbit bar 3 1  01100001 => 01110001  
14  bitcount key [startBytes] [endBytes] bitcount bar 0 0   从[startBytes, endBytes]字节范围内寻找比特位为1的个数,闭区间,返回4(01110001作为一个字节有4个为1的比特位)  
15  bitop  operation  destkey  key1 [key2 key 3 ...]

set foo b

bitop or result bar foo

 对bar和foo做或运算,结果存储到result中,操作有AND OR XOR NOT 四种  
         
         
         
         

posted on   崔好好  阅读(68)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示