zoukankan      html  css  js  c++  java
  • Redis字符串操作

     

    字符串命令

     (基本用法)


    GET : 获取给定键的值

    SET : 设置给定键的值

    DEL : 删除给定键的值(这个命令可以用于任何类型)

    (自增命令和自减命令)

    INCR : INCR key-name ------将键存储的值加1

    DECR : DECR key-name-------将键存储的值减1

    INCRBY : INCRBY key-name amount------将键存储的值加上整数account

    DECRBY : DECRBY kiey-name amount-------将键存储的值减去整数account

    INCRBYFLOAT : INCRBYFLOAT key-name amount-------------将键存储的值加上浮点数account(2.6版本以上可用)

    >>> import redis
    >>> conn = redis.Redis(host='192.168.146.129',port=6379,db=0)
    >>> conn.get('key')
    '14'
    >>> conn.set('key',1)
    True
    >>> conn.incr('key')
    2
    >>> conn.incr('key',15)
    17
    >>> conn.decr('key',8)
    9
    >>> conn.get('key')
    '9'
    >>> conn.set('key','13')
    True
    >>> conn.incr('key',15)
    28

     (Redis子串操作和二进制操作)

    APPEND : APPEND key-name value--------将值value追加到给定键值的末尾

    GETRANGE : GETRANGE  key-name start end---------截取字符串,包括start到end范围内

    SETRANGE : SETRANGE key-name offset value----------从offset位置开始设置字符串的值

    GETBIT : GETBIT key-name offset----------将字节看成二进制位串,并返回位串中偏移量为offset的二进制位的值

    SETBIT :SETBIT key-name offset value--------将字节串看作是二进制位串,并将位串中偏移量为offset的二进制位的值设置为value

    >>> import redis
    >>> conn = redis.Redis(host='192.168.146.129',port=6379,db=0)
    >>> coon.append('new-string-key','hello')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'coon' is not defined
    >>> conn.append('new-string-key','hello')
    5L
    >>> conn.append('new-string-key',' world')
    11L
    >>> conn.substr('new-string-key',3,7)
    'lo wo'
    >>> conn.setrange('new-string-key',0,'H')
    11
    >>> conn.get('new-string-key')
    'Hello world'
    >>> conn.setrange('new-string-key',18,'ffff')
    22
    >>> conn.get('new-string-key')
    'Hello worldx00x00x00x00x00x00x00ffff'
    >>> conn.setbit('another-key',2,1)
    0
    >>> conn.get('another-key')
    ' '
    >>> conn.setbit('another-key',7,1)
    0
    >>> conn.get('another-key')
    '!'
  • 相关阅读:
    菜根谭#188
    菜根谭#187
    Single value range only allowed in SystemVerilog
    LUTs, Flip-Flop, Slice
    FPGA 的 RAM 的 区别
    GPU core clock, shader clock ???
    更改Mac的Terminal 格式
    GPU share memory 的应用 (主要内容转载)
    Mac text edit & pdf reader
    Programming Font
  • 原文地址:https://www.cnblogs.com/ldybyz/p/6411860.html
Copyright © 2011-2022 走看看