|
@@ -1,10 +1,33 @@
|
|
|
package com.alvin;
|
|
|
|
|
|
|
|
|
-import com.alvin.util.NumberUtil;
|
|
|
+import redis.clients.jedis.*;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
public class Application {
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+
|
|
|
+ Set<String> hosts = new HashSet<>();
|
|
|
+ hosts.add("127.0.0.1:26379");
|
|
|
+ //hosts.add("127.0.0.1:36379"); 配置多个哨兵
|
|
|
+
|
|
|
+ JedisSentinelPool pool = new JedisSentinelPool("mymaster", hosts);
|
|
|
+ pool.setMaxTotal(10);
|
|
|
+ Jedis jedis = null;
|
|
|
|
|
|
+ for (int i = 0; i < 20; i++) {
|
|
|
+ Thread.sleep(2000);
|
|
|
+ try {
|
|
|
+ jedis = pool.getResource();
|
|
|
+ String v = "hi" + i;
|
|
|
+ jedis.set("hello", v);
|
|
|
+ System.out.println(v + "-->" + jedis.get("hello").equals(v));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(" [ exception happened]" + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|