test_pipline.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import redis
import time
r = redis.StrictRedis(host='localhost', port=6379, db=0)
# 通常の場合
start = time.time()
for key in range(1000):
r.get(key)
stop = time.time()
print stop - start
# パイプライニングした場合
start = time.time()
with r.pipeline() as pipe:
for key in range(1000):
pipe.get(key)
pipe.execute()
stop = time.time()
print stop - start
実行結果:
% python test_pipline.py
0.168359994888
0.0300588607788