• Redis字符串类型


    字符串是Redis中最基本的数据类型,他能存储任何形式的字符串,包括二进制数据。

    命令

    1. 赋值

      SET key value
      
      > SET key hello
      OK
      
    2. 取值

      GET key
      
      > GET key
      "hello"
      
    3. 递增数字

      INCR key
      
      > INCR num
      (integer) 1
      
      

      要操作的键不存在时默认键值为0,不是整数时会报错

    4. 递减数字

      DECR key
      
      > DECR num
      (integer) 0
      
      

      要操作的键不存在时默认键值为0,不是整数时会报错

    5. 增加制定的整数

      INCRBY key increment
      
      > INCRBY num 2
      (integer) 2
      
    6. 减少指定的整数

      DECRBY key increment
      
      > INCRBY num 2
      (integer) 0
      
    7. 增加制定浮点数

      INCRBYFLOAT key increment
      
      > INCRBYFLOAT num 2.7
      "2.7"
      
    8. 向尾部追加值

      APPEND key increment
      
      > SET key hello
      OK
      > APPEND key " world!"
      (integer) 12
      

      返回值是追加后字符串的总长度

    9. 获取字符串长度

      STRLEN key
      
      > STRLEN key
      (integer) 12
      

      如果键不存在则返回0

    10. 同时设置多个键值

      MSET key value [key value ...]
      
      > MSET key1 v1 key2 v2 key3 v3
      OK
      
    11. 同时获取多个键值

      MGET key value [key value ...]
      
      > MSET key1 key3
      1) "v1"
      2) "v3"
      
    12. 位获取

      GETBIT key offset
      
      > SET foo bar
      OK
      > GETBIT foo 0
      (integer) 0
      > GETBIT foo 6
      (integer) 1 
      

      如果获取的二进制位的索引超出了键值的二进制位的实际长度则默认位值是0

    13. 位设置

      SETBIT key offset value
      
      > SETBIT key 6 0
      (integer) 1
      > SETBIT key 7 1
      (integer) 0
      > GET foo
      "aar"
      

      如果设置的位置超过了键值的二进制位的长度,SETBIT会自动将总监的二进制位设为0。同理设置一个不存在的键的指定二进制位的值会自动将其前面的位赋值为0。

    14. 位统计

      BITCOUNT key [start] [end]
      
      > BITCOUNT foo
      (integer) 10
      > BITCOUNT foo 0 1
      (integer) 6
      
    15. 位运算

      BITOP operation destkey key [key ...]
      
      > SET foo1 bar
      OK
      > SET foo2 aar
      OK
      > BITOP OR res foo1 foo2
      "Car"
      
    16. 获得指定键的第一个位值是0或1的位置

      BITPOS destkey value [start] [end]
      
      > SET foo bar
      OK
      > BITPOS foo 1
      (integer) 1
      > BITPOS foo 1 1 2
      (integer) 9
      
  • 相关阅读:
    HDU 3152 Obstacle Course(BFS+优先队列 重载)
    芸芸毕业生
    shell学习三十四天----printf具体解释
    tomcat启动批处理——catalina.bat
    ZooKeeper启动过程2:FastLeaderElection
    R语言——数据分析的一把利剑
    Oracle blob字段的插入和更新
    [LeetCode] 698. Partition to K Equal Sum Subsets
    小知识!
    小知识!
  • 原文地址:https://www.cnblogs.com/leisurelylicht/p/Redis-zi-fu-chuan-lei-xing.html
Copyright © 2020-2023  润新知