5

Processes A and B both operate on a Redis resource R.

These processes may be executed in parallel, and I need both processes to be certain of the value of R at the moment they change it.

I'm therefore using Redis transactions with the WATCH command. From the docs: "we are asking Redis to perform the transaction only if no other client modified any of the WATCHed keys. Otherwise the transaction is not entered at all."

To retry in case of failure, the suggested way is looping the Watch/Multi-exec loop until it succeeds. However, I'm worried that both A and B might starting looping indefinitely (i.e.: livelock).

It this something to be worried about? Better yet, what to do about it? Would setting a random timeout on the retry solve the issue?

Geert-Jan
  • 16,760
  • 10
  • 68
  • 121

1 Answers1

5

No need to worry because only A or B will succeed with their EXEC and change R (Redis is [mostly] single threaded). The one that fails will need to retry the transaction with the new R value.

Itamar Haber
  • 39,899
  • 5
  • 67
  • 94