标签:个人 index with ado 任务 sms line code val
if __name__ == "__main__": with sms_redis.pipeline() as pipe: while 1: try: # 事务开始 pipe.multi() count = int(sms_redis.get(‘stock_count‘)) if count > 0: # 有库存 pipe.set(‘stock_count‘, count - 1) # 事务结束 pipe.execute() # 把命令推送过去 break except Exception: traceback.print_exc() continue
if __name__ == "__main__": with sms_redis.pipeline() as pipe: while 1: try: #关注一个key pipe.watch(‘stock_count’) count = int(pipe.get(‘stock_count‘)) if count > 0: # 有库存 # 事务开始 pipe.multi() pipe.set(‘stock_count‘, count - 1) # 事务结束 pipe.execute() # 把命令推送过去 break except Exception: traceback.print_exc() continue
python学习笔记4-redis multi watch实现锁库存
标签:个人 index with ado 任务 sms line code val
原文地址:http://www.cnblogs.com/suyuan1573/p/6037066.html