当前位置:   article > 正文

redis验证

怎么验证redis正常
去randomkey
#!/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( )



验证key
#!/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)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/511128
推荐阅读
相关标签
  

闽ICP备14008679号