-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRedisCommand.java
67 lines (56 loc) · 1.75 KB
/
RedisCommand.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.db.redis;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
import sirius.kernel.health.console.Command;
import javax.annotation.Nonnull;
import java.util.Map;
/**
* Reports all available statistics for Redis.
*/
@Register
public class RedisCommand implements Command {
@Part
private Redis redis;
@Override
public void execute(Output output, String... params) throws Exception {
if (!redis.isConfigured()) {
output.line("Redis is not configured...");
return;
}
if (params.length > 1 && "unlock".equals(params[0])) {
output.line("Killing lock: " + params[1]);
redis.unlock(params[1], true);
}
output.line("Redis Statistics");
output.separator();
for (Map.Entry<String, String> e : redis.getInfo().entrySet()) {
output.apply("%-40s %40s", e.getKey(), e.getValue());
}
output.blankLine();
output.line("Redis Locks (use redis unlock <lock> to forcefully remove a lock)");
output.separator();
for (Redis.LockInfo info : redis.getLockList()) {
output.apply("%-45s %-5s %-25s %-15s",
info.name,
info.value,
info.since != null ? info.since.toString() : "-",
info.ttl != null ? info.ttl + "s" : "-");
}
}
@Override
public String getDescription() {
return "Reports statistics for Redis";
}
@Nonnull
@Override
public String getName() {
return "redis";
}
}