Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Python catches redis exceptions

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how Python catches redis exceptions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Python catches redis exceptions.

Scene reproduction

Using python's redis package to connect to redis, deliberately set the wrong password, but found that he did not throw an exception

Environment

System: win 10

Python version: 3.6.8

Initial code import redishost = "127.0.0.1" port= 6379password = "123456" redis_conn = redis.Redis (host=host,port=port,password)

After testing, we found that after creating the connection object, it threw a password error exception when we queried through the conn object.

Capture redis connection exception code import redishost = "127.0.0.1" port= 6379password = "123456" try: redis_conn = redis.Redis (host=host,port=port,password) # perform a query operation redis_conn.client_list () except redis.ConnectError as err: print (str (err)) after creating the connection. I believe you have a deeper understanding of "how Python catches redis exceptions". You might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report