Python redis 模块,exceptions() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用redis.exceptions()

项目:enteletaor    作者:cr0hn    | 项目源码 | 文件源码
def brute_redis(host, port=6379, user=None, password=None, db=0):

    try:
        redis.StrictRedis(host=host,
                          port=int(port),
                          socket_connect_timeout=1,
                          socket_timeout=1,
                          password=password,
                          db=db).ping()
        return True

    except redis.exceptions.ResponseError as e:
        if str(e).startswith("NOAUTH"):
            raise AuthRequired()
        else:
            return False
    except Exception:
        return False


# ----------------------------------------------------------------------
项目:nyu-devops-BankingSystem    作者:HansiMou    | 项目源码 | 文件源码
def validate_active(active):
    active = str(active).lower()

    if (active == 'true' or active == 't' or active == '1'):
        return ('true', 'valid', 'true')
    elif (active == 'false' or active == 'f' or active == '0'):
        return ('true', 'valid', 'false')

    return ('false', 'Not a valid value for active parameter', active)

######################################################################
# Connect to Redis and catch connection exceptions
######################################################################