在redis 里 0 表示最小,-1表示最大,负数表示第x大的数 0 -14 表示从最小的数开始到第14大的数。
set name value
get name
del name
incr name 使name 增长1;
decr -1
There is something special about INCR. Why do we provide such an operation if we can do it ourself with a bit of code? After all it is as simple as:
x = GET count
x = x + 1
SET count x
The problem is that doing the increment in this way will only work as long as there is a single client using the key. See what happens if two clients are accessing this key at the same time:
- Client A reads count as 10.
- Client B reads count as 10.
- Client A increments 10 and setscount to 11.
- Client B increments 10 and setscount to 11.
We wanted the value to be 12, but instead it is 11! This is because incrementing the value in this way is not an atomic operation. Calling theINCR command in Redis will prevent this from happening, because itis an atomic operation. Redis provides many of these atomic operations on different types of data.
expire:设置一个字段过期时间 默认以秒为单位
ttl: 查看字段剩余可以用时间 -1表示永久存在,-2表示已经被删除
在list中 有 RPUSH, LPUSH,LLEN,LRANGE,LPOP, andRPOP.命令
RPUSH/LPUSH arrayname value 把value存入arrayname中;
LRANGE arrayname 0 -1 列出 array中的元素; 第二个元素-1表示列出所有的元素
LLEN arrayname 列出数组长度
LPOP arrayname removes the first element from the list and returns it.
RPOP
在set中有 SADD, SREM,SISMEMBER,SMEMBERS andSUNION.
SISMEMBER : tests if the given value is in the set. It returns 1 if the value is there and0 if it is not.
sorted set
ZADD ZRANGE
SDIFF 返回存在于第一个集合,但是不存在于其他集合中的元素。
SDIFFSTORE dest-key key-name [key name...] ...........................................................................,并保存到dest-key中
SINTER 返回同时存在于所有集合的元素
SINTERSOTRE
SUNION 返回至少存在于一个集合中的元素
SUNITSTORE
hash set
HSET setname key value
HGETALL setname
HGET setname key
HMSET setname key value key2 value2