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)
#Normal case
start = time.time()
for key in range(1000):
r.get(key)
stop = time.time()
print stop - start
#When pipe lining
start = time.time()
with r.pipeline() as pipe:
for key in range(1000):
pipe.get(key)
pipe.execute()
stop = time.time()
print stop - start
Execution result: % python test_pipline.py 0.168359994888 0.0300588607788
Recommended Posts