diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index b1dc6fbd..95f1590e 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -180,6 +180,7 @@ use Predis\Command\Redis\Container\Search\FTCURSOR; * @method $this jsonnumincrby(string $key, string $path, int $value) * @method $this jsonmerge(string $key, string $path, string $value) * @method $this jsonmget(array $keys, string $path) + * @method $this jsonmset(string ...$keyPathValue) * @method $this jsonobjkeys(string $key, string $path = '$') * @method $this jsonobjlen(string $key, string $path = '$') * @method $this jsonresp(string $key, string $path = '$') diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 3e5f579b..924db1ec 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -189,6 +189,7 @@ use Predis\Response\Status; * @method string jsonnumincrby(string $key, string $path, int $value) * @method Status jsonmerge(string $key, string $path, string $value) * @method array jsonmget(array $keys, string $path) + * @method Status jsonmset(string ...$keyPathValue) * @method array jsonobjkeys(string $key, string $path = '$') * @method array jsonobjlen(string $key, string $path = '$') * @method array jsonresp(string $key, string $path = '$') diff --git a/src/Command/Redis/Json/JSONMSET.php b/src/Command/Redis/Json/JSONMSET.php new file mode 100644 index 00000000..4fc6cd85 --- /dev/null +++ b/src/Command/Redis/Json/JSONMSET.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 + * @return void + * @requiresRedisJsonVersion >= 2.6.0 + */ + public function testSetMultipleJsonDocuments(): void + { + $redis = $this->getClient(); + + $this->assertEquals('OK', $redis->jsonmset('doc1', '$', '{"a":2}', 'doc2', '$', '{"b":3}')); + $this->assertEquals(['[{"a":2}]', '[{"b":3}]'], $redis->jsonmget(['doc1', 'doc2'], '$')); + } + + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.0 + */ + public function testThrowsExceptionOnNewValuesNotInTheRootPath(): void + { + $redis = $this->getClient(); + + $this->expectException(ServerException::class); + $this->expectExceptionMessage('ERR new objects must be created at the root'); + + $redis->jsonmset('doc1', '$', '{"a":2}', 'doc2', '$.f', '{"b":3}'); + } +}