|
@@ -39,6 +39,11 @@ public class RedisTask extends Task { |
|
@@ -39,6 +39,11 @@ public class RedisTask extends Task { |
39
|
|
39
|
|
40
|
this.tUrl = tUrl;
|
40
|
this.tUrl = tUrl;
|
41
|
|
41
|
|
|
|
42
|
+ sureConnect();
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+
|
|
|
46
|
+ private void connect() {
|
42
|
try {
|
47
|
try {
|
43
|
client = new Jedis(this.getIp(), this.getPort(), 5 * 1000);
|
48
|
client = new Jedis(this.getIp(), this.getPort(), 5 * 1000);
|
44
|
|
49
|
|
|
@@ -50,7 +55,28 @@ public class RedisTask extends Task { |
|
@@ -50,7 +55,28 @@ public class RedisTask extends Task { |
50
|
|
55
|
|
51
|
client = null;
|
56
|
client = null;
|
52
|
}
|
57
|
}
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ private void sureConnect() {
|
|
|
61
|
+ DEBUG.info("start to connect to redis {},time {}", super.url, System.currentTimeMillis());
|
|
|
62
|
+
|
|
|
63
|
+ connect();
|
|
|
64
|
+
|
|
|
65
|
+ //等待两秒重连
|
|
|
66
|
+ try {
|
|
|
67
|
+
|
|
|
68
|
+ Thread.sleep(2 * 1000);
|
|
|
69
|
+
|
|
|
70
|
+ } catch (InterruptedException e) {
|
|
|
71
|
+
|
|
|
72
|
+ DEBUG.error("Failed to wait for reconnect to redis {}", super.url);
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ if (null == client || !client.isConnected()) {
|
|
|
76
|
+ connect();
|
|
|
77
|
+ }
|
53
|
|
78
|
|
|
|
79
|
+ DEBUG.info("End to connect to redis {},time {}", super.url, System.currentTimeMillis());
|
54
|
}
|
80
|
}
|
55
|
|
81
|
|
56
|
|
82
|
|