IlyaSkriblovsky/txredisapi

pipelining transactions

sgoudelis opened this issue · 2 comments

I am trying to to pipeline multiple transactions using txredisapi. I am using transactions because I want to check if a hash key exists before I add another key/value to it.

Here is my code:

pipeline = yield redisconnection.pipeline()
...
yield pipeline.watch(key)
transaction = yield pipeline.multi()
keyexists = yield transaction.exists(key)
if keyexists:
    transaction.hset(key, 'clients', json.dumps(clientslist))
r = yield transaction.commit()

...
yield pipeline.execute_pipeline()

I adjusted my code based on the example here: https://stackoverflow.com/questions/10987441/redis-only-allow-operation-on-existing-keys
What I am observing is that the program always hangs after the pipeline.multi() call.

Anyone have any thoughts ?

I'm not sure that I'm recalling correctly, but according to example in README, watch itself returns a transaction object.

Please try to change your code like this:

transaction = yield redisconnection.watch(key)
yield transaction.multi()
...
yield transaction.commit()

You don't need pipeline() because due to asynchronous nature of txredisapi all commands are pipelined automatically

You can close this one.