redis pipeline|Request/Response protocols and RTT(python)

来源:互联网 发布:测量员软件使用说明书 编辑:程序博客网 时间:2024/05/26 05:51


redis pipeline:

http://redis.io/topics/pipelining

http://www.cnblogs.com/redcreen/archive/2011/02/15/1955517.html

redis-py:

https://github.com/antirez/redis


python代码实现

def without_pipelining():    start = datetime.datetime.now()    r = redis.Redis()    for i in range(10000): r.ping()    print 'without pipeline ', datetime.datetime.now() - start    def with_pipelining():    start = datetime.datetime.now()    with redis.Redis().pipeline() as pipe:        for i in range(10000):             pipe.ping()        pipe.execute()    print 'with    pipeline ', datetime.datetime.now() - start                    without_pipelining()with_pipelining()

测试输出:

@redis-py$ python pipeline.pywithout pipeline  0:00:00.578954with    pipeline  0:00:00.175569







原创粉丝点击