mirror of
https://github.com/predis/predis.git
synced 2026-08-30 20:21:31 +00:00
Improve Relay compatibility (#1597)
This commit is contained in:
committed by
GitHub
parent
fd1a0fc278
commit
da7b1cedb7
+4
-1
@@ -3,9 +3,12 @@
|
||||
## Unreleased
|
||||
### Added
|
||||
- Added cluster support for `XADD`, `XDEL` and `XRANGE` (#1587)
|
||||
- Added prefixable interface for HEXPIRE, HEXPIRETIME (#1592)
|
||||
- Added prefixable interface for `HEXPIRE` and `HEXPIRETIME` (#1592)
|
||||
|
||||
### Changed
|
||||
- Refactor pipeline data writing depends on connection type (#1586)
|
||||
- Improved compatiblity with Relay (#1597)
|
||||
|
||||
### Maintenance
|
||||
- Added testing with 8.4-M01 (#1593)
|
||||
|
||||
|
||||
@@ -32,9 +32,23 @@ class COMMAND extends BaseCommand
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
// Relay (RESP3) uses maps and it might be good
|
||||
// to make the return value a breaking change
|
||||
if (!is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
if ($data === array_values($data)) {
|
||||
return array_map(function ($item) {
|
||||
return $this->parseResponse($item);
|
||||
}, $data);
|
||||
}
|
||||
|
||||
// Relay
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$result[] = $key;
|
||||
$result[] = $this->parseResponse($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +127,26 @@ class FUNCTIONS extends RedisCommand
|
||||
|
||||
parent::setArguments($processedArguments);
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ($data === array_values($data)) {
|
||||
return array_map(function ($item) {
|
||||
return $this->parseResponse($item);
|
||||
}, $data);
|
||||
}
|
||||
|
||||
// Relay
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$result[] = $key;
|
||||
$result[] = $this->parseResponse($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,20 @@ class FTCONFIG extends RedisCommand
|
||||
{
|
||||
return 'FT.CONFIG';
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (!is_array($data) || $data === array_values($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Relay
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$group = [$key, $value];
|
||||
$result[] = $group;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,11 @@ class VINFO extends RedisCommand
|
||||
public function parseResponse($data): ?array
|
||||
{
|
||||
if (!is_null($data)) {
|
||||
return CommandUtility::arrayToDictionary($data);
|
||||
if ($data === array_values($data)) {
|
||||
return CommandUtility::arrayToDictionary($data);
|
||||
} else {
|
||||
return $data; // Relay
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -84,9 +84,11 @@ class VSIM extends RedisCommand
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if ($this->withScores) {
|
||||
$data = CommandUtility::arrayToDictionary($data, function ($key, $value) {
|
||||
return [$key, (float) $value];
|
||||
});
|
||||
if ($data === array_values($data)) {
|
||||
$data = CommandUtility::arrayToDictionary($data, function ($key, $value) {
|
||||
return [$key, (float) $value];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -58,7 +58,11 @@ class XINFO extends RedisCommand
|
||||
|
||||
private function parseStreamResponse($data): array
|
||||
{
|
||||
$result = CommandUtility::arrayToDictionary($data, null, false);
|
||||
if ($data === array_values($data)) {
|
||||
$result = CommandUtility::arrayToDictionary($data, null, false);
|
||||
} else {
|
||||
$result = $data; // Relay
|
||||
}
|
||||
|
||||
if (isset($result['entries'])) {
|
||||
$result['entries'] = $this->parseDict($result['entries']);
|
||||
@@ -66,10 +70,16 @@ class XINFO extends RedisCommand
|
||||
|
||||
if (isset($result['groups']) && is_array($result['groups'])) {
|
||||
$result['groups'] = array_map(static function ($group) {
|
||||
$group = CommandUtility::arrayToDictionary($group, null, false);
|
||||
if ($group === array_values($group)) {
|
||||
$group = CommandUtility::arrayToDictionary($group, null, false);
|
||||
}
|
||||
if (isset($group['consumers'])) {
|
||||
$group['consumers'] = array_map(static function ($consumer) {
|
||||
return CommandUtility::arrayToDictionary($consumer, null, false);
|
||||
if ($consumer === array_values($consumer)) {
|
||||
$consumer = CommandUtility::arrayToDictionary($consumer, null, false);
|
||||
}
|
||||
|
||||
return $consumer;
|
||||
}, $group['consumers']);
|
||||
}
|
||||
|
||||
@@ -92,6 +102,10 @@ class XINFO extends RedisCommand
|
||||
|
||||
private function parseDict($data): array
|
||||
{
|
||||
if ($data !== array_values($data)) {
|
||||
return $data; // Relay
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
for ($i = 0, $iMax = count($data); $i < $iMax; $i++) {
|
||||
|
||||
@@ -50,6 +50,10 @@ class XREAD extends RedisCommand
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($data !== array_values($data)) {
|
||||
return $data; // Relay
|
||||
}
|
||||
|
||||
$processedData = [];
|
||||
|
||||
foreach ($data as $stream) {
|
||||
|
||||
@@ -42,4 +42,20 @@ class XREADGROUP extends RedisCommand
|
||||
|
||||
parent::setArguments(array_merge($processedArguments, $keyOrIds));
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (!is_array($data) || $data === array_values($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Relay
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$group = [$key, $value];
|
||||
$result[] = $group;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,6 @@ class COMMAND_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @group relay-fixme
|
||||
* @requiresRedisVersion >= 2.8.13
|
||||
*
|
||||
* Relay uses RESP3 maps, the `Predis\Command\Redis\COMMAND` needs a converter.
|
||||
|
||||
@@ -173,7 +173,6 @@ class CONFIG_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @requiresRedisVersion >= 7.9.0
|
||||
*/
|
||||
public function testOverrideDefaultDialectWithConfigCommand()
|
||||
|
||||
@@ -327,7 +327,6 @@ class FUNCTIONS_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.0.0
|
||||
*/
|
||||
@@ -354,7 +353,6 @@ class FUNCTIONS_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.0.0
|
||||
*/
|
||||
|
||||
@@ -54,7 +54,6 @@ class HGETDEL_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.0.0
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,6 @@ class VSIM_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 8.0.0
|
||||
*/
|
||||
|
||||
@@ -86,7 +86,6 @@ class XINFO_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 6.2.0
|
||||
*/
|
||||
@@ -110,7 +109,6 @@ class XINFO_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.0.0
|
||||
*/
|
||||
@@ -147,7 +145,6 @@ class XINFO_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.0.0
|
||||
*/
|
||||
@@ -180,7 +177,6 @@ class XINFO_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.2.0
|
||||
*/
|
||||
@@ -280,7 +276,6 @@ class XINFO_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.0.0
|
||||
*/
|
||||
|
||||
@@ -90,7 +90,6 @@ class XREADGROUP_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 5.0.0
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,6 @@ class XREAD_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 5.0.0
|
||||
*/
|
||||
@@ -110,7 +109,6 @@ class XREAD_Test extends PredisCommandTestCase
|
||||
/**
|
||||
* @group medium
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 5.0.0
|
||||
*/
|
||||
@@ -137,7 +135,6 @@ class XREAD_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @return void
|
||||
* @requiresRedisVersion >= 7.4.0
|
||||
*/
|
||||
@@ -167,7 +164,6 @@ class XREAD_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @requiresRedisVersion >= 5.0.0
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -88,7 +88,6 @@ class XSETID_Test extends PredisCommandTestCase
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @requiresRedisVersion >= 5.0.0
|
||||
*/
|
||||
public function testSetIdExtended(): void
|
||||
|
||||
Reference in New Issue
Block a user