赞
踩
#!/usr/bin/python26import timeimport redisfile_object = open('thefile.txt', 'w+')#file_object.write('haohao\n')#file_object.write('ningning\n')rediskey=""r = redis.Redis(host='11.11.11.11', port=8998)i = 1start = time.clock()while i<=10000000: if(i%1000==0): time.sleep(0.1) print i rediskey= r.randomkey() if(rediskey!=None): file_object.write(rediskey+'\n') i+=1print " cost %s second"%(time.clock()-start)file_object.close( )
#!/usr/bin/python26import timeimport redisstart=time.clock()def _key_hash( key) : hash = 5381 length = len(key) for i in xrange(length) : hash = ((hash << 5) + hash ) + ord(key[i]) return hashr11090 =redis.Redis(host='111.75.22.239', port=11090)r11091 =redis.Redis(host='111.75.22.239', port=11091)r11092 =redis.Redis(host='111.75.22.239', port=11092)r11093 =redis.Redis(host='111.75.22.239', port=11093)r11094 =redis.Redis(host='111.75.22.240', port=11094)r11095 =redis.Redis(host='111.75.22.240', port=11095)r11096 =redis.Redis(host='111.75.22.240', port=11096)r11097 =redis.Redis(host='111.75.22.240', port=11097)file_object = open('nonefile.txt', 'w+')def printkey(thiskey): s=_key_hash(thiskey)%8# print "hash:::::"+str(s)+" "+thiskey if(s==0): client=r11090 elif(s==1): client=r11091 elif(s==2): client=r11092 elif(s==3): client=r11093 elif(s==4): client=r11094 elif(s==5): client=r11095# print "5555 "+thiskey elif(s==6): client=r11096 elif(s==7): client=r11097 else: print thiskey+" hasherror" return -1; thisvalue=client.get(thiskey) if(thisvalue==None): print "error" file_object.write("error:"+str(thiskey)+" "+str(s)+" "+str(thisvalue) +"\n") else: file_object.write("right:"+thiskey+" "+thisvalue+"\n") #passf = open("bigFile.txt", "r") i=0while True: i+=1; if(i%1000==0): time.sleep(0.1) print i line = f.readline() if line: printkey(line.strip()) else: break f.close() file_object.close()print " cost %s second"%(time.clock()-start)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。