一、异常
复制代码
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...
无法从哨兵运行中获得主地址
1警告: Cannot get master address from sentinel running @ 127.0.0.1:26379. Reason: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect. Trying next one.
可能导致以上异常原因:
1.ip(可能是内网,外网这个要分清楚)不对。也可能是配置文件中bind未注释。
2.redis未启动。
3.所有的哨兵,不能确是mymaster主运行。
二、连接池连不上
复制代码
看了很多网上的解决办法,可能是
1redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
1.bind 127.0.0.1 未注释。
2.ip端口ping通 (以下是通的状态)
redis 127.0.0.1:6388> ping
PONG
redis 127.0.0.1:6388>
3.防火墙ip、redis版本问题、各种参数设置
4.密码
我测试时是密码有问题。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38public static void main(String[] args) { Set<String> sentinels = new HashSet<String>(); String hostAndPort1 = "111.13.56.194:26379"; //String hostAndPort1 = "192.168.1.104:26379"; sentinels.add(hostAndPort1); String clusterName = "mymaster6379" ; String password = "123456" ; //此处添加密码 // 建立连接池配置参数 JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(50); config.setMinIdle(8);//设置最小空闲数 config.setMaxWaitMillis(10000); config.setTestOnBorrow(true); config.setTestOnReturn(true); //Idle时进行连接扫描 config.setTestWhileIdle(true); //表示idle object evitor两次扫描之间要sleep的毫秒数 config.setTimeBetweenEvictionRunsMillis(30000); //表示idle object evitor每次扫描的最多的对象数 config.setNumTestsPerEvictionRun(10); //表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 config.setMinEvictableIdleTimeMillis(60000); JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName,sentinels,config,password); Jedis jedis = null; try { jedis = redisSentinelJedisPool.getResource(); jedis.set("key", "aaa"); System.out.println(jedis.get("key")); System.out.println(jedis.get("bbb")); } catch (Exception e) { e.printStackTrace(); } finally { //redisSentinelJedisPool.returnResource(jedis); jedis.close(); } redisSentinelJedisPool.close(); }
注意:
master(主)需要设置密码,否则会抛出Could not get a resource from the pool
requirepass 123456
master(主)设置了密码,slave(从)需要验证,否则主从配置不生效,主从不同步。
masterauth 123456
最后
以上就是傻傻棉花糖最近收集整理的关于redis和jedis搭建过程中遇到的问题的全部内容,更多相关redis和jedis搭建过程中遇到内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复