redis的事务

python代码

class Redis_Test(object):
    def __init__(self):
        self.client = redis.StrictRedis(host="xxx", port=6379, db=0,decode_responses=True)

    def transaction_set_str(self):
        try:
            """1.回滚事务,redis的事务是在管道中进行的,要么同时成功,要么同时失败"""
            # 1. 开启事务管道
            pipe = self.client.pipeline()
            # 2. 进行操作
            pipe.set("s3","v3")
            print(1/0)  # 事务提交前出现异常,导致事务没有提交。
            pipe.set("s4","v4")
            pipe.execute()
        except Exception as e:
            print(e)
原文地址:https://www.cnblogs.com/meloncodezhang/p/13669772.html