def regist_url(url,bites=8,hours=48): md5=utility.md5code(url) cinfo = dict(state=0,code="",url=url,expire=0) cinfo.update(RedisCli.hgetall("Q2k:Urls:%s"%md5)) if cinfo["state"]=="0": if cinfo["code"]=="": while True: code = utility.generateCode(bites) if not exists(code): break time.sleep(0.1) cinfo["code"]=code RedisCli.hset("Q2k:Codes", cinfo["code"],url) RedisCli.hset("Q2k:Urls:%s"%md5,"code",cinfo["code"]) RedisCli.hset("Q2k:Urls:%s"%md5,"state",1) #默认将过期时间向后延期 RedisCli.hset("Q2k:Urls:%s"%md5,"expire",time.time()+hours*60*60) return cinfo["code"]
def updateHashTable(uid, name, key="", value="", **dict): tag = "profile:%s:%s" % (uid, name) if dict != None and len(dict) > 0: RedisCli.hmset(tag, dict) if name != None: RedisCli.hset(tag, key, value)
def apply(url,bites,hours): md5=utility.md5code(url) RedisCli.hset("Q2k:Urls:%s"%md5,"state",0) RedisCli.rpush("Q2k:Queue:Apply",json.dumps(dict(url=url,bites=bites,hours=hours)))