| Command | Description | Supported | Tested | Class/Trait | Method |
|---|---|---|---|---|---|
| bzPop | Block until Redis can pop the highest or lowest scoring member from one or more ZSETs. | ✅ | ✅ | SortedSets | bzPop |
| bzPopMin | Block until Redis can pop the lowest scoring member from one or more ZSETs. | ✅ | ✅ | SortedSets | bzPopMin |
| bzPopMax | Block until Redis can pop the highest scoring member from one or more ZSETs. | ✅ | ✅ | SortedSets | bzPopMax |
| zAdd | Add one or more members to a sorted set or update its score if it already exists. | ✅ | ✅ | SortedSets | zAdd |
| zCard | Get the number of members in a sorted set. | ✅ | ✅ | SortedSets | zCard |
| zSize | Get the number of members in a sorted set. | ✅ | ✅ | SortedSets | zSize |
| zCount | Count the members in a sorted set with scores within the given values. | ✅ | ✅ | SortedSets | zCount |
| zIncrBy | Increment the score of a member in a sorted set. | ✅ | ✅ | SortedSets | zIncrBy |
| zinterstore | Intersect multiple sorted sets and store the resulting sorted set in a new key. | ✅ | ✅ | SortedSets | zinterstore |
| zInter | Intersect multiple sorted sets and store the resulting sorted set in a new key. | ✅ | ✅ | SortedSets | zInter |
| zPop | Redis can pop the highest or lowest scoring member from one a ZSET. | ✅ | ✅ | SortedSets | zPop |
| zRange | Return a range of members in a sorted set, by index. | ✅ | ✅ | SortedSets | zRange |
| zRangeByScore | Return a range of members in a sorted set, by score. | ✅ | ✅ | SortedSets | zRangeByScore |
| zRevRangeByScore | Return a range of members in a sorted set, by score. | ✅ | ✅ | SortedSets | zRevRangeByScore |
| zRangeByLex | Return a lexicographical range from members that share the same score. | ✅ | ✅ | SortedSets | zRangeByLex |
| zRank | Determine the index of a member in a sorted set. | ✅ | ✅ | SortedSets | zRank |
| zRevRank | Determine the index of a member in a sorted set. | ✅ | ✅ | SortedSets | zRevRank |
| zRem | Remove one or more members from a sorted set. | ✅ | ✅ | SortedSets | zRem |
| zDelete | Remove one or more members from a sorted set. | ✅ | ✅ | SortedSets | zDelete |
| zRemove | Remove one or more members from a sorted set. | ✅ | ✅ | SortedSets | zRemove |
| zRemRangeByRank | Remove all members in a sorted set within the given indexes. | ✅ | ✅ | SortedSets | zRemRangeByRank |
| zDeleteRangeByRank | Remove all members in a sorted set within the given indexes. | ✅ | ✅ | SortedSets | zDeleteRangeByRank |
| zRemRangeByScore | Remove all members in a sorted set within the given scores. | ✅ | ✅ | SortedSets | zRemRangeByScore |
| zDeleteRangeByScore | Remove all members in a sorted set within the given scores. | ✅ | ✅ | SortedSets | zDeleteRangeByScore |
| zRemoveRangeByScore | Remove all members in a sorted set within the given scores. | ✅ | ✅ | SortedSets | zRemoveRangeByScore |
| zRevRange | Return a range of members in a sorted set, by index, with scores ordered from high to low. | ✅ | ✅ | SortedSets | zRevRange |
| zScore | Get the score associated with the given member in a sorted set. | ✅ | ✅ | SortedSets | zScore |
| zunionstore | Add multiple sorted sets and store the resulting sorted set in a new key. | ✅ | ✅ | SortedSets | zunionstore |
| zUnion | Add multiple sorted sets and store the resulting sorted set in a new key. | ✅ | ✅ | SortedSets | zUnion |
| zScan | Scan a sorted set for members. | ✅ | ✅ | SortedSets | zScan |
BZMPOP Removes and returns a member by score from one or more sorted sets. Blocks until a member is available otherwise. Deletes the sorted set if the last element was popped. BZPOPMAX Removes and returns the member with the highest score from one or more sorted sets. Blocks until a member available otherwise. Deletes the sorted set if the last element was popped. BZPOPMIN Removes and returns the member with the lowest score from one or more sorted sets. Blocks until a member is available otherwise. Deletes the sorted set if the last element was popped. ZADD Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist. ZCARD Returns the number of members in a sorted set. ZCOUNT Returns the count of members in a sorted set that have scores within a range. ZDIFF Returns the difference between multiple sorted sets. ZDIFFSTORE Stores the difference of multiple sorted sets in a key. ZINCRBY Increments the score of a member in a sorted set. ZINTER Returns the intersect of multiple sorted sets. ZINTERCARD Returns the number of members of the intersect of multiple sorted sets. ZINTERSTORE Stores the intersect of multiple sorted sets in a key. ZLEXCOUNT Returns the number of members in a sorted set within a lexicographical range. ZMPOP Returns the highest- or lowest-scoring members from one or more sorted sets after removing them. Deletes the sorted set if the last member was popped. ZMSCORE Returns the score of one or more members in a sorted set. ZPOPMAX Returns the highest-scoring members from a sorted set after removing them. Deletes the sorted set if the last member was popped. ZPOPMIN Returns the lowest-scoring members from a sorted set after removing them. Deletes the sorted set if the last member was popped. ZRANDMEMBER Returns one or more random members from a sorted set. ZRANGE Returns members in a sorted set within a range of indexes. ZRANGEBYLEX Returns members in a sorted set within a lexicographical range. ZRANGEBYSCORE Returns members in a sorted set within a range of scores. ZRANGESTORE Stores a range of members from sorted set in a key. ZRANK Returns the index of a member in a sorted set ordered by ascending scores. ZREM Removes one or more members from a sorted set. Deletes the sorted set if all members were removed. ZREMRANGEBYLEX Removes members in a sorted set within a lexicographical range. Deletes the sorted set if all members were removed. ZREMRANGEBYRANK Removes members in a sorted set within a range of indexes. Deletes the sorted set if all members were removed. ZREMRANGEBYSCORE Removes members in a sorted set within a range of scores. Deletes the sorted set if all members were removed. ZREVRANGE Returns members in a sorted set within a range of indexes in reverse order. ZREVRANGEBYLEX Returns members in a sorted set within a lexicographical range in reverse order. ZREVRANGEBYSCORE Returns members in a sorted set within a range of scores in reverse order. ZREVRANK Returns the index of a member in a sorted set ordered by descending scores. ZSCAN Iterates over members and scores of a sorted set. ZSCORE Returns the score of a member in a sorted set. ZUNION Returns the union of multiple sorted sets. ZUNIONSTORE Stores the union of multiple sorted sets in a key.
- bzPop - Block until Valkey can pop the highest or lowest scoring member from one or more ZSETs.
- zAdd - Add one or more members to a sorted set or update its score if it already exists
- zCard - Get the number of members in a sorted set
- zCount - Count the members in a sorted set with scores within the given values
- zDiff - Computes the difference between the first and all successive input sorted sets and return the resulting sorted set
- zdiffstore - Computes the difference between the first and all successive input sorted sets and stores the result in a new key
- zIncrBy - Increment the score of a member in a sorted set
- zInter - Intersect multiple sorted sets and return the resulting sorted set
- zinterstore - Intersect multiple sorted sets and store the resulting sorted set in a new key
- zMscore - Get the scores associated with the given members in a sorted set
- zPop - Valkey can pop the highest or lowest scoring member from one a ZSET.
- zRange - Return a range of members in a sorted set, by index
- zRangeByScore, zRevRangeByScore - Return a range of members in a sorted set, by score
- zRangeByLex - Return a lexicographical range from members that share the same score
- zRank, zRevRank - Determine the index of a member in a sorted set
- zRem - Remove one or more members from a sorted set
- zRemRangeByRank - Remove all members in a sorted set within the given indexes
- zRemRangeByScore - Remove all members in a sorted set within the given scores
- zRevRange - Return a range of members in a sorted set, by index, with scores ordered from high to low
- zScore - Get the score associated with the given member in a sorted set
- zUnion - Add multiple sorted sets and return the resulting sorted set
- zunionstore - Add multiple sorted sets and store the resulting sorted set in a new key
- zScan - Scan a sorted set for members
$valkey = new Valkey();
$valkey->connect('127.0.0.1', 6379);
$valkey->zAdd('key', 1, 'val1');
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 5, 'val5');
$valkey->zRange('key', 0, -1); // [val0, val1, val5]
// From Valkey 3.0.2 it's possible to add options like XX, NX, CH, INCR
$valkey->zAdd('key', ['CH'], 5, 'val5', 10, 'val10', 15, 'val15');Description: Block until Valkey can pop the highest or lowest scoring members from one or more ZSETs. There are two commands (BZPOPMIN and BZPOPMAX for popping the lowest and highest scoring elements respectively.)
$valkey->bzPopMin(array $keys, int $timeout): array
$valkey->bzPopMax(array $keys, int $timeout): array
$valkey->bzPopMin(string $key1, string $key2, ... int $timeout): array
$valkey->bzPopMax(string $key1, string $key2, ... int $timeout): arrayARRAY: Either an array with the key member and score of the highest or lowest element or an empty array if the timeout was reached without an element to pop.
/* Wait up to 5 seconds to pop the *lowest* scoring member from sets `zs1` and `zs2`. */
$valkey->bzPopMin(['zs1', 'zs2'], 5);
$valkey->bzPopMin('zs1', 'zs2', 5);
/* Wait up to 5 seconds to pop the *highest* scoring member from sets `zs1` and `zs2` */
$valkey->bzPopMax(['zs1', 'zs2'], 5);
$valkey->bzPopMax('zs1', 'zs2', 5);Note: Calling these functions with an array of keys or with a variable number of arguments is functionally identical.
Description: Add one or more members to a sorted set or update its score if it already exists
$valkey->zAdd($key, [ $options ,] $score, $value [, $score1, $value1, ...]);key: string
options: array (optional)
score: double
value: string
score1: double
value1: string
Long 1 if the element is added. 0 otherwise.
$valkey->zAdd('key', 1, 'val1');
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 5, 'val5');
$valkey->zRange('key', 0, -1); // [val0, val1, val5]
// From Valkey 3.0.2 it's possible to add options like XX, NX, CH, INCR
$valkey->zAdd('key', ['CH'], 5, 'val5', 10, 'val10', 15, 'val15');Description: Returns the cardinality of an ordered set.
key
Long, the set's cardinality
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 2, 'val2');
$valkey->zAdd('key', 10, 'val10');
$valkey->zCard('key'); /* 3 */Description: Returns the number of elements of the sorted set stored at the specified key which have scores in the range [start,end]. Adding a parenthesis before start or end excludes it from the range. +inf and -inf are also valid limits.
key
start: string
end: string
LONG the size of a corresponding zRangeByScore.
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 2, 'val2');
$valkey->zAdd('key', 10, 'val10');
$valkey->zCount('key', 0, 3); /* 2, corresponding to ['val0', 'val2'] */Description: Computes the difference between the first and all successive input sorted sets in the first argument. The result of the difference will be returned.
The second argument is a set of options. It can define WITHSCORES so that the scores are returned as well.
arrayZSetKeys
arrayOptions One option is available: withscores => TRUE.
ARRAY The result of the difference of sets.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k1', 3, 'val3');
$valkey->zAdd('k2', 5, 'val1');
$valkey->zAdd('k3', 5, 'val0');
$valkey->zAdd('k3', 3, 'val4');
$valkey->zDiff(['k1', 'k2']); /* ['val0', 'val3'] */
$valkey->zDiff(['k2', 'k1']); /* [] */
$valkey->zDiff(['k1', 'k2'], ['withscores' => true]); /* ['val0' => 0.0, 'val3' => 3.0] */
$valkey->zDiff(['k1', 'k2', 'k3']); /* ['val3'] */
$valkey->zDiff(['k3', 'k2', 'k1']); /* ['val4'] */Description: Computes the difference between the first and all successive input sorted sets in the second argument. The result of the difference will be stored in the sorted set defined by the first argument.
keyOutput
arrayZSetKeys
LONG The number of values in the new sorted set.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k1', 3, 'val3');
$valkey->zAdd('k2', 5, 'val1');
$valkey->zAdd('k3', 5, 'val0');
$valkey->zAdd('k3', 3, 'val4');
$valkey->zdiffstore('ko1', ['k1', 'k2']); /* 2, 'ko1' => ['val0', 'val3'] */
$valkey->zdiffstore('ko2', ['k2', 'k1']); /* 0, 'ko2' => [] */
$valkey->zdiffstore('ko3', ['k1', 'k2', 'k3']); /* 1, 'ko3' => ['val3'] */
$valkey->zdiffstore('ko4', ['k3', 'k2', 'k1']); /* 1, 'k04' => ['val4'] */Description: Increments the score of a member from a sorted set by a given amount.
key
value: (double) value that will be added to the member's score
member
DOUBLE the new value
$valkey->del('key');
$valkey->zIncrBy('key', 2.5, 'member1'); /* key or member1 didn't exist, so member1's score is to 0 before the increment */
/* and now has the value 2.5 */
$valkey->zIncrBy('key', 1, 'member1'); /* 3.5 */Description: Creates an intersection of sorted sets given in first argument. The result of the intersection will be returned.
The second optional argument defines weights to apply to the sorted sets in input. In this case, the weights will be multiplied by the score of each element in the sorted set before applying the aggregation.
The third argument is a set of options. It can define the AGGREGATE option which specify how the results of the intersection are aggregated. It can also define WITHSCORES so that the scores are returned as well.
arrayZSetKeys
arrayWeights
arrayOptions Two options are available: withscores => TRUE, and aggregate => $behaviour. Either "SUM", "MIN", or "MAX" defines the behaviour to use on duplicate entries during the zinter.
ARRAY The result of the intersection of sets.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k1', 3, 'val3');
$valkey->zAdd('k2', 5, 'val1');
$valkey->zAdd('k2', 3, 'val3');
$valkey->zinter(['k1', 'k2']); /* ['val1', 'val3'] */
$valkey->zinter(['k1', 'k2'], [1, 1]); /* ['val1', 'val3'] */
/* Weighted zinter */
$valkey->zinter(['k1', 'k2'], [1, 5], 'min'); /* ['val1', 'val3'] */
$valkey->zinter(['k1', 'k2'], [1, 5], 'max'); /* ['val3', 'val1'] */Description: Creates an intersection of sorted sets given in second argument. The result of the intersection will be stored in the sorted set defined by the first argument.
The third optional argument defines weights to apply to the sorted sets in input. In this case, the weights will be multiplied by the score of each element in the sorted set before applying the aggregation.
The forth argument defines the AGGREGATE option which specify how the results of the intersection are aggregated.
keyOutput
arrayZSetKeys
arrayWeights
aggregateFunction Either "SUM", "MIN", or "MAX": defines the behaviour to use on duplicate entries during the zinterstore.
LONG The number of values in the new sorted set.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->del('ko1');
$valkey->del('ko2');
$valkey->del('ko3');
$valkey->del('ko4');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k1', 3, 'val3');
$valkey->zAdd('k2', 5, 'val1');
$valkey->zAdd('k2', 3, 'val3');
$valkey->zinterstore('ko1', ['k1', 'k2']); /* 2, 'ko1' => ['val1', 'val3'] */
$valkey->zinterstore('ko2', ['k1', 'k2'], [1, 1]); /* 2, 'ko2' => ['val1', 'val3'] */
/* Weighted zinterstore */
$valkey->zinterstore('ko3', ['k1', 'k2'], [1, 5], 'min'); /* 2, 'ko3' => ['val1', 'val3'] */
$valkey->zinterstore('ko4', ['k1', 'k2'], [1, 5], 'max'); /* 2, 'ko4' => ['val3', 'val1'] */Description: Returns the scores of the given members in the specified sorted set.
key
members: member1, member2, ... , memberN: Any number of members in the specified sorted set.
ARRAY or FALSE when the key is not found. Array entries corresponding to members that do not exist will be false.
$valkey->zAdd('key', 2.5, 'val2');
$valkey->zAdd('key', 4.5, 'val4');
$valkey->zMscore('key', 'val2', 'val3', 'val4'); /* [2.5, false, 4.5] */Description: Can pop the highest or lowest scoring members from one ZSETs. There are two commands (ZPOPMIN and ZPOPMAX for popping the lowest and highest scoring elements respectively.)
$valkey->zPopMin(string $key, int $count): array
$valkey->zPopMax(string $key, int $count): array
$valkey->zPopMin(string $key, int $count): array
$valkey->zPopMax(string $key, int $count): arrayARRAY: Either an array with the key member and score of the highest or lowest element or an empty array if there is no element available.
/* Pop the *lowest* scoring member from set `zs1`. */
$valkey->zPopMin('zs1', 5);
/* Pop the *highest* scoring member from set `zs1`. */
$valkey->zPopMax('zs1', 5);Description: Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end].
Start and stop are interpreted as zero-based indices:
0 the first element, 1 the second ...
-1 the last element, -2 the penultimate ...
key
start: long
end: long
withscores: bool = false
Array containing the values in specified range.
$valkey->zAdd('key1', 0, 'val0');
$valkey->zAdd('key1', 2, 'val2');
$valkey->zAdd('key1', 10, 'val10');
$valkey->zRange('key1', 0, -1); /* ['val0', 'val2', 'val10'] */
// with scores
$valkey->zRange('key1', 0, -1, true); /* ['val0' => 0, 'val2' => 2, 'val10' => 10] */Description: Returns the elements of the sorted set stored at the specified key which have scores in the range [start,end]. Adding a parenthesis before start or end excludes it from the range. +inf and -inf are also valid limits. zRevRangeByScore returns the same items in reverse order, when the start and end parameters are swapped.
key
start: string
end: string
options: array
Two options are available: withscores => TRUE, and limit => [$offset, $count]
Array containing the values in specified range.
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 2, 'val2');
$valkey->zAdd('key', 10, 'val10');
$valkey->zRangeByScore('key', 0, 3); /* ['val0', 'val2'] */
$valkey->zRangeByScore('key', 0, 3, ['withscores' => TRUE]); /* ['val0' => 0, 'val2' => 2] */
$valkey->zRangeByScore('key', 0, 3, ['limit' => [1, 1]]); /* ['val2'] */
$valkey->zRangeByScore('key', 0, 3, ['withscores' => TRUE, 'limit' => [1, 1]]); /* ['val2' => 2] */
$valkey->zRangeByScore('key', '-inf', '+inf', ['withscores' => TRUE]); /* ['val0' => 0, 'val2' => 2, 'val10' => 10] */Description: Returns a lexicographical range of members in a sorted set, assuming the members have the same score. The min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values '-' (negative inf) or '+' (positive inf). The command must be called with either three or five arguments or will return FALSE.
key: The ZSET you wish to run against
min: The minimum alphanumeric value you wish to get
max: The maximum alphanumeric value you wish to get
offset: Optional argument if you wish to start somewhere other than the first element.
limit: Optional argument if you wish to limit the number of elements returned.
Array containing the values in the specified range.
foreach(['a','b','c','d','e','f','g'] as $c)
$valkey->zAdd('key',0,$c);
$valkey->zRangeByLex('key','-','[c') /* ['a','b','c']; */
$valkey->zRangeByLex('key','-','(c') /* ['a','b'] */
$valkey->zRangeByLex('key','-','[c',1,2) /* ['b','c'] */Description: Returns the rank of a given member in the specified sorted set, starting at 0 for the item with the smallest score. zRevRank starts at 0 for the item with the largest score.
key
member
Long, the item's rank.
$valkey->del('z');
$valkey->zAdd('key', 1, 'one');
$valkey->zAdd('key', 2, 'two');
$valkey->zRank('key', 'one'); /* 0 */
$valkey->zRank('key', 'two'); /* 1 */
$valkey->zRevRank('key', 'one'); /* 1 */
$valkey->zRevRank('key', 'two'); /* 0 */Description: Delete one or more members from a sorted set.
$valkey->zRem($key, $member [, $member ...]);LONG: The number of members deleted.
$valkey->zAdd('key', 0, 'val0', 1, 'val1', 2, 'val2');
$valkey->zRem('key', 'val0', 'val1', 'val2'); // Returns: 3Description: Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].
key
start: LONG
end: LONG
LONG The number of values deleted from the sorted set
$valkey->zAdd('key', 1, 'one');
$valkey->zAdd('key', 2, 'two');
$valkey->zAdd('key', 3, 'three');
$valkey->zRemRangeByRank('key', 0, 1); /* 2 */
$valkey->zRange('key', 0, -1, ['withscores' => TRUE]); /* ['three' => 3] */Description: Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].
key
start: double or "+inf" or "-inf" string
end: double or "+inf" or "-inf" string
LONG The number of values deleted from the sorted set
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 2, 'val2');
$valkey->zAdd('key', 10, 'val10');
$valkey->zRemRangeByScore('key', 0, 3); /* 2 */Description: Returns the elements of the sorted set stored at the specified key in the range [start, end] in reverse order. start and stop are interpreted as zero-based indices:
0 the first element, 1 the second ...
-1 the last element, -2 the penultimate ...
key
start: long
end: long
withscores: bool = false
Array containing the values in specified range.
$valkey->zAdd('key', 0, 'val0');
$valkey->zAdd('key', 2, 'val2');
$valkey->zAdd('key', 10, 'val10');
$valkey->zRevRange('key', 0, -1); /* ['val10', 'val2', 'val0'] */
// with scores
$valkey->zRevRange('key', 0, -1, true); /* ['val10' => 10, 'val2' => 2, 'val0' => 0] */Description: Returns the score of a given member in the specified sorted set.
key
member
Double or FALSE when the value is not found
$valkey->zAdd('key', 2.5, 'val2');
$valkey->zScore('key', 'val2'); /* 2.5 */Description: Creates an union of sorted sets given in first argument. The result of the union will be returned.
The second optional argument defines weights to apply to the sorted sets in input. In this case, the weights will be multiplied by the score of each element in the sorted set before applying the aggregation.
The third argument is a set of options. It can define the AGGREGATE option which specify how the results of the intersection are aggregated. It can also define WITHSCORES so that the scores are returned as well.
arrayZSetKeys
arrayWeights
arrayOptions Two options are available: withscores => TRUE, and aggregate => $behaviour. Either "SUM", "MIN", or "MAX" defines the behaviour to use on duplicate entries during the zunion.
ARRAY The result of the union of sets.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k2', 2, 'val2');
$valkey->zAdd('k2', 3, 'val3');
$valkey->zunion(['k1', 'k2']); /* ['val0', 'val1', 'val2', 'val3'] */
/* Weighted zunion */
$valkey->zunion(['k1', 'k2'], [1, 1]); /* ['val0', 'val1', 'val2', 'val3'] */
$valkey->zunion(['k1', 'k2'], [5, 1]); /* ['val0', 'val2', 'val3', 'val1'] */Description: Creates an union of sorted sets given in second argument. The result of the union will be stored in the sorted set defined by the first argument.
The third optional argument defines weights to apply to the sorted sets in input. In this case, the weights will be multiplied by the score of each element in the sorted set before applying the aggregation.
The forth argument defines the AGGREGATE option which specify how the results of the union are aggregated.
keyOutput
arrayZSetKeys
arrayWeights
aggregateFunction Either "SUM", "MIN", or "MAX": defines the behaviour to use on duplicate entries during the zunionstore.
LONG The number of values in the new sorted set.
$valkey->del('k1');
$valkey->del('k2');
$valkey->del('k3');
$valkey->del('ko1');
$valkey->del('ko2');
$valkey->del('ko3');
$valkey->zAdd('k1', 0, 'val0');
$valkey->zAdd('k1', 1, 'val1');
$valkey->zAdd('k2', 2, 'val2');
$valkey->zAdd('k2', 3, 'val3');
$valkey->zunionstore('ko1', ['k1', 'k2']); /* 4, 'ko1' => ['val0', 'val1', 'val2', 'val3'] */
/* Weighted zunionstore */
$valkey->zunionstore('ko2', ['k1', 'k2'], [1, 1]); /* 4, 'ko2' => ['val0', 'val1', 'val2', 'val3'] */
$valkey->zunionstore('ko3', ['k1', 'k2'], [5, 1]); /* 4, 'ko3' => ['val0', 'val2', 'val3', 'val1'] */Description: Scan a sorted set for members, with optional pattern and count
key: String, the set to scan
iterator: Long (reference), initialized to NULL
pattern: String (optional), the pattern to match
count: How many keys to return per iteration (Valkey might return a different number)
Array, boolean PHPValkey will return matching keys from Valkey, or FALSE when iteration is complete
$it = NULL;
$valkey->setOption(Valkey::OPT_SCAN, Valkey::SCAN_RETRY);
while($arr_matches = $valkey->zScan('zset', $it, '*pattern*')) {
foreach($arr_matches as $str_mem => $f_score) {
echo "Key: $str_mem, Score: $f_score\n";
}
}