Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
test_codis_mig.py
import threading
import os
import time
import commands
import redis
class RedisServer(threading.Thread):
def __init__(self, binary = 'redis-server', port = 7777):
threading.Thread.__init__(self)
self.binary = binary
self.port = port
def run(self):
cmd = '%s --port %s' % (self.binary, self.port)
print cmd
#os.system(cmd)
commands.getoutput(cmd)
def __str__(self):
return '%s:%s' % (self.binary, self.port)
r1 = RedisServer('./bin/codis-server', port = 7777)
r2 = RedisServer('./bin/codis-server', port = 7778)
r1.start()
r2.start()
time.sleep(1)
conn = redis.StrictRedis('127.0.0.1', r1.port)
i = 0
while i < 1000 * 1000:
conn.hmset('test-key', {'f-%s' % i: 1})
i += 1
t1 = time.time()
print conn.execute_command('slotsmgrttagone', '127.0.0.1', '7778', '1000', 'test-key')
t2 = time.time()
print t2 - t1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment