question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

weird pipeline() combined with watch() behavior

See original GitHub issue

I understand it’s intended and documented, still it’s seems so inconvenient, illogical and prohibits efficient use of pipelining (not MULTI).

Why pipe suddenly breaks when I call .watch()? It is still kind of pipe, but it doesn’t work as one. Maybe, old 2.2 approach is not the best, but it didn’t cause this confusion. I used .pipeline(transaction=false) to make pipeline and with a flag on to make atomic pipeline. Cluttering everything in on method is questionable but concept is clear. Now, we still use .pipeline() to get atomic pipeline until we don’t use .watch() when we suddenly loose pipelining and using .multi() directly to get atomic, which makes things with MULTI very inconsistent.

My use case, implemented for redis-py 2.2:

# set up pipeline not for multi, but to avoid unneeded network roundtrips
pipe = redis_conn.pipeline(transaction=False)  
pipe.watch(version_key, *conjs_keys)
# get something from redis
pipe.get(...)
pipe.sunion(...)
...
# ignore watch() result, gather all other
_, result1, result2, ... = pipe.execute() 

if <some condition involving result*>:
    redis_conn.unwatch()
else:
    try:
        txn = redis_conn.pipeline()
        # Change something in redis
        txn.delete(...)
        txn.execute()
    except WatchError:
        <Optimistic locking failed: just redo everything.>

Actual working example is here https://github.com/Suor/django-cacheops/blob/master/cacheops/invalidation.py#L111

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
roncohencommented, Apr 18, 2016

Sorry to revisit this old thread, but is there a way to buffer up those three commands that @Suor mentioned? I’m trying to get a lot of data from watched keys, and would like to avoid those roundtrips. I also tried to start the overall pipeline with pipeline(transaction=false) but it does not seem to be the way to go:

with redis.pipeline(transaction=False) as pipe:
    pipe.watch(*keys)
    for key in keys:
        pipe.lrange(key, 0, -1)

    data = pipe.execute()

    pipe.multi()
    # set stuff back, then:
    pipe.execute()

I get ResponseError: DISCARD without MULTI

0reactions
github-actions[bot]commented, Sep 1, 2020

This issue is marked stale. It will be closed in 30 days if it is not updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

weird pipeline() combined with watch() behavior #197 - GitHub
So, new watch behavior is ok with transactions, the problem is its incompatible with plain pipelines with transaction=False. By the way, .
Read more >
Strange behaviour with multiple scikit learn pipelines
For some reason each pipeline fits the data without issue, and when they occur in sequence, they transform the data without issue either....
Read more >
Makoto's preprocessing pipeline - SCCN
(Update 11/29/2017) I wrote a simple EEGLAB plugin fullRankAveRef() to perform the average reference after adding the original reference channel (i.e., zero- ...
Read more >
Elixir for Beginners: From Pipes to Pattern Matching and Beyond
Learning Elixir? We have collected all the tips, techniques, and patterns you need to do beginner-level Elixir programming in one article.
Read more >
Weird Loops in Pipes - What are They? What are They For?
Have you ever seen a pipe that turns laterally but again loops back to its original direction without really going anywhere?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found