今天在使用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();
}
}
后来指定配置文件启动才能连接redis(我在redis.conf设置了密码的)
redis-server /opt/redis/redis.conf &
可以成功使用了哇


关闭redis:(xxxxx填写密码)
redis-cli -a xxxxx shutdown
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
其实这个错误出现的原因和上面一样,都是redis启动方式的问题
指定配置文件启动就能成功连接redis。

启动后,即可正常连接redis啦

202211091935三