Completed
Pull Request — master (#96)
by Roberto
12:14
created

SortedSets::zRevRangeByScore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Webdcg\Redis\Traits;
4
5
use Webdcg\Redis\Exceptions\SetOperationException;
6
7
trait SortedSets
8
{
9
    /*
10
     * Available Set Operations
11
     */
12
    protected $SET_OPERATIONS = ['SUM', 'MIN', 'MAX'];
13
14
    public function bzPop(): bool
15
    {
16
        return false;
17
    }
18
19
    /**
20
     * Add one or more members to a sorted set or update its score if it
21
     * already exists.
22
     * See: https://redis.io/commands/zadd.
23
     *
24
     * @param  string $key
25
     * @param  float  $score
26
     * @param  mixed] $member
0 ignored issues
show
Documentation introduced by
The doc-type mixed] could not be parsed: Expected "|" or "end of type", but got "]" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
27
     *
28
     * @return int              1 if the element is added. 0 otherwise.
29
     */
30
    public function zAdd(string $key, float $score, $member): int
31
    {
32
        return $this->redis->zAdd($key, $score, $member);
0 ignored issues
show
Bug introduced by
The property redis does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
    }
34
35
    /**
36
     * Get the number of members in a sorted set.
37
     * See: https://redis.io/commands/zcard.
38
     *
39
     * @param  string $key
40
     *
41
     * @return int          The Set's cardinality
42
     */
43
    public function zCard(string $key): int
44
    {
45
        return $this->redis->zCard($key);
46
    }
47
48
    /**
49
     * Get the number of members in a sorted set.
50
     * Note: zSize is an alias for zCard and will be removed in future
51
     * versions of phpredis.
52
     * See: https://redis.io/commands/zcard.
53
     *
54
     * @param  string $key
55
     *
56
     * @return int          The Set's cardinality
57
     */
58
    public function zSize(string $key): int
59
    {
60
        return $this->redis->zCard($key);
61
    }
62
63
    /**
64
     * Returns the number of elements of the sorted set stored at the specified
65
     * key which have scores in the range [start, end]. Adding a parenthesis
66
     * before start or end excludes it from the range. +inf and -inf are also
67
     * valid limits.
68
     * See: https://redis.io/commands/zcount.
69
     *
70
     * @param  string $key
71
     * @param  mixed|int|string $start
72
     * @param  mixed|int|string $end
73
     *
74
     * @return int                      the size of a corresponding zRangeByScore.
75
     */
76
    public function zCount(string $key, $start, $end): int
77
    {
78
        return $this->redis->zCount($key, $start, $end);
79
    }
80
81
    /**
82
     * Increments the score of a member from a sorted set by a given amount.
83
     * See: https://redis.io/commands/zincrby.
84
     *
85
     * @param  string $key
86
     * @param  float  $value    (double) value that will be added to the
87
     *                          member's score).
88
     * @param  string $member
89
     *
90
     * @return float            the new value
91
     */
92
    public function zIncrBy(string $key, float $value, $member): float
93
    {
94
        return $this->redis->zIncrBy($key, $value, $member);
95
    }
96
97
    /**
98
     * Creates an intersection of sorted sets given in second argument.
99
     * The result of the union will be stored in the sorted set defined by the
100
     * first argument.
101
     * The third optional argument defines weights to apply to the sorted sets
102
     * in input. In this case, the weights will be multiplied by the score of
103
     * each element in the sorted set before applying the aggregation. The
104
     * forth argument defines the AGGREGATE option which specify how the
105
     * results of the union are aggregated.
106
     * See: https://redis.io/commands/zinterstore.
107
     *
108
     * @param  string $keyOutput
109
     * @param  array  $arrayZSetKeys
110
     * @param  array  $arrayWeights
111
     * @param  string $aggregateFunction    Either "SUM", "MIN", or "MAX":
112
     *                                      defines the behaviour to use on
113
     *                                      duplicate entries during the
114
     *                                      zInterStore.
115
     *
116
     * @return int                          The number of values in the new
117
     *                                      sorted set.
118
     */
119
    public function zInterStore(
120
        string $keyOutput,
121
        array $arrayZSetKeys,
122
        ?array $arrayWeights = null,
123
        ?string $aggregateFunction = null
124
    ): int {
125
        // Validate Aggregate Function
126
        if (!is_null($aggregateFunction) && !is_null($arrayWeights)) {
127
            $operation = strtoupper($aggregateFunction);
128
129
            if (!in_array($operation, $this->SET_OPERATIONS)) {
130
                throw new SetOperationException('Operation not supported', 1);
131
            }
132
133
            return $this->redis->zInterStore($keyOutput, $arrayZSetKeys, $arrayWeights, $operation);
134
        }
135
136
        // Call using Weights
137
        if (!is_null($arrayWeights)) {
138
            return $this->redis->zInterStore($keyOutput, $arrayZSetKeys, $arrayWeights);
139
        }
140
141
        // Make simplest call just with the required params
142
        return $this->redis->zInterStore($keyOutput, $arrayZSetKeys);
143
    }
144
145
    /**
146
     * Creates an intersection of sorted sets given in second argument.
147
     * The result of the union will be stored in the sorted set defined by the
148
     * first argument.
149
     * The third optional argument defines weights to apply to the sorted sets
150
     * in input. In this case, the weights will be multiplied by the score of
151
     * each element in the sorted set before applying the aggregation. The
152
     * forth argument defines the AGGREGATE option which specify how the
153
     * results of the union are aggregated.
154
     * Note: zInter is an alias for zinterstore and will be removed in future
155
     * versions of phpredis.
156
     * See: https://redis.io/commands/zinterstore.
157
     *
158
     * @param  string $keyOutput
159
     * @param  array  $arrayZSetKeys
160
     * @param  array  $arrayWeights
161
     * @param  string $aggregateFunction    Either "SUM", "MIN", or "MAX":
162
     *                                      defines the behaviour to use on
163
     *                                      duplicate entries during the
164
     *                                      zInterStore.
165
     *
166
     * @return int                          The number of values in the new
167
     *                                      sorted set.
168
     */
169
    public function zInter(
170
        string $keyOutput,
171
        array $arrayZSetKeys,
172
        ?array $arrayWeights = null,
173
        ?string $aggregateFunction = null
174
    ): int {
175
        // Validate Aggregate Function
176
        if (!is_null($aggregateFunction) && !is_null($arrayWeights)) {
177
            $operation = strtoupper($aggregateFunction);
178
179
            if (!in_array($operation, $this->SET_OPERATIONS)) {
180
                throw new SetOperationException('Operation not supported', 1);
181
            }
182
183
            return $this->redis->zInterStore($keyOutput, $arrayZSetKeys, $arrayWeights, $operation);
184
        }
185
186
        // Call using Weights
187
        if (!is_null($arrayWeights)) {
188
            return $this->redis->zInterStore($keyOutput, $arrayZSetKeys, $arrayWeights);
189
        }
190
191
        // Make simplest call just with the required params
192
        return $this->redis->zInterStore($keyOutput, $arrayZSetKeys);
193
    }
194
195
    public function zPop(): bool
196
    {
197
        return false;
198
    }
199
200
    public function zRange(): bool
201
    {
202
        return false;
203
    }
204
205
    public function zRangeByScore(): bool
206
    {
207
        return false;
208
    }
209
210
    public function zRevRangeByScore(): bool
211
    {
212
        return false;
213
    }
214
215
    public function zRangeByLex(): bool
216
    {
217
        return false;
218
    }
219
220
    public function zRank(): bool
221
    {
222
        return false;
223
    }
224
225
    public function zRevRank(): bool
226
    {
227
        return false;
228
    }
229
230
    public function zRem(): bool
231
    {
232
        return false;
233
    }
234
235
    public function zDelete(): bool
236
    {
237
        return false;
238
    }
239
240
    public function zRemove(): bool
241
    {
242
        return false;
243
    }
244
245
    public function zRemRangeByRank(): bool
246
    {
247
        return false;
248
    }
249
250
    public function zDeleteRangeByRank(): bool
251
    {
252
        return false;
253
    }
254
255
    public function zRemRangeByScore(): bool
256
    {
257
        return false;
258
    }
259
260
    public function zDeleteRangeByScore(): bool
261
    {
262
        return false;
263
    }
264
265
    public function zRemoveRangeByScore(): bool
266
    {
267
        return false;
268
    }
269
270
    public function zRevRange(): bool
271
    {
272
        return false;
273
    }
274
275
    public function zScore(): bool
276
    {
277
        return false;
278
    }
279
280
    public function zunionstore(): bool
281
    {
282
        return false;
283
    }
284
285
    public function zUnion(): bool
286
    {
287
        return false;
288
    }
289
290
    public function zScan(): bool
291
    {
292
        return false;
293
    }
294
}
295