Use python's redis package to connect to redis and deliberately set a wrong password, but found that it did not raise an exception
System: win 10
Python version: 3.6.8
import redis host = "127.0.0.1" port = 6379 password = "123456" redis_conn = redis.Redis(host=host,port=port,password)
After testing, we found that after creating the connection object, we When querying through the conn
object, it threw a password error exception
import redis host = "127.0.0.1" port = 6379 password = "123456" try: redis_conn = redis.Redis(host=host,port=port,password) # 在创建连接后执行一个查询操作 redis_conn.client_list() except redis.ConnectError as err: print(str(err))
The above is the detailed content of How to catch redis exception in Python. For more information, please follow other related articles on the PHP Chinese website!