feihangchen 2016-02-21 08:26 采纳率: 100%
浏览 5366
已采纳

redis配置密码,客户端报错

没有使用密码认证的情况下客户端连redis服务器都是正常的。使用密码配置会就提示错误了

在redis 服务端修改/etc/redis.conf

requirepass myRedis

重启服务
sudo service redis restart

客户端是使用JedisPool ,其中参数password 就是myRedis
使用的是new JedisPool(config, host, Integer.parseInt(port), Integer.parseInt(timeout), password);

当我从池中获取一个Jedis的时候就会报错;
Jedis jedis = jedisPool.getResource();

具体报错的地方在以下。

redis.clients.jedis.Connection 类的 socket.connect(new InetSocketAddress(host, port), timeout);就会报
Could not get a resource from the pool

public void connect() {
    if (!isConnected()) {
        try {
            socket = new Socket();
            //->@wjw_add
            socket.setReuseAddress(true);
            socket.setKeepAlive(true);  //Will monitor the TCP connection is valid
            socket.setTcpNoDelay(true);  //Socket buffer Whetherclosed, to ensure timely delivery of data
            socket.setSoLinger(true,0);  //Control calls close () method, the underlying socket is closed immediately
            //<-@wjw_add

            socket.connect(new InetSocketAddress(host, port), timeout);
            socket.setSoTimeout(timeout);
            outputStream = new RedisOutputStream(socket.getOutputStream());
            inputStream = new RedisInputStream(socket.getInputStream());
        } catch (IOException ex) {
            throw new JedisConnectionException(ex);
        }
    }
}


       redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:42)

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:137)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:65)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1706)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:65)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:819)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:429)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:360)
at redis.clients.util.Pool.getResource(Pool.java:40)
... 2 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:132)
... 9 more

  • 写回答

2条回答 默认 最新

  • zxl78585 2016-02-21 09:42
    关注

    你这中错误,应该是你启动redis的时候,没有使用配置文件,或者是配置文件没有生效。redis带配置文件启动的命令是:
    redis-server redis.conf
    如果用这样还是无法启动,那建议您检查一下您的配置文件是否正确

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型