Skip to content

Commit

Permalink
chore: make order in the sorted set functions more explicit (#235)
Browse files Browse the repository at this point in the history
change the order argument in the sorted set functions to explicitly take
SORT_ASC and SORT_DESC, and treat other values as ascending. This
replaces the previous logic where SORT_DESC or lower was descending, and
SORT_ASC or higher was ascending. Using built-in constants in a
comparison was confusing.
  • Loading branch information
nand4011 authored Oct 19, 2024
1 parent 7b4ff9e commit 702897c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/Cache/CacheClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,8 @@ public function sortedSetIncrementScore(string $cacheName, string $sortedSetName
* This rank is exclusive, i.e. the element at this rank will not be fetched.
* Defaults to null, which fetches up until and including the last element.
* @param ?int $order The order to fetch the elements in. Defaults to Ascending.
* Will be treated as ascending if SORT_ASC or higher is supplied, and descending if SORT_DESC or lower is supplied.
* Use SORT_ASC for ascending order, or SORT_DESC for descending order.
* Any other values will be treated as ascending
* @return ResponseFuture<SortedSetFetchResponse> A waitable future which will
* provide the result of the sorted set fetch operation upon a blocking call to wait:<br />
* <code>$response = $responseFuture->wait();</code><br />
Expand Down Expand Up @@ -1938,7 +1939,8 @@ public function sortedSetFetchByRankAsync(string $cacheName, string $sortedSetNa
* This rank is exclusive, i.e. the element at this rank will not be fetched.
* Defaults to null, which fetches up until and including the last element.
* @param ?int $order The order to fetch the elements in. Defaults to Ascending.
* Will be treated as ascending if SORT_ASC or higher is supplied, and descending if SORT_DESC or lower is supplied.
* Use SORT_ASC for ascending order, or SORT_DESC for descending order.
* Any other values will be treated as ascending
* @return SortedSetFetchResponse Represents the result of the sorted set fetch operation.
* This result is resolved to a type-safe object of one of the following types:<br>
* * SortedSetFetchHit<br>
Expand Down Expand Up @@ -1968,7 +1970,8 @@ public function sortedSetFetchByRank(string $cacheName, string $sortedSetName, ?
* @param ?float $maxScore The maximum score (inclusive) of the
* elements to fetch. Defaults to positive infinity.
* @param ?int $order The order to fetch the elements in. Defaults to Ascending.
* Will be treated as ascending if SORT_ASC or higher is supplied, and descending if SORT_DESC or lower is supplied.
* Use SORT_ASC for ascending order, or SORT_DESC for descending order.
* Any other values will be treated as ascending
* @param ?int $offset The number of elements to skip before
* returning the first element. Defaults to 0. Note: this is not the rank of
* the first element to return, but the number of elements of the result set
Expand Down Expand Up @@ -2011,7 +2014,8 @@ public function sortedSetFetchByScoreAsync(string $cacheName, string $sortedSetN
* @param ?float $maxScore The maximum score (inclusive) of the
* elements to fetch. Defaults to positive infinity.
* @param ?int $order The order to fetch the elements in. Defaults to Ascending.
* Will be treated as ascending if SORT_ASC or higher is supplied, and descending if SORT_DESC or lower is supplied.
* Use SORT_ASC for ascending order, or SORT_DESC for descending order.
* Any other values will be treated as ascending
* @param ?int $offset The number of elements to skip before
* returning the first element. Defaults to 0. Note: this is not the rank of
* the first element to return, but the number of elements of the result set
Expand Down
6 changes: 3 additions & 3 deletions src/Cache/Internal/ScsDataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,10 @@ public function sortedSetFetchByRank(string $cacheName, string $sortedSetName, ?
}
$sortedSetFetchRequest->setByIndex($byIndex);

if (is_null($order) || $order >= SORT_ASC) {
$sortedSetFetchRequest->setOrder(_SortedSetFetchRequest\Order::ASCENDING);
} else {
if ($order == SORT_DESC) {
$sortedSetFetchRequest->setOrder(_SortedSetFetchRequest\Order::DESCENDING);
} else {
$sortedSetFetchRequest->setOrder(_SortedSetFetchRequest\Order::ASCENDING);
}

$call = $this->grpcManager->client->SortedSetFetch(
Expand Down

0 comments on commit 702897c

Please sign in to comment.