#!/usr/bin/env python

import time
import mc_ascii_client
from threading import Thread
import random

host = "10.3.121.98"
host = "127.0.0.1"

def t():
    global host
    keys = []
    keycount = 1000
    for i in range(keycount):
        keys.append("k_"+`i`)

    j = 0

    mct = mc_ascii_client.MemcachedAsciiClient(host, 11211, timeout=2)
    while True:
        if j % 100 == 0:
            print '.'

        try:
            start = random.randint(0,keycount-20)
            rkeys = mct.getMulti(keys[start:start+10])
        except mc_ascii_client.MemcachedError as e:
                mct.close()
                mct = mc_ascii_client.MemcachedAsciiClient(host, 11211, timeout=2)

        j = j + 1


mc = mc_ascii_client.MemcachedAsciiClient(host, 11211, timeout=5)

keycount = 1000
threadcount = 100

keys = []
for i in range(keycount):
    mc.set("k_"+`i`,0,0,"v_"+`i`)
    keys.append("k_"+`i`)

threads = []
for i in range(threadcount):
    threads.append(Thread(target=t))

for thread in threads:
    thread.start()

for thread in threads:
    thread.join()
