mirror of
https://github.com/predis/predis.git
synced 2026-09-12 19:37:05 +00:00
Added new COUNT aggregator for Sorted Set commands (#1668)
* Added test coverage with new COUNT aggregator * Updated CHANGELOG.md * Changed version constraint * Fixed broken test * Marked as relay-resp3
This commit is contained in:
committed by
GitHub
parent
622f4df2b6
commit
6c3909e675
@@ -5,6 +5,7 @@
|
||||
- Added support for `GCRA` command (#1657)
|
||||
- Handle Redis Cluster `-READONLY` responses failover events (#1656)
|
||||
- Added FPHA argument for JSON.SET command (#1661)
|
||||
- Added new COUNT aggregator for Sorted Set commands (#1668)
|
||||
- Added XNACK support (#1666)
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -27,6 +27,7 @@ trait Aggregate
|
||||
'min' => 'MIN',
|
||||
'max' => 'MAX',
|
||||
'sum' => 'SUM',
|
||||
'count' => 'COUNT',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -116,6 +116,32 @@ class ZINTERSTORE_Test extends PredisCommandTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.7.2
|
||||
*/
|
||||
public function testStoresIntersectedValuesWithCountAggregate(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->zadd('test-zinterstore1', 1, 'member1', 2, 'member2', 3, 'member3');
|
||||
$redis->zadd('test-zinterstore2', 1, 'member1', 2, 'member2');
|
||||
|
||||
$actualResponse = $redis->zinterstore(
|
||||
'destination',
|
||||
['test-zinterstore1', 'test-zinterstore2'],
|
||||
[],
|
||||
'count'
|
||||
);
|
||||
|
||||
$this->assertSame(2, $actualResponse);
|
||||
$this->assertEquals(
|
||||
['member1' => '2', 'member2' => '2'],
|
||||
$redis->zrange('destination', 0, -1, ['withscores' => true])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
@@ -201,6 +227,10 @@ class ZINTERSTORE_Test extends PredisCommandTestCase
|
||||
]],
|
||||
['destination', 2, 'key1', 'key2', 'WEIGHTS', 1, 2, 'AGGREGATE', 'MIN'],
|
||||
],
|
||||
'with count aggregate' => [
|
||||
['destination', ['key1', 'key2'], [], 'count'],
|
||||
['destination', 2, 'key1', 'key2', 'AGGREGATE', 'COUNT'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -268,7 +298,7 @@ class ZINTERSTORE_Test extends PredisCommandTestCase
|
||||
['key1'],
|
||||
[],
|
||||
'wrong',
|
||||
'Aggregate argument accepts only: min, max, sum values',
|
||||
'Aggregate argument accepts only: min, max, sum, count values',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ class ZINTER_Test extends PredisCommandTestCase
|
||||
[['key1', 'key2'], [1, 2], 'min', true],
|
||||
[2, 'key1', 'key2', 'WEIGHTS', 1, 2, 'AGGREGATE', 'MIN', 'WITHSCORES'],
|
||||
],
|
||||
'with count aggregate' => [
|
||||
[['key1', 'key2'], [], 'count'],
|
||||
[2, 'key1', 'key2', 'AGGREGATE', 'COUNT'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -110,6 +114,29 @@ class ZINTER_Test extends PredisCommandTestCase
|
||||
$this->assertEquals($expectedResponse, $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-resp3
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.7.2
|
||||
*/
|
||||
public function testReturnsIntersectedValuesWithCountAggregate(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->zadd('test-zinter1', 1, 'member1', 2, 'member2', 3, 'member3');
|
||||
$redis->zadd('test-zinter2', 1, 'member1', 2, 'member2');
|
||||
|
||||
$actualResponse = $redis->zinter(
|
||||
['test-zinter1', 'test-zinter2'],
|
||||
[],
|
||||
'count',
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertSame(['member1' => '2', 'member2' => '2'], $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
@@ -226,7 +253,7 @@ class ZINTER_Test extends PredisCommandTestCase
|
||||
[],
|
||||
'wrong',
|
||||
false,
|
||||
'Aggregate argument accepts only: min, max, sum values',
|
||||
'Aggregate argument accepts only: min, max, sum, count values',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -116,6 +116,32 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.7.2
|
||||
*/
|
||||
public function testStoresUnionValuesWithCountAggregate(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->zadd('test-zunionstore1', 1, 'member1', 2, 'member2', 3, 'member3');
|
||||
$redis->zadd('test-zunionstore2', 1, 'member1', 2, 'member2');
|
||||
|
||||
$actualResponse = $redis->zunionstore(
|
||||
'destination',
|
||||
['test-zunionstore1', 'test-zunionstore2'],
|
||||
[],
|
||||
'count'
|
||||
);
|
||||
|
||||
$this->assertSame(3, $actualResponse);
|
||||
$this->assertEquals(
|
||||
['member3' => '1', 'member1' => '2', 'member2' => '2'],
|
||||
$redis->zrange('destination', 0, -1, ['withscores' => true])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
@@ -201,6 +227,10 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase
|
||||
]],
|
||||
['destination', 2, 'key1', 'key2', 'WEIGHTS', 1, 2, 'AGGREGATE', 'MIN'],
|
||||
],
|
||||
'with count aggregate' => [
|
||||
['destination', ['key1', 'key2'], [], 'count'],
|
||||
['destination', 2, 'key1', 'key2', 'AGGREGATE', 'COUNT'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -268,7 +298,7 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase
|
||||
['key1'],
|
||||
[],
|
||||
'wrong',
|
||||
'Aggregate argument accepts only: min, max, sum values',
|
||||
'Aggregate argument accepts only: min, max, sum, count values',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -84,6 +84,29 @@ class ZUNION_Test extends PredisCommandTestCase
|
||||
$this->assertEquals($expectedResponse, $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-resp3
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.7.2
|
||||
*/
|
||||
public function testReturnsUnionValuesWithCountAggregate(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$redis->zadd('test-zunion1', 1, 'member1', 2, 'member2', 3, 'member3');
|
||||
$redis->zadd('test-zunion2', 1, 'member1', 2, 'member2');
|
||||
|
||||
$actualResponse = $redis->zunion(
|
||||
['test-zunion1', 'test-zunion2'],
|
||||
[],
|
||||
'count',
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertSame(['member3' => '1', 'member1' => '2', 'member2' => '2'], $actualResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @return void
|
||||
@@ -163,6 +186,10 @@ class ZUNION_Test extends PredisCommandTestCase
|
||||
[['key1', 'key2'], [1, 2], 'min', true],
|
||||
[2, 'key1', 'key2', 'WEIGHTS', 1, 2, 'AGGREGATE', 'MIN', 'WITHSCORES'],
|
||||
],
|
||||
'with count aggregate' => [
|
||||
[['key1', 'key2'], [], 'count'],
|
||||
[2, 'key1', 'key2', 'AGGREGATE', 'COUNT'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -226,7 +253,7 @@ class ZUNION_Test extends PredisCommandTestCase
|
||||
[],
|
||||
'wrong',
|
||||
false,
|
||||
'Aggregate argument accepts only: min, max, sum values',
|
||||
'Aggregate argument accepts only: min, max, sum, count values',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class AggregateTest extends PredisTestCase
|
||||
public function testThrowsExceptionOnUnexpectedValueGiven(array $actualArguments): void
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage('Aggregate argument accepts only: min, max, sum values');
|
||||
$this->expectExceptionMessage('Aggregate argument accepts only: min, max, sum, count values');
|
||||
|
||||
$this->testClass->setArguments($actualArguments);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user