jedis访问redis被拒绝

gzc
  • 69

CentOS7.0安装了redis4.0.10,安装成功并且windows上用RedisDesktopManager连接成功.

CentOS防火墙已关:

clipboard.png

redis.conf配置文件已改:

clipboard.png

java程序如下:

public static void main(String[] args) {
    Jedis jedis = new Jedis("127.0.0.1",6379);
    System.out.println(jedis.get("name"));
}

报错如下:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
    at redis.clients.jedis.Connection.connect(Connection.java:207)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:117)
    at redis.clients.jedis.Jedis.get(Jedis.java:152)
    at cn.chao.JedisTest.main(JedisTest.java:15)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)


怎么办?

回复
阅读 2.9k
1 个回答

需要确认你的服务确实运行着

    ps -ef | grep redis
    netstat -antp | grep 6379
    

你的java程序运行在与redis在同一台机器上?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏