aredis
aredis copied to clipboard
Transaction example doesn't work with StrictRedisCluster
Checklist
- Python version: 3.8
- Using hiredis or just Python parser: hiredis
- Using uvloop or just asyncio event loop: uvloop
- Does issue exists against the
masterbranch of aredis? yes
Steps to reproduce
I'm initializing a StrictRedisCluster against an AWS ElastiCache Redis cluster, using skip_full_coverage_check and decode_responses.
When I run the example:
async with await r.pipeline() as pipe:
while 1:
try:
# put a WATCH on the key that holds our sequence value
await pipe.watch("OUR-SEQUENCE-KEY")
# after WATCHing, the pipeline is put into immediate execution
# mode until we tell it to start buffering commands again.
# this allows us to get the current value of our sequence
current_value = await pipe.get("OUR-SEQUENCE-KEY")
next_value = int(current_value) + 1
# now we can put the pipeline back into buffered mode with MULTI
pipe.multi()
pipe.set("OUR-SEQUENCE-KEY", next_value)
# and finally, execute the pipeline (the set command)
await pipe.execute()
# if a WatchError wasn't raised during execution, everything
# we just did happened atomically.
break
except WatchError:
# another client must have changed 'OUR-SEQUENCE-KEY' between
# the time we started WATCHing it and the pipeline's execution.
# our best bet is to just retry.
continue
current_value is an instance of StrictClusterPipeline instead of an int. Looks like the watch doesn't make the pipeline go into immediate execution mode?
Expected behavior
The pipeline is put into immediate execution mode.
Actual behavior
The pipeline returns self.
It seems calling pipe.watch does nothing except log a warning ('Call WATCH from a Pipeline object'), so I'm not sure how to proceed.