In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis disconnect how to reconnect? This problem may be often encountered in our daily work. This article mainly discusses the solution of redis disconnection and reconnection. There is a certain reference value, friends in need can refer to, hope to help you.
After the Redis is restarted, the network disconnects and returns to normal, the application must be able to recover itself. Take the jedis client in Java language as an example:
1. As a publisher
The Jedis object cannot be used as a singleton, and the Jedis object cannot recover itself after the network flash is broken. Each time a message is published, the Jedis object is fetched from the JedisPool and the set method is called.
2. As a subscriber
When the network flash breaks, the psubscribe () method no longer blocks and throws an exception, so you can use the while loop to handle the exception inside the loop, as follows:
While (true) {Jedis redis = this.jedisPool.getResource (); try {redis.psubscribe (this, channelArray);} catch (JedisConnectionException e) {logger.warn ("Exception:", e); logger.warn ("Exit redis psubscribe, retry after 1 second") } catch (Exception e) {logger.error ("Exception:", e);} try {Thread.sleep (1000);} catch (Exception unused) {} try {if (redis! = null) {redis.close () }} catch (Exception unused) {}}
After reading the content of the appeal, have you mastered the method of redis disconnection and reconnection? If you want to know more related content, welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.