redis-py中pipline
来源:互联网 发布:nginx ffmpeg hls 编辑:程序博客网 时间:2024/05/15 15:41
>>> with r.pipeline() as pipe:... while 1:... try:... # put a WATCH on the key that holds our sequence value... pipe.watch('OUR-SEQUENCE-KEY')... # after WATCHing, the pipeline is put into immediate execution... # mode until we tell it to start buffering commands again.... # this allows us to get the current value of our sequence... current_value = pipe.get('OUR-SEQUENCE-KEY')... next_value = int(current_value) + 1... # now we can put the pipeline back into buffered mode with MULTI... pipe.multi()... pipe.set('OUR-SEQUENCE-KEY', next_value)... # and finally, execute the pipeline (the set command)... pipe.execute()... # if a WatchError wasn't raised during execution, everything... # we just did happened atomically.... break... except WatchError:... # another client must have changed 'OUR-SEQUENCE-KEY' between... # the time we started WATCHing it and the pipeline's execution.... # our best bet is to just retry.... continue
防止并发情况下的影响,
采用watch用来监控key是否变化。
watch下的代码是直接运行的,调用multi()后才进入缓冲区,等到execute(),缓冲区的代码才一并执行。
如果其他客户端改变了所监控的key,立马抛error
0 0
- redis-py中pipline
- Redis pipline
- redis 中pipline,mset, mget使用对比
- pipline
- 关于redis的pipline和lua脚本
- redis利用pipline实现发布订阅机制
- redis-py
- django-redis 和 py-redis
- redis-py 下载地址
- redis-py说明文件
- redis-py API Reference
- redis-py API Reference
- redis-py-cluster详述
- redis-monitor.py
- python redis-py使用
- sklearn pipline
- redis.py整理(未完)
- redis的py语法lrem
- Android布局 android:gravity 和 android:layout_Gravity一些细节问题
- UIScrollView的属性总结
- 设计模式之中介者
- 生产者消费者模型
- c++prime重学(四)基于第四版
- redis-py中pipline
- 学习Fragment笔记-选择Master/Dtail Flow创建项目开始(1)
- 配置防火墙端口
- Java异常处理
- HDU 3530 Subsequence
- Q推广和营销要从哪里着手才能有更好的效果呢?
- JavaScript 对象
- shell语法简介
- PHP函数autoload简单应用