php redis zset score 自增,php对redis的zset(有序集合)操作

<?phprequire ('redistest.php');classzsetcacheextendscache{/***向名称为key的zset中添加元素member,score用亍排序。如果该元素已经存在,则根据score更新该元素的顺序。*ZADD命令的返回值是新加入到集合中的元素个数**@param$key string集合名称*@param$score int分数*@param$member string值*@returnint返回插入的个数*/public functionzAdd($key,$score,$member){return$this->redis->zAdd($key,$score,$member);}/***返回名称为key的zset(元素已按score从小到大排序)中的index从start到end的所有元素* ZRANGE命令会按照元素分数从小到大的顺序返回索引从start到stop之间的所有元素(包*含两端的元素)。ZRANGE命令与LRANGE命令十分相似,如索引都是从0开始,负数代表从后*向前查找(-1表示最后一个元素)**@param$key string集合名称*@param$start int开始*@param$end   int结束*@parambool $withscores是否查找分数*@returnarray返回集合的的数组*/public functionzRange($key,$start,$end,$withscores=False){if($withscores){return$this->redis->zRange($key,$start,$end,true);}else{return$this->redis->zRange($key,$start,$end);}}/***删除名称为key的zset中的元素member,返回删除的个数*作用同zDelete**@param$key string集合*@param$member string元素*@returnint删除的个数*/public functionzRem($key,$member){return$this->redis->zRem($key,$member);}/***与zRange功能一样,只是zRevRange返回的元素是按score从大到小排序的**@param$key string集合名称*@param$start int开始*@param$end  int结束*@parambool $withscores是否查找分数*@returnarray返回集合的的数组*/public functionzRevRange($key,$start,$end,$withscores=False){if($withscores){return$this->redis->zRevRange($key,$start,$end,true);}else{return$this->redis->zRevRange($key,$start,$end);}}/***@param$key string集合名称*@param$start int开始*@param$end  int结束*@param$limit*@parambool|False $withscores是否查找分数*@returnmixed*/public functionzRangeByScore($key,$start,$end,$limit,$withscores=False){if($withscores){return$this->redis->zRangeByScore($key,$start,$end,array('$withscores'=>TRUE,'limit'=>$limit));}else{return$this->redis->zRangeByScore($key,$start,$end,array('limit'=>$limit));}}/***返回名称为key的zset中score >= star且score <= end的所有元素的个数**@param$key string集合名称*@param$start int开始*@param$end  int结束*@returnint*/public functionzCount($key,$start,$end){return$this->redis->zCount($key,$start,$end);}/***删除名称为key的zset中score >= star且score <= end的所有元素,返回删除个数**@param$key string集合名称*@param$start int开始*@param$end  int结束*@returnint*/public functionzRemRangeByScore($key,$start,$end){return$this->redis->zRemRangeByScore($key,$start,$end);}/***返回名称为key的zset的所有元素的个数*作用同zCard*@param$key集合名称*@returnInt返回个数*/public functionzSize($key){return$this->redis->zSize($key);}/***返回集合key中元素member的分数**@param$key string集合*@param$member string元素*@returnfloat|bool分数(如果不存在就返回false)*/public functionzScore($key,$member){return$this->redis->zScore($key,$member);}/***返回名称为key的zset(元素已按score从小到大排序)中val元素的rank(即index,从0开始),若没有val元素,返回“0”。*就是返回比元素$member分数小的元素的个数**@param$key string集合*@param$member string元素*@returnint*/public functionzRank($key,$member){return$this->redis->zRank($key,$member);}/***就是返回比元素$member分数大的元素的个数*@param$key string集合*@param$member string元素*@returnint*/public functionzRevRank($key,$member){return$this->redis->zRevRank($key,$member);}/***如果在名称为key的zset中已经存在元素member,则该元素的score增加increment;否则向集合中添加该元素,其score的值为increment**@param$key集合*@param$increment分数*@param$member元素*@returnint增加的分数*/public functionzIncrBy($key,$increment,$member){return$this->redis->zIncrBy($key,$increment,$member);}/***求有序集合的并集**@param$output要保存的集合*@param$zsetkey求并集的集合*@returnint集合的数目*/public functionzUnion($output,$zsetkey){return$this->redis->zUnion($output,$zsetkey);}/***求有序集合的交集**@param$output要保存的集合*@param$zsetkey求并集的集合*@returnint集合的数目*/public functionzInter($output,$zsetkey){return$this->redis->zInter($output,$zsetkey);}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值