redis连接数据库与去重代码

连接数据库

def connect_redis(mode):
    """连接redis."""
    host = config[mode]["host"]
    port = config[mode]["port"]
    redis_db = config[mode]["db"]
    password = config[mode]["pass"]
    return redis.StrictRedis(
        host=host, port=port, db=redis_db, password=password, decode_responses=True
    )

redis_helper = connect_redis('redis_dev')

去重

def duplicate_data(redis_helper, value):
    """duplicate data by redis - set."""
    result = redis_helper.sadd('master_insight', value)
    if result == 0:
        print("---duplicate key---: %s,  pass---" % value)
        return True
    return False

result = duplicate_data(redis_helper, link)

你可能感兴趣的:(redis,数据库,redis)