• 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
  • 相关阅读:
    [纯C#实现]基于BP神经网络的中文手写识别算法
    【转载】Jedis对管道、事务以及Watch的操作详细解析
    redis 缓存用户账单策略
    redis 通配符 批量删除key
    explain分析sql效率
    mysql 常用命令大全
    【转载】实战mysql分区(PARTITION)
    mysql表名忽略大小写配置
    【转】微服务架构的分布式事务解决方案
    【转载】Mysql中的Btree与Hash索引比较
  • 原文地址:https://www.cnblogs.com/cuish/p/14678718.html
Copyright © 2020-2023  润新知