redis 命令

在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:

  1. Client A reads count as 10.
  2. Client B reads count as 10.
  3. Client A increments 10 and setscount to 11.
  4. 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







 


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值