Perform Redis transactions with MULTI/EXEC
masterTransactions are supported on normal, lazy, and connection pool connections (but not on sharded connections).
Because exec is a reserved keyword in Python, you must use the .commit() method to finalize a transaction. To use optimistic locking, use .watch(key).
multi(): Starts the transaction.commit(): Commits the transaction and returns a list of all command responses.discard(): Aborts the transaction and returnsOK.
@defer.inlineCallbacks
def main():
rc = yield redis.ConnectionPool()
yield rc.delete(["a1", "a2", "a3"])
# Start transaction
t = yield rc.multi()
# Commands return "QUEUED"
yield t.set("a1", "1")
yield t.set("a2", "2")
# Commit and get all responses
r = yield t.commit()
print "commit=", repr(r)
yield rc.disconnect()