字符串命令
(基本用法)
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 world\x00\x00\x00\x00\x00\x00\x00ffff‘ >>> conn.setbit(‘another-key‘,2,1) 0 >>> conn.get(‘another-key‘) ‘ ‘ >>> conn.setbit(‘another-key‘,7,1) 0 >>> conn.get(‘another-key‘) ‘!‘
原文:http://www.cnblogs.com/ldybyz/p/6411860.html