ClientInterface: update watch command accepting string and string[] (#1476)

This commit is contained in:
Stephan
2025-02-13 17:39:51 +00:00
committed by GitHub
parent 549889b198
commit 355faa099f
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -334,7 +334,7 @@ use Predis\Response\Status;
* @method mixed multi()
* @method mixed unwatch()
* @method array waitaof(int $numLocal, int $numReplicas, int $timeout)
* @method mixed watch(string $key)
* @method mixed watch(string[]|string $keyOrKeys)
* @method mixed eval(string $script, int $numkeys, string ...$keyOrArg = null)
* @method mixed eval_ro(string $script, array $keys, ...$argument)
* @method mixed evalsha(string $script, int $numkeys, string ...$keyOrArg = null)
+19
View File
@@ -90,6 +90,25 @@ class WATCH_Test extends PredisCommandTestCase
$this->assertSame('hijacked', $redis1->get('foo'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.2.0
*/
public function testWatchMultipleKeysAsListAbortsTransactionOnExternalWriteOperations(): void
{
$redis1 = $this->getClient();
$redis2 = $this->getClient();
$redis1->mset('foo', 'bar', 'hoge', 'piyo');
$this->assertEquals('OK', $redis1->watch(['foo', 'hoge']));
$this->assertEquals('OK', $redis1->multi());
$this->assertEquals('QUEUED', $redis1->set('hoge', 'bar'));
$this->assertEquals('OK', $redis2->set('hoge', 'hijacked'));
$this->assertNull($redis1->exec());
$this->assertSame('hijacked', $redis1->get('hoge'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.2.0