Skip to content

Commit

Permalink
Rename RangeBoundary to ScoreBoundary
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 18, 2023
1 parent ed5555e commit a3e8dc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/RedisSortedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getRangeWithScores(int $start, int $end, ?RangeOptions $options
/**
* @return Promise<list<string>>
*/
public function getRangeByScore(RangeBoundary $start, RangeBoundary $end, ?RangeOptions $options = null): Promise
public function getRangeByScore(ScoreBoundary $start, ScoreBoundary $end, ?RangeOptions $options = null): Promise
{
$query = ['zrange', $this->key, $start->toQuery(), $end->toQuery(), 'BYSCORE'];
if ($options !== null) {
Expand All @@ -78,7 +78,7 @@ public function getRangeByScore(RangeBoundary $start, RangeBoundary $end, ?Range
/**
* @return Promise<array<string, float>>
*/
public function getRangeByScoreWithScores(RangeBoundary $start, RangeBoundary $end, ?RangeOptions $options = null): Promise
public function getRangeByScoreWithScores(ScoreBoundary $start, ScoreBoundary $end, ?RangeOptions $options = null): Promise
{
$query = ['zrange', $this->key, $start->toQuery(), $end->toQuery(), 'BYSCORE', 'WITHSCORES'];
if ($options !== null) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public function removeRankRange(int $start, int $stop): Promise
/**
* @return Promise<int>
*/
public function removeRangeByScore(RangeBoundary $min, RangeBoundary $max): Promise
public function removeRangeByScore(ScoreBoundary $min, ScoreBoundary $max): Promise
{
return $this->queryExecutor->execute(['zremrangebyscore', $this->key, $min->toQuery(), $max->toQuery()]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RangeBoundary.php → src/ScoreBoundary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amp\Redis;

final class RangeBoundary
final class ScoreBoundary
{
public static function exclusive(float $value): self
{
Expand Down
18 changes: 9 additions & 9 deletions test/RedisSortedSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public function testScoredSet(): \Generator
$this->assertSame(['foo', 'bar'], yield $set->getRange(0, 1));
$this->assertSame(['bar'], yield $set->getRange(1, 2));

$this->assertSame(['foo'], yield $set->getRangeByScore(RangeBoundary::inclusive(1), RangeBoundary::inclusive(2)));
$this->assertSame(['foo' => 1.0], yield $set->getRangeByScoreWithScores(RangeBoundary::inclusive(1), RangeBoundary::exclusive(3)));
$this->assertSame(['foo', 'bar'], yield $set->getRangeByScore(RangeBoundary::negativeInfinity(), RangeBoundary::inclusive(3)));
$this->assertSame(['foo'], yield $set->getRangeByScore(RangeBoundary::inclusive(1), RangeBoundary::exclusive(3)));
$this->assertSame(['foo'], yield $set->getRangeByScore(ScoreBoundary::inclusive(1), ScoreBoundary::inclusive(2)));
$this->assertSame(['foo' => 1.0], yield $set->getRangeByScoreWithScores(ScoreBoundary::inclusive(1), ScoreBoundary::exclusive(3)));
$this->assertSame(['foo', 'bar'], yield $set->getRangeByScore(ScoreBoundary::negativeInfinity(), ScoreBoundary::inclusive(3)));
$this->assertSame(['foo'], yield $set->getRangeByScore(ScoreBoundary::inclusive(1), ScoreBoundary::exclusive(3)));


$this->assertSame(['bar', 'foo'], yield $set->getRange(0, 1, (new RangeOptions())->withReverseOrder()));
$this->assertSame(['bar' => 3.0], yield $set->getRangeWithScores(0, 0, (new RangeOptions())->withReverseOrder()));
$this->assertSame(['foo'], yield $set->getRange(1, 2, (new RangeOptions())->withReverseOrder()));

$this->assertSame(['foo'], yield $set->getRangeByScore(RangeBoundary::inclusive(2), RangeBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));
$this->assertSame(['bar' => 3.0, 'foo' => 1.0], yield $set->getRangeByScoreWithScores(RangeBoundary::positiveInfinity(), RangeBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));
$this->assertSame(['bar', 'foo'], yield $set->getRangeByScore(RangeBoundary::inclusive(3), RangeBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));
$this->assertSame(['foo'], yield $set->getRangeByScore(ScoreBoundary::inclusive(2), ScoreBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));
$this->assertSame(['bar' => 3.0, 'foo' => 1.0], yield $set->getRangeByScoreWithScores(ScoreBoundary::positiveInfinity(), ScoreBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));
$this->assertSame(['bar', 'foo'], yield $set->getRangeByScore(ScoreBoundary::inclusive(3), ScoreBoundary::inclusive(1), (new RangeOptions())->withReverseOrder()));

$this->assertSame(0, yield $set->getRank('foo'));
$this->assertSame(1, yield $set->getRank('bar'));
Expand All @@ -67,8 +67,8 @@ public function testRemove(): \Generator
'baz' => 3.3,
]));

yield $set->removeRangeByScore(RangeBoundary::exclusive(2.2), RangeBoundary::positiveInfinity());
$this->assertSame(['foo', 'bar'], yield $set->getRangeByScore(RangeBoundary::negativeInfinity(), RangeBoundary::positiveInfinity()));
yield $set->removeRangeByScore(ScoreBoundary::exclusive(2.2), ScoreBoundary::positiveInfinity());
$this->assertSame(['foo', 'bar'], yield $set->getRangeByScore(ScoreBoundary::negativeInfinity(), ScoreBoundary::positiveInfinity()));
}

public function testLexSet(): \Generator
Expand Down

0 comments on commit a3e8dc3

Please sign in to comment.