IlyaSkriblovsky / txredisapi

non-blocking redis client for python twisted
Apache License 2.0
235 stars 91 forks source link

pipelining transactions #115

Closed sgoudelis closed 6 years ago

sgoudelis commented 7 years ago

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 ?

IlyaSkriblovsky commented 7 years ago

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

sgoudelis commented 6 years ago

You can close this one.