-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathSortedSetsCommandsTrait.php
129 lines (120 loc) · 4.32 KB
/
SortedSetsCommandsTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* This file is part of RedisClient.
* git: https://github.com/cheprasov/php-redis-client
*
* (C) Alexander Cheprasov <acheprasov84@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RedisClient\Command\Traits\Version2x8;
use RedisClient\Command\Parameter\Parameter;
use RedisClient\Command\Traits\Version2x6\SortedSetsCommandsTrait as SortedSetsCommandsTraitVersion2x6;
/**
* SortedSets Commands
* @link http://redis.io/commands#set
* @link http://redis.io/topics/data-types#sorted-sets
*/
trait SortedSetsCommandsTrait {
use SortedSetsCommandsTraitVersion2x6;
/**
* ZLEXCOUNT key min max
* Available since 2.8.9.
* Time complexity: O(log(N)) with N being the number of elements in the sorted set.
* @link http://redis.io/commands/zlexcount
*
* @param string $key
* @param string $min
* @param string $max
* @return int The number of elements in the specified score range.
*/
public function zlexcount($key, $min, $max) {
return $this->returnCommand(['ZLEXCOUNT'], $key, [$key, $min, $max]);
}
/**
* ZRANGEBYLEX key min max [LIMIT offset count]
* Available since 2.8.9.
* Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and
* M the number of elements being returned.
* If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
* @link http://redis.io/commands/zrangebylex
*
* @param string $key
* @param string $min
* @param string $max
* @param int|array $limit
* @return string[] List of elements in the specified score range.
*/
public function zrangebylex($key, $min, $max, $limit = null) {
$params = [$key, $min, $max];
if ($limit) {
$params[] = 'LIMIT';
$params[] = Parameter::limit($limit);
}
return $this->returnCommand(['ZRANGEBYLEX'], $key, $params);
}
/**
* ZREMRANGEBYLEX key min max
* Available since 2.8.9.
* Time complexity: O(log(N)+M) with N being the number of elements in the sorted set
* and M the number of elements removed by the operation.
* @link http://redis.io/commands/zremrangebylex
*
* @param string $key
* @param string $min
* @param string $max
* @return int The number of elements removed.
*/
public function zremrangebylex($key, $min, $max) {
return $this->returnCommand(['ZREMRANGEBYLEX'], $key, [$key, $min, $max]);
}
/**
* ZREVRANGEBYLEX key max min [LIMIT offset count]
* Available since 2.8.9.
* Time complexity: O(log(N)+M) with N being the number of elements in the sorted set
* and M the number of elements being returned.
* If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
* @link http://redis.io/commands/zrevrangebylex
*
* @param string $key
* @param string $max
* @param string $min
* @param int|array $limit
* @return string[] List of elements in the specified score range.
*/
public function zrevrangebylex($key, $max, $min, $limit = null) {
$params = [$key, $max, $min];
if ($limit) {
$params[] = 'LIMIT';
$params[] = Parameter::limit($limit);
}
return $this->returnCommand(['ZREVRANGEBYLEX'], $key, $params);
}
/**
* ZSCAN key cursor [MATCH pattern] [COUNT count]
* Available since 2.8.0.
* Time complexity: O(1) for every call. O(N) for a complete iteration,
* including enough command calls for the cursor to return back to 0.
* N is the number of elements inside the collection.
* @link http://redis.io/commands/zscan
*
* @param string $key
* @param int $cursor
* @param string|null $pattern
* @param int|null $count
* @return mixed
*/
public function zscan($key, $cursor, $pattern = null, $count = null) {
$params = [$key, $cursor];
if ($pattern) {
$params[] = 'MATCH';
$params[] = $pattern;
}
if ($count) {
$params[] = 'COUNT';
$params[] = $count;
}
return $this->returnCommand(['ZSCAN'], $key, $params);
}
}