[redis_proxy] Add support for UNWATCH #37620
Check was skipped
This check was not triggered in this CI run
Details
Request (pr/37620/main@d9f5eaf)
@dbarbosapn d9f5eaf
#37620 merge
main@5cccef9
[redis_proxy] Add support for UNWATCH
This PR adds support for the
UNWATCH
command in the Redis proxy.
Because of the lack ofUNWATCH
support, transactions are not well supported by clients such as StackExchange.Redis, since conditions requireUNWATCH
support.The Challenge
The challenge with implementingUNWATCH
in Envoy is knowing which server to send theUNWATCH
command to.
This was solved in this PR by consideringWATCH
a Transaction Command. The behavior is explained below.Expected Behavior
WATCH
as a transaction command.
MakingWATCH
a transaction command means it will be handled by the transaction handler, not the simple request handler. There, we set the transaction key in advance, without starting the transaction. This means we will have state of the key where the latestWATCH
was sent to.
UNWATCH
afterWATCH
If anUNWATCH
is sent right after aWATCH
, we send it to the server of the transaction key that was set. After that, we reset the key. Covered by test: ✅
UNWATCH
without key
Sending anUNWATCH
without previous key being set, will have a direct proxy response of+OK\r\n
. Covered by test: ✅
UNWATCH
afterMULTI
(no key)
Sending anUNWATCH
without a key but within a transaction, will also be a no-op in the proxy. But the response this time is+QUEUED\r\n
, to match Redis behavior. Covered by test: ✅
UNWATCH
with key
Sending anUNWATCH
with a transaction key set (either byWATCH
or a simple command within an active transaction) will send the command to the server of such hash key. Covered by test: ✅
MULTI
afterWATCH
SinceWATCH
now sets the transaction key in advance, in this scenario we no longer queue theMULTI
command, and we send it directly upstream, based on the key set by theWATCH
command. Covered by test: ✅
MULTI
afterUNWATCH
If anUNWATCH
is sent after aWATCH
, the transaction key is reset, and theMULTI
command is queued. This is the existing behavior in the proxy. Covered by test: ✅
Environment
Request variables
Key | Value |
---|---|
ref | e84bbc4 |
sha | d9f5eaf |
pr | 37620 |
base-sha | 5cccef9 |
actor | @dbarbosapn |
message | [redis_proxy] Add support for UNWATCH... |
started | 1734453535.08544 |
target-branch | main |
trusted | false |
Build image
Container image/s (as used in this CI run)
Key | Value |
---|---|
default | envoyproxy/envoy-build-ubuntu:246094216be818bc56f1f7f30d3c08b5209ab125 |
mobile | envoyproxy/envoy-build-ubuntu:mobile-246094216be818bc56f1f7f30d3c08b5209ab125 |
Version
Envoy version (as used in this CI run)
Key | Value |
---|---|
major | 1 |
minor | 33 |
patch | 0 |
dev | true |