Python redis 테스트 스크립트.
랜덤으로 키를 생성해서 값을 넣도록 만든 Python redis 테스트 스크립트.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#!/usr/bin/env python from multiprocessing import Process import redis import random import string import time def id_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for x in range(size)) data = id_generator(12, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()") def g(idx): r_server = redis.Redis('localhost') for i in xrange(idx * 1024 * 1024 * 2, (idx+1)*1024*1024 * 2): key = 'PR%s'%(id_generator(random.randrange(6,15), "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()")) if random.randrange(1,100) > 70: r_server.setex(key, id_generator(random.randrange(128,1024), "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()"),random.randrange(1,350)) print "expire key: %s" % key else: r_server.set(key, id_generator(random.randrange(128,1024), "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()")) print "permanent key: %s" % key time.sleep(0.2) if __name__ == '__main__': pids = [] for i in xrange(80): p = Process(target=g, args=(i,)) pids.append(p) p.start() for pid in pids: pid.join() |