It is connected to the ordered set of python redis weight

# - * - Coding: UTF-8 - * - 
Import Redis
from Constant Import redis_ip, redis_db, redis_pw, Logger, redis_zset_clean_date, redis_zset_name, \
move_file_lm

the pool = redis.ConnectionPool (Host = redis_ip, db = redis_db, password = redis_pw)
# = redis.ConnectionPool the pool (db = 6, password = redis_pw)
rr = redis.Redis (= connection_pool the pool) # # client StrictRedis = Redis merged
pipe = rr.pipeline (transaction = True) # batch operations, asynchronous encounter prone to error, may not be used, with a direct connection rr objects, one at a time adding


DEF distinct_md5 (DATE, eml_md5, eml_path, redis_fail_path):
  #
# pipe.zadd (redis_zset_name, eml_md5, DATE)
# pipe.zadd (redis_zset_name, {DATE: eml_md5}, nx = True) # nx only inserted, will not modify the value of its presence fraction
# pipe.zadd (redis_zset_name, {date: eml_md5})
pipe.zadd (redis_zset_name, {eml_md5: DATE})
return pipe.execute () [0] #. 1 added, without adding 0

# pipe.zcard ( 'eml_md5_zset') # see the total number of


def del_redis_md5 (n, m): # delete point value according to
the try:
pipe.zremrangebyscore (redis_zset_name, n-, m)
the except Exception AS E:
logger.warning ( "delete Redis cache md5 value failed: {}," the format (E).)
return
pipe.execute ()


# return
# pipe.execute return () [0]


DEF clean_redis_zset (md5_score):
IF md5_score <= redis_zset_clean_date:
md5_score + = 31 is
md5_clean_score = md5_score - redis_zset_clean_date
del_redis_md5 (md5_clean_score - 0.5, 0.5 + md5_clean_score) # cleaning on the Redis md5 closed interval
# print(distinct_md5(redis_zset_name, "qwe", 2, "sdfsd", "sdfsdf"))
#print(distinct_md5(27, "qweqwe","sdfsd", "sdfsdf"))
# print(del_redis_md5(redis_zset_name, 1, 10))

Guess you like

Origin www.cnblogs.com/520zm/p/11298208.html