-
Notifications
You must be signed in to change notification settings - Fork 928
Description
The problem/use-case that the feature addresses
As far as I know, there are currently two options for implementing optimistic locks for non-trivial changes: WATCH/MULTI/EXEC
and LUA.
LUA functions look like a rather expensive solution in terms of CPU.
WATCH
is actually incompatible with clients that use pipelining instead of a connection pool: a round trip is required between WATCH
and MULTI
to make decisions on the client side.
Description of the feature
Instead of WATCH
, make it possible to explicitly specify the version
condition in the optimistic lock for MULTI
.
For example, instead of:
WATCH mykey
val = GET mykey
val = val + 1
MULTI
SET mykey $val
EXEC
Make a construction of the form:
old = GET mykey
new = old + 1
MULTI CHECK mykey EQ $old
SET mykey $new
EXEC
Alternatives you've considered
For trivial cases, it is possible to use SET+IFEQ/NX/XX
/INCR
/etc, but if you need to change several keys or HSET
, then optimistic locking can only be done using LUA.
Additional information
There has already been a similar discussion in PR: