Added support for JSON.MSET command (#1307)

This commit is contained in:
Vladyslav Vildanov
2023-06-08 17:35:04 +03:00
committed by GitHub
parent df83c94bb3
commit c57a6744bb
4 changed files with 115 additions and 0 deletions
+1
View File
@@ -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 = '$')
+1
View File
@@ -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 = '$')
+28
View File
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis\Json;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/json.mset/
*
* Set or update one or more JSON values according to the specified key-path-value triplets.
*/
class JSONMSET extends RedisCommand
{
public function getId()
{
return 'JSON.MSET';
}
}
@@ -0,0 +1,85 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis\Json;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
class JSONMSET_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return JSONMSET::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'JSONMSET';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$arguments = ['key', '$..', 'value', 'key1', '$', 'value1'];
$expected = ['key', '$..', 'value', 'key1', '$', 'value1'];
$command = $this->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}');
}
}