Skip to content

[NEW] The ability to check the optimistic lock before starting a transaction #2713

@bozaro

Description

@bozaro

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions