redis验证
程序员文章站
2022-07-14 15:52:14
...
去randomkey
验证key
#!/usr/bin/python26 import time import redis file_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 = 1 start = 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+=1 print " cost %s second"%(time.clock()-start) file_object.close( )
验证key
#!/usr/bin/python26 import time import redis start=time.clock() def _key_hash( key) : hash = 5381 length = len(key) for i in xrange(length) : hash = ((hash << 5) + hash ) + ord(key[i]) return hash r11090 =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") #pass f = open("bigFile.txt", "r") i=0 while 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)
上一篇: python发邮件
下一篇: Docker镜像的基本操作