spring server cannot connect to redis using jedis client

淺唱寂寞╮ 提交于 2019-12-24 09:50:00

问题


I am getting this issue when I deploy redis server and spring server in two different servers and try to connect to spring server through my application.

App Details:
We have mobile application which publish gps coordinates to spring server using stomp. In the spring server we create jedis pubsub connection and publish those gps data to our web application and web users subscribe to those jedis pubsub connections.

Library versions:
stomp:1.7.1
jedis: 2.8.1
spring: 4.3.0

Working scenarios:
*Deploy spring server in my local machine and redis server in remote production server.
*Deploy spring server in remote server and redis server in same remote server where spring server is deployed.

Partially Working scenarios:
*Deploy spring server in remote server and redis server in different remote server where spring server is deployed. In this scenario I monitor redis server using redis cli and I can see the "HGETALL", "PUBLISH" key words with its data. But the same time I got following error in spring server:

Caused by:

java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at redis.clients.jedis.Connection.connect(Connection.java:158)
    ... 4 more
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
    at redis.clients.jedis.Connection.connect(Connection.java:164)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80)
    at redis.clients.jedis.Connection.setTimeoutInfinite(Connection.java:68)
    at redis.clients.jedis.Jedis.subscribe(Jedis.java:2626)
    at shipxpress.pubsubservice.controllers.SubscriberThread.run(MainController.java:227)

The spring server can successfully depoyed to the server and exception occurs when jedis try to publish or subscripe to the connection. I can succesfully ping to redis server from the server where we deploy the spring server through the redis-cli and the redis server prtected-mode is no and and bind ip is set to 0.0.0.0

Links: I went through following links but no luck
Redis bind to more than one IP

https://github.com/xetorthio/jedis/issues/1405

Cannot connect to redis using jedis


回答1:


This issue means that the Spring remote server is not able to communicate with the other remote server(Redis server) on the default Redis port. Maybe you could confirm this by trying to access the Remote Redis server from the other remote Server using netstat from the console.




回答2:


I had the same issue, and the simplest solution was

Find the following line in your redis.conf file and comment it out:

bind 127.0.0.1

By adding a # in front of it:

# bind 127.0.0.1

and change the line protected-mode yes to be protected-mode no

save your redis.conf and restart redis using the config file

redis-server /configFileLocation


来源:https://stackoverflow.com/questions/44043358/spring-server-cannot-connect-to-redis-using-jedis-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!