Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
import redis
import time
import random, string
from os import getenv
r_host = getenv('HOST', 'localhost')
r_port = getenv('PORT', '6379')
r = redis.StrictRedis(host=r_host, port=r_port)
num = 10000
def rs(length):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(length))
sets = 0
for i in range(0, num):
rand = rs(10)
set_start = time.time()
r.set(i, rand)
set_end = time.time()
diff = set_end - set_start
sets += diff
gets = 0
for i in range(0, num):
get_start = time.time()
get_end = time.time()
diff = get_end - get_start
gets += diff
s = sets / num * 1000000
g = gets / num * 1000000
print("Avg set: {0}".format(s))
print("Avg get: {0}".format(g))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.