python redis连接 有序集合去重
发布时间:2020-12-20 12:48:25 所属栏目:Python 来源:网络整理
导读:# -*- coding: utf-8 -*- import redisfrom constant import redis_ip,redis_db,redis_pw,logger,redis_zset_clean_date,redis_zset_name, move_file_lmpool = redis.ConnectionPool(host=redis_ip,db=redis_db,password=redis_pw)# pool = redis.Connectio
# -*- coding: utf-8 -*- import redisfrom constant import redis_ip,redis_db,redis_pw,logger,redis_zset_clean_date,redis_zset_name, move_file_lmpool = redis.ConnectionPool(host=redis_ip,db=redis_db,password=redis_pw)# pool = redis.ConnectionPool(db=6,password=redis_pw)rr = redis.Redis(connection_pool=pool) # # 客户端StrictRedis=Redis 合并了pipe = rr.pipeline(transaction=True) # 批量操作,遇到异步容易出错,可以不使用,直接用 rr 连接对象,一次一个添加def distinct_md5(date,eml_md5,eml_path,redis_fail_path): # # pipe.zadd(redis_zset_name,date) # pipe.zadd(redis_zset_name,{date: eml_md5},nx=True) # nx 只插入,存在的值不会修改其分数 # pipe.zadd(redis_zset_name,{date: eml_md5}) pipe.zadd(redis_zset_name,{eml_md5: date}) return pipe.execute()[0] # 1 添加,0 没添加 # pipe.zcard(‘eml_md5_zset‘) # 查看总个数def del_redis_md5(n,m): # 按照分数值进行删除 try: pipe.zremrangebyscore(redis_zset_name,n,m) except Exception as e: logger.warning("删除Redis缓存中md5值失败: {},".format(e)) return pipe.execute()# return# return pipe.execute()[0]def clean_redis_zset(md5_score): if md5_score <= redis_zset_clean_date: md5_score += 31 md5_clean_score = md5_score - redis_zset_clean_date del_redis_md5(md5_clean_score - 0.5,md5_clean_score + 0.5) # 清理Redis上的md5 闭区间# print(distinct_md5(redis_zset_name,"qwe",2,"sdfsd","sdfsdf"))#print(distinct_md5(27,"qweqwe","sdfsdf"))# print(del_redis_md5(redis_zset_name,1,10)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |