获取Redis连接池实例报错及解决方案( Could not get a resource from the pool)
2019-03-24 21:33
405 查看
描述:
这个错误产生的前提是这样的,将数据存入redis(新安装的)中,在通过连接池获取jedis实例时,产生如下错误( Could not get a resource from the pool)。
分析:
由于是新安装的redis,配置文件没有更改,低级的错误浪费不少时间,写一篇文章,让同样犯这种错误的朋友别再浪费时间。
解决:
更改配置文件 redis.conf 中两处
1.将 bind 127.0.0.1 注释掉
2.将 protected-mode 改为 no
bind 127.0.0.1 | protected-mode |
---|---|
默认情况bind=127.0.0.1只能接受本机的访问请求不写的情况下,无限制接受任何ip地址的访问 | 如果开启了protected-mode,那么在没有设定bind ip且没有设密码的情况下,Redis只允许接受本机的相应 |
运行代码
//创建jedis配置文件对象 val jedisPoolConfig = new JedisPoolConfig() //添加配置信息 jedisPoolConfig.setMaxTotal(100) jedisPoolConfig.setMaxIdle(20) jedisPoolConfig.setMinIdle(0) jedisPoolConfig.setBlockWhenExhausted(true) jedisPoolConfig.setMaxWaitMillis(500) jedisPoolConfig.setTestOnBorrow(true) //创建连接池对象 var jedisPool:JedisPool = new JedisPool(jedisPoolConfig,"linux1",6379) //获取实例 jedisPool.getResource
报错内容
ERROR --- [ Executor task launch worker for task 15] org.apache.spark.executor.Executor (line: 91) : Exception in task 7.0 in stage 2.0 (TID 15) redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:53) at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) at com.atguigu.bigdata.sparkmall.common.RedisUtil$.getJedisClient(RedisUtil.scala:26) at com.atguigu.bigdata.sparkmall.realtime.Req7TimeAdvertClickTrendApplication$$anonfun$main$1$$anonfun$apply$2.apply(Req7TimeAdvertClickTrendApplication.scala:54) at com.atguigu.bigdata.sparkmall.realtime.Req7TimeAdvertClickTrendApplication$$anonfun$main$1$$anonfun$apply$2.apply(Req7TimeAdvertClickTrendApplication.scala:53) at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926) at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926) at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1951) at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1951) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87) at org.apache.spark.scheduler.Task.run(Task.scala:99) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:322) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: 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.BinaryJedis.connect(BinaryJedis.java:1767) at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106) at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at redis.clients.util.Pool.getResource(Pool.java:49) ... 14 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) 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.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at redis.clients.jedis.Connection.connect(Connection.java:184) ... 21 more
相关文章推荐
- Redis2.1.0:Could not get a resource from the pool的分析
- redis提示Could not get a resource from the pool(jedis连接池配置)
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- jedis 连接 redis:Could not get a resource from the pool——我的出错原因和解决办法
- redis提示Could not get a resource from the pool(jedis连接池配置)
- Redis客户端连接异常:Could not get resource from the pool 解决办法
- Java连接redis集群报错,connection refused 和Could not get a resource from the pool
- redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
- Redis客户端连接异常:Could not get resource from the pool 解决办法
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- 、redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- 处理应用端连接redis报could not get a resource from the pool问题
- 、redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- Redis: Could not get a resource from the pool
- java 连接 redis集群时报错:Could not get a resource from the pool
- 急求大婶指导redis Could not get a resource from the pool 异常
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool