Ivan Velichko
Ivan Velichko

Reputation: 6709

Sequential watch calls in Redis

Is this pattern legal?

$redis->watch('foo');
$var1 = $redis->get('foo');

$redis->watch('bar');
$var2 = $redis->get('bar');


$redis->multi();
$redis->mset(['foo' => 42, 'bar' => 9001]);
$redis->exec();

Or second watch call cancels first watching state?

Upvotes: 1

Views: 242

Answers (1)

Nick Bondarenko
Nick Bondarenko

Reputation: 6351

This pattern is legal. From redis documentation

WATCH can be called multiple times. Simply all the WATCH calls will have the effects to watch for changes starting from the call, up to the moment EXEC is called. You can also send any number of keys to a single WATCH call.

Upvotes: 2

Related Questions