spring服务器无法使用jedis客户端连接到redis [英] spring server cannot connect to redis using jedis client

查看:71
本文介绍了spring服务器无法使用jedis客户端连接到redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在两个不同的服务器上部署 redis 服务器和 spring 服务器并尝试通过我的应用程序连接到 spring 服务器时,我遇到了这个问题.

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.

应用详情:
我们有使用 stomp 将 gps 坐标发布到 spring 服务器的移动应用程序.在 spring 服务器中,我们创建 jedis pubsub 连接并将这些 gps 数据发布到我们的网络应用程序,网络用户订阅这些 jedis pubsub 连接.

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.

库版本:
跺脚:1.7.1
绝地武士:2.8.1
弹簧:4.3.0

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

工作场景:
*在我的本地机器上部署spring服务器,在远程生产服务器上部署redis服务器.
*在远程服务器上部署spring server,在部署spring server的同一个远程服务器上部署redis server.

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.

部分工作场景:
*在远程服务器上部署spring server,在部署spring server的不同远程服务器上部署redis server.在这种情况下,我使用 redis cli 监视 redis 服务器,我可以看到HGETALL"、PUBLISH"关键字及其数据.但同时我在 spring 服务器中遇到以下错误:

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:

原因:

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)

spring 服务器可以成功部署到服务器,jedis 尝试发布或订阅连接时发生异常.我可以通过redis-cli从我们部署spring服务器的服务器成功ping到redis服务器,并且redis服务器prtected-mode为no并且绑定ip设置为0.0.0.0

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

链接:我浏览了以下链接,但没有运气
Redis 绑定多个 IP

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

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

无法使用jedis连接redis

推荐答案

我遇到了同样的问题,最简单的解决方案是

I had the same issue, and the simplest solution was

在您的 redis.conf 文件中找到以下行并注释掉:

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

并将行 protected-mode yes 更改为 protected-mode no

保存您的 redis.conf 并使用 config 文件重新启动 redis

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

redis-server /configFileLocation

这篇关于spring服务器无法使用jedis客户端连接到redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆