-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Change pipeline behaviour to autoexecute upon exit of the with
block
#1383
Conversation
…k - a behaviour I very much expected
Codecov Report
@@ Coverage Diff @@
## master #1383 +/- ##
==========================================
+ Coverage 85.92% 85.96% +0.03%
==========================================
Files 6 6
Lines 2892 2892
==========================================
+ Hits 2485 2486 +1
+ Misses 407 406 -1
Continue to review full report at Codecov.
|
Sometimes you do care about the reply values from commands within the pipeline and we need to provide a way to access those values. See the discussion on #730. |
You can still get results by calling |
Yes (in addition to calling execute manually) I wondered about setting a |
To play devil's advocate, could there be code in the wild written as follows?
But I'm struggling to come up with what Also presumably they'd be calling |
This pull request is marked stale. It will be closed in 30 days if it is not updated. |
Prompted by bot ... Re. the 'access to results' problem, I think @Fogapod is saying that this change request is not preventing you from doing the following:
It does however prevent the following
Is the lack of the latter a concern (or is it even possible in terms of the exit being already called?) If it is, we could store the result in the pipe, such that a later |
Just a passing visitor, but I noticed this PR as I've also encountered this problem. One way to satisfy all parties in a light-touch way would be to modify redis.utils.pipeline: i.e. change @contextmanager
def pipeline(redis_obj):
p = redis_obj.pipeline()
yield p
p.execute() to @contextmanager
def pipeline(redis_obj):
p = redis_obj.pipeline()
try:
yield p
finally:
p.execute() and then encourage users who want this behaviour to change their code from: with r.pipeline() as pipe:
... to from redis.utils import pipeline
with pipeline(r) as pipe:
... Obviously it's light-touch enough that I don't really need this PR, but perhaps it would be useful for others. |
This pull request is marked stale. It will be closed in 30 days if it is not updated. |
A behaviour I very much expected!
I've a similar open pull request for aredis at NoneGG/aredis#168
The author there suggested that redis-py is the template being followed, so I thought it might be good to open it up for discussion here also to see if there are any objections?
The idea is that if you are just setting a few values in a transaction, you'd expect them all to be completed upon exiting the
with
block (you don't care about the results in this case):I didn't find any documentation relating to pipelines, but didn't look all that hard.