redis验证

去randomkey

#!/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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值