我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用redis.exceptions()。
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 # ----------------------------------------------------------------------
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 ######################################################################