Implemented MONITOR
This commit is contained in:
@@ -535,4 +535,8 @@ public class Client extends Connection {
|
||||
public void info() {
|
||||
sendCommand("INFO");
|
||||
}
|
||||
|
||||
public void monitor() {
|
||||
sendCommand("MONITOR");
|
||||
}
|
||||
}
|
||||
@@ -68,12 +68,16 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
public void disconnect() {
|
||||
if (connected) {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
if (!socket.isClosed()) {
|
||||
socket.close();
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
if (!socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
connected = false;
|
||||
}
|
||||
|
||||
@@ -638,4 +638,9 @@ public class Jedis {
|
||||
client.info();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
public void monitor(JedisMonitor jedisMonitor) {
|
||||
client.monitor();
|
||||
jedisMonitor.proceed(client);
|
||||
}
|
||||
}
|
||||
15
src/main/java/redis/clients/jedis/JedisMonitor.java
Normal file
15
src/main/java/redis/clients/jedis/JedisMonitor.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public abstract class JedisMonitor {
|
||||
protected Client client;
|
||||
|
||||
public void proceed(Client client) {
|
||||
this.client = client;
|
||||
do {
|
||||
String command = client.getBulkReply();
|
||||
onCommand(command);
|
||||
} while (client.isConnected());
|
||||
}
|
||||
|
||||
public abstract void onCommand(String command);
|
||||
}
|
||||
Reference in New Issue
Block a user