Skip to content

Commit

Permalink
chore: add named argument sorted-set example (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta authored Oct 25, 2024
1 parent 1906221 commit 96412ba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/sorted-set-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ function printBanner(string $message, LoggerInterface $logger): void
exit(1);
}

// fetch sorted set by score (0 to 2) in descending order
$logger->info("Fetching sorted set $SET_NAME by score in descending order\n");
$response = $client->sortedSetFetchByScore($CACHE_NAME, $SET_NAME, minScore: 0, maxScore: 2, order: SORT_DESC);
if ($response->asHit()) {
$logger->info("SUCCESS: Sorted set $SET_NAME: " . implode(', ', $response->asHit()->valuesArray()) . "\n");
} elseif ($err = $response->asMiss()) {
$logger->info("Sorted set $SET_NAME not found\n");
} elseif ($err = $response->asError()) {
$logger->info("Error fetching sorted set: {$err->message()}\n");
exit(1);
}

// increment score of element in sorted set
$logger->info("Incrementing score of element 'one' in sorted set $SET_NAME by 1\n");
$response = $client->sortedSetIncrementScore($CACHE_NAME, $SET_NAME, "one", 1);
Expand Down

0 comments on commit 96412ba

Please sign in to comment.