aioredis连接池上下文是否也清理了事务?

时间:2018-03-02 04:34:29

标签: python redis python-asyncio

async def transaction():
    pool = await aioredis.create_pool('redis://localhost')

    with await pool as con:
        await con.execute('multi')
        await con.execute('watch', 'var')
        raise Exception

上述事务是通过连接池上下文安全释放的吗?

async def transaction():
    pool = await aioredis.create_pool('redis://localhost')

    with await pool as con:
        try:
            await con.execute('multi')
            await con.execute('watch')
            raise Exception
        except Exception as e:
            await con.execute('discard')            

否则,我应该明确地放弃交易吗?

0 个答案:

没有答案