You can establish a transaction by calling the pipeline
method on the StrictRedis
. Redis commands executed against the transaction are performed in a single block.
# defaults to transaction=True
tx = r.pipeline()
tx.hincrbyfloat(debit_account_key, 'balance', -amount)
tx.hincrbyfloat(credit_account_key, 'balance', amount)
tx.execute()