• 使用客户端jedis时报错Could not get a resource from the pool 以及使用Spring Data Redis报错解决方法


    一.Jedis

    报错

    今天在使用jedis时,一直报错

    Could not get a resource from the pool

    在网上找了好多解决的方法,并且找了半天错误,才发现是我的启动方式有问题。。。(初学者太菜了)

    解决方式

    原来启动只是使用的后台启动(默认配置)

    redis-server &

    然后进入客户端,有时候不用输密码都能用(我设置了密码的)
    并且在iead中使用时一直连不上redis,配置文件看了又看也没发现问题。

    public class JedisConnectionFactory {
        private static final JedisPool jedisPool;
        static{
            //配置连接池
            JedisPoolConfig poolConfig = new JedisPoolConfig();
            poolConfig.setMaxTotal(8);
            poolConfig.setMaxIdle(8);
            poolConfig.setMinIdle(0);
            poolConfig.setMaxWaitMillis(-1);
    
            //创建连接池对象
            jedisPool = new JedisPool(poolConfig,"192.168.142.130",6379,1000,"123456");
        }
    
        public static Jedis getJedis(){
            return jedisPool.getResource();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    后来指定配置文件启动才能连接redis(我在redis.conf设置了密码的)

    redis-server /opt/redis/redis.conf &

    可以成功使用了哇
    在这里插入图片描述
    在这里插入图片描述
    关闭redis:(xxxxx填写密码)

    redis-cli -a xxxxx shutdown

    二.Spring Data Redis

    报错

    Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.142.130:6379

    解决

    yml中的配置

    spring:
      redis:
        host: 192.168.142.130
        port: 6379
        password: 123456
        lettuce:
          pool:
            max-active: 8
            max-idle: 8
            min-idle: 0
            max-wait: 100ms
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    其实这个错误出现的原因和上面一样,都是redis启动方式的问题
    指定配置文件启动就能成功连接redis。
    在这里插入图片描述

    启动后,即可正常连接redis啦
    在这里插入图片描述

    202211091935三

  • 相关阅读:
    docker学习2-基本指令
    【牛客刷题】——Python入门 08 元组
    Vulhub靶场环境搭建
    java使用bouncycastle加解密
    各版本 DOTween 下载地址
    JVM篇---第四篇
    Vue笔记_03组件_mavonEditor组件(基于vue)
    翻译: 如何学习编译器:LLVM Edition
    多路并归,贪心:《信息学奥赛一本通》:池塘钓鱼
    JAVA设计模式-桥接模式
  • 原文地址:https://blog.csdn.net/qq_53843555/article/details/127775820