创建交易

你可以通过调用 StrictRedis 上的 pipeline 方法来建立事务。针对事务执行的 Redis 命令在单个块中执行。

# defaults to transaction=True 
tx = r.pipeline()
tx.hincrbyfloat(debit_account_key, 'balance', -amount)
tx.hincrbyfloat(credit_account_key, 'balance', amount)
tx.execute()