@@ -59,7 +59,7 @@ public void createSingle() {
59
59
}
60
60
61
61
public void createSentinel () {
62
- Set <String > sentinels = new HashSet <String >(Arrays .asList ("xxx :26379" , "xxx :26380" , "xxx :26381" ));
62
+ Set <String > sentinels = new HashSet <String >(Arrays .asList ("localhost :26379" , "localhost :26380" , "localhost :26381" ));
63
63
// 创建Jedis配置对象
64
64
String password = "" ;
65
65
Integer port = 6379 ;
@@ -72,7 +72,8 @@ public void createSentinel() {
72
72
poolConfig .setTestOnReturn (TEST_ON_RETURN );
73
73
String masterName = "mymaster" ;
74
74
// 初始化
75
- sentinelPool = new JedisSentinelPool (masterName , sentinels , poolConfig , TIMEOUT , password );
75
+ sentinelPool = new JedisSentinelPool (masterName , sentinels , poolConfig , TIMEOUT );
76
+ //sentinelPool = new JedisSentinelPool(masterName, sentinels, poolConfig, TIMEOUT, password);
76
77
}
77
78
78
79
/**
@@ -81,12 +82,20 @@ public void createSentinel() {
81
82
public void createCluster () {
82
83
Set <HostAndPort > jedisClusterNode = new HashSet <HostAndPort >();
83
84
String password = "apijson" ;
84
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6371 ));
85
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6372 ));
86
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6373 ));
87
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6374 ));
88
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6375 ));
89
- jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6376 ));
85
+
86
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6380 ));
87
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6381 ));
88
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6382 ));
89
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6383 ));
90
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6384 ));
91
+ jedisClusterNode .add (new HostAndPort ("127.0.0.1" , 6385 ));
92
+
93
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6371));
94
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6372));
95
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6373));
96
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6374));
97
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6375));
98
+ //jedisClusterNode.add(new HostAndPort("127.0.0.1", 6376));
90
99
JedisPoolConfig poolConfig = new JedisPoolConfig ();
91
100
/*
92
101
* 注意: 在高版本的jedis jar包,比如本版本2.9.0,JedisPoolConfig没有setMaxActive和setMaxWait属性了
@@ -103,9 +112,9 @@ public void createCluster() {
103
112
int maxAttempts = 5 ;
104
113
// JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT,
105
114
// DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
106
- jedisCluster = new JedisCluster (jedisClusterNode , connectionTimeout , soTimeout , maxAttempts , password , poolConfig );
115
+ jedisCluster = new JedisCluster (jedisClusterNode , connectionTimeout , soTimeout , maxAttempts , poolConfig );
116
+ //jedisCluster = new JedisCluster(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, password, poolConfig);
107
117
log .info ("节点信息:{}" , jedisCluster .getClusterNodes ().keySet ());
108
118
}
109
-
110
119
111
120
}
0 commit comments