diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index a6e0baef..bccb549a 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -112,6 +112,7 @@ use Predis\Command\CommandInterface; * @method $this jsonmget(array $keys, string $path) * @method $this jsonobjkeys(string $key, string $path = '$') * @method $this jsonobjlen(string $key, string $path = '$') + * @method $this jsonresp(string $key, string $path = '$') * @method $this jsonset(string $key, string $path, string $value, ?string $subcommand = null) * @method $this jsonstrappend(string $key, string $path, string $value) * @method $this jsonstrlen(string $key, string $path = '$') diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 15aa779c..a3cda275 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -121,6 +121,7 @@ use Predis\Response\Status; * @method array jsonmget(array $keys, string $path) * @method array jsonobjkeys(string $key, string $path = '$') * @method array jsonobjlen(string $key, string $path = '$') + * @method array jsonresp(string $key, string $path = '$') * @method string jsonset(string $key, string $path, string $value, ?string $subcommand = null) * @method array jsonstrappend(string $key, string $path, string $value) * @method array jsonstrlen(string $key, string $path = '$') diff --git a/src/Command/Redis/Json/JSONRESP.php b/src/Command/Redis/Json/JSONRESP.php new file mode 100644 index 00000000..6fbfa6f0 --- /dev/null +++ b/src/Command/Redis/Json/JSONRESP.php @@ -0,0 +1,28 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @dataProvider jsonProvider + * @param array $jsonArguments + * @param string $key + * @param string $path + * @param array $expectedResponse + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnRespValueFromGivenJson( + array $jsonArguments, + string $key, + string $path, + array $expectedResponse + ): void { + $redis = $this->getClient(); + + $redis->jsonset(...$jsonArguments); + + $this->assertEquals($expectedResponse, $redis->jsonresp($key, $path)); + } + + public function jsonProvider(): array + { + return [ + 'with string value' => [ + ['key', '$', '{"key1":"value1"}'], + 'key', + '$.key1', + ['value1'], + ], + 'with numeric value' => [ + ['key', '$', '{"key1":1}'], + 'key', + '$.key1', + [1], + ], + 'with array value' => [ + ['key', '$', '{"key1":[1,2,3]}'], + 'key', + '$.key1', + [[new Status('['), 1, 2, 3]], + ], + 'with json object value' => [ + ['key', '$', '{"key1":{"key2":"value2"}}'], + 'key', + '$.key1', + [[new Status('{'), 'key2', 'value2']], + ], + 'with boolean value' => [ + ['key', '$', '{"key1":true}'], + 'key', + '$.key1', + ['true'], + ], + 'with null value' => [ + ['key', '$', '{"key1":null}'], + 'key', + '$.key1', + [null], + ], + ]; + } +}