Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in WATCH command between Redis and redis-py #3167

Open
mdczaplicki opened this issue Feb 29, 2024 · 0 comments
Open

Inconsistency in WATCH command between Redis and redis-py #3167

mdczaplicki opened this issue Feb 29, 2024 · 0 comments

Comments

@mdczaplicki
Copy link
Contributor

Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!

Version: What redis-py and what redis version is the issue happening on?
redis-py: 5.0.0
redis: 6.2.0
Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)
python3.11 on Ubuntu
Description: Description of your issue, stack traces from errors and code that reproduces the issue
This is how Redis works:

>> SET a 2
"OK"
>> WATCH a
"OK"
>> SET a 3
"OK"
>> MULTI
"OK"
>> SET a 4
"QUEUED"
>> EXEC
(nil)
>> GET a
"3"

As expected.
This is how redis-py works:

In [19]: await redis.set("a", 1)
    ...: await redis.watch("a")
    ...: a = await redis.get("a")
    ...: await redis.set("a", 2)
    ...: async with redis.pipeline() as pipeline:
    ...:     pipeline.multi()
    ...:     await pipeline.set("a", 3)
    ...:     await pipeline.execute()
    ...: 

In [20]: await redis.get("a")
Out[20]: '3'

It will work however if we add WATCH to the pipeline.

But I don't want to create a pipeline when getting the value, because I won't always update the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant