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 四种  
         
         
         
         
**********************技术交流请 email:cuihao0532#163.com 欢迎转载,转载请注明出处!***************************** 如果对本文满意请扫描文章左侧【二维码添加微信】获取更多好玩、有趣、有益、有营养的料, 你我共同成长!Y(^_^)Y
原文地址:https://www.cnblogs.com/cuish/p/14678718.html