diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index f8095bc9..db814191 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -117,6 +117,7 @@ use Predis\Command\CommandInterface; * @method $this jsonstrappend(string $key, string $path, string $value) * @method $this jsonstrlen(string $key, string $path = '$') * @method $this jsontoggle(string $key, string $path) + * @method $this jsontype(string $key, string $path = '$') * @method $this blmove(string $source, string $destination, string $where, string $to, int $timeout) * @method $this blpop(array|string $keys, $timeout) * @method $this brpop(array|string $keys, $timeout) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 92ae5191..5b213cb0 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -126,6 +126,7 @@ use Predis\Response\Status; * @method array jsonstrappend(string $key, string $path, string $value) * @method array jsonstrlen(string $key, string $path = '$') * @method array jsontoggle(string $key, string $path) + * @method array jsontype(string $key, string $path = '$') * @method string blmove(string $source, string $destination, string $where, string $to, int $timeout) * @method array|null blpop(array|string $keys, int|float $timeout) * @method array|null brpop(array|string $keys, int|float $timeout) diff --git a/src/Command/Redis/Json/JSONTYPE.php b/src/Command/Redis/Json/JSONTYPE.php new file mode 100644 index 00000000..83a69d05 --- /dev/null +++ b/src/Command/Redis/Json/JSONTYPE.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 $expectedType + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsJsonValueType( + array $jsonArguments, + string $key, + string $path, + array $expectedType + ): void { + $redis = $this->getClient(); + + $redis->jsonset(...$jsonArguments); + + $this->assertSame($expectedType, $redis->jsontype($key, $path)); + } + + public function jsonProvider(): array + { + return [ + 'with string value' => [ + ['key', '$', '{"key1":"value1"}'], + 'key', + '$.key1', + ['string'], + ], + 'with numeric value' => [ + ['key', '$', '{"key1":1}'], + 'key', + '$.key1', + ['integer'], + ], + 'with array value' => [ + ['key', '$', '{"key1":[1,2,3]}'], + 'key', + '$.key1', + ['array'], + ], + 'with json object value' => [ + ['key', '$', '{"key1":{"key2":"value2"}}'], + 'key', + '$.key1', + ['object'], + ], + 'with boolean value' => [ + ['key', '$', '{"key1":true}'], + 'key', + '$.key1', + ['boolean'], + ], + 'with null value' => [ + ['key', '$', '{"key1":null}'], + 'key', + '$.key1', + ['null'], + ], + ]; + } +}