Is there a way to atomically delete a key if the string value stored under this key equals some parameter string? This is a very useful pattern. Please consider this a feature request if there is no way of doing it. Maybe something like DELIF mykey EQ myvalue

Comment From: oranagra

Why is this very useful? Did you see such a feature anywhere else?

Comment From: chenyang8094

@compfy-dot-com Currently I think you can achieve your purpose with a tiny lua script or try this module.

@oranagra I've seen several similar questions and I think they're all talking about CAS (compare and set)/CAD (compare and delete), do we have any plans to support this(they are indeed more useful when implementing things like distributed locks.)?

Comment From: oranagra

@chenyang8094 this sounds reasonable to me, but i'm not aware of any previous discussions around this and i imagine there were. maybe @itamarhaber can share something on the history of such requests and discussions?

Comment From: compfy-dot-com

@chenyang8094 @oranagra - I am implementing a "remote" lock and I indeed use both CAS (compare and set) and CAD (compare and delete) in this context.

Comment From: compfy-dot-com

Hands-on example: For a key-value pair: Key is the ID of the lock or resource, Value is the ID of the client session placing the lock. CAD is used for allowing clients to delete only their own locks.

Comment From: oranagra

so would adding CAS and CAD solve your problem (instead of the request in the title)? have you considered a tiny Lua script?

Comment From: enjoy-binbin

they are indeed more useful when implementing things like distributed locks

yes, i also agree. the compromise method used now is lua script, it wll be nice if we support it i can recall this CAS PR: https://github.com/redis/redis/pull/8361 (there are more other related links)

Comment From: compfy-dot-com

so would adding CAS and CAD solve your problem (instead of the request in the title)? have you considered a tiny Lua script?

@oranagra Yes, and yes. Thanks. And I agree with others that CAS/CAD is a useful functionality.

Comment From: oranagra

ok, so closing this one, as we track these features in the other issue