From 702897c5d69ebbeba533ebe4955823ba228c9d38 Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Fri, 18 Oct 2024 17:51:45 -0700 Subject: [PATCH] chore: make order in the sorted set functions more explicit (#235) 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. --- src/Cache/CacheClient.php | 12 ++++++++---- src/Cache/Internal/ScsDataClient.php | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Cache/CacheClient.php b/src/Cache/CacheClient.php index de20dcb..cda6b23 100644 --- a/src/Cache/CacheClient.php +++ b/src/Cache/CacheClient.php @@ -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 A waitable future which will * provide the result of the sorted set fetch operation upon a blocking call to wait:
* $response = $responseFuture->wait();
@@ -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:
* * SortedSetFetchHit
@@ -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 @@ -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 diff --git a/src/Cache/Internal/ScsDataClient.php b/src/Cache/Internal/ScsDataClient.php index 69e20d4..5301908 100644 --- a/src/Cache/Internal/ScsDataClient.php +++ b/src/Cache/Internal/ScsDataClient.php @@ -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(