|
|
@@ -1,10 +1,12 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace tw\redis\traits;
|
|
|
|
|
|
use tw\redis\TwRedis;
|
|
|
|
|
|
-trait SortedSetTrait {
|
|
|
-
|
|
|
+trait SortedSetTrait
|
|
|
+{
|
|
|
+
|
|
|
/**
|
|
|
* 添加/更新一个元素
|
|
|
*
|
|
|
@@ -12,7 +14,7 @@ trait SortedSetTrait {
|
|
|
* @param float $score
|
|
|
* @return int 0|1 1代表新增
|
|
|
*/
|
|
|
- public function zadd($word, $val, $score) : int
|
|
|
+ public function zadd($word, $val, $score): int
|
|
|
{
|
|
|
return TwRedis::zAdd($this->key($word), $score, $val);
|
|
|
}
|
|
|
@@ -20,14 +22,13 @@ trait SortedSetTrait {
|
|
|
/**
|
|
|
* 删除 1 个或多个元素
|
|
|
*/
|
|
|
- public function zrem($word, $members) : int
|
|
|
+ public function zrem($word, $members): int
|
|
|
{
|
|
|
if (is_array($members)) {
|
|
|
return TwRedis::zRem($this->key($word), ...$members);
|
|
|
} else {
|
|
|
return TwRedis::zRem($this->key($word), $members);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -47,7 +48,7 @@ trait SortedSetTrait {
|
|
|
* @param string $member
|
|
|
* @return float 名次
|
|
|
*/
|
|
|
- public function zrank($word, $member) : float
|
|
|
+ public function zrank($word, $member): float
|
|
|
{
|
|
|
return TwRedis::zRank($this->key($word), $member);
|
|
|
}
|
|
|
@@ -55,7 +56,7 @@ trait SortedSetTrait {
|
|
|
/**
|
|
|
* 求 zset 的基数
|
|
|
*/
|
|
|
- public function zcard($word) : int
|
|
|
+ public function zcard($word): int
|
|
|
{
|
|
|
return TwRedis::zCard($this->key($word));
|
|
|
}
|
|
|
@@ -66,7 +67,7 @@ trait SortedSetTrait {
|
|
|
* @param float|string $start,$end: 也可以包括 +inf -inf 表示正负无穷
|
|
|
* @return
|
|
|
*/
|
|
|
- public function zcount($word, $start, $end) : int
|
|
|
+ public function zcount($word, $start, $end): int
|
|
|
{
|
|
|
return TwRedis::zCount($this->key($word), $start, $end);
|
|
|
}
|
|
|
@@ -74,7 +75,7 @@ trait SortedSetTrait {
|
|
|
/**
|
|
|
* 增加指定元素的分数
|
|
|
*/
|
|
|
- public function zincr_by($word, $member, $by) : float
|
|
|
+ public function zincr_by($word, $member, $by): float
|
|
|
{
|
|
|
return TwRedis::zIncrBy($this->key($word), $by, $member);
|
|
|
}
|
|
|
@@ -82,7 +83,7 @@ trait SortedSetTrait {
|
|
|
/**
|
|
|
* 弹出分数最大的几个
|
|
|
*/
|
|
|
- public function zpop_max($word, $num) : array
|
|
|
+ public function zpop_max($word, $num): array
|
|
|
{
|
|
|
return TwRedis::zPopMax($this->key($word), $num);
|
|
|
}
|
|
|
@@ -90,7 +91,7 @@ trait SortedSetTrait {
|
|
|
/**
|
|
|
* 弹出分数最小的几个
|
|
|
*/
|
|
|
- public function zpop_min($word, $num) : array
|
|
|
+ public function zpop_min($word, $num): array
|
|
|
{
|
|
|
return TwRedis::zPopMin($this->key($word), $num);
|
|
|
}
|
|
|
@@ -104,7 +105,7 @@ trait SortedSetTrait {
|
|
|
* ['withscores' => TRUE, 'limit' => [1, 1]]
|
|
|
* @return
|
|
|
*/
|
|
|
- public function zrange_by_score($word, $start, $end, $options) : array
|
|
|
+ public function zrange_by_score($word, $start, $end, $options): array
|
|
|
{
|
|
|
return TwRedis::zRangeByScore($this->key($word), $start, $end, $options);
|
|
|
}
|
|
|
@@ -118,4 +119,4 @@ trait SortedSetTrait {
|
|
|
{
|
|
|
return TwRedis::zRemRangeByScore($this->key($word), $start, $end);
|
|
|
}
|
|
|
-}
|
|
|
+}
|