From 4d0461b74561815387b7944b7d94fe567dd1571c Mon Sep 17 00:00:00 2001 From: carrot Date: Wed, 21 Feb 2024 23:00:14 +0300 Subject: [PATCH] add LatencyEvent class --- src/main/java/redis/clients/jedis/Jedis.java | 4 ++-- .../java/redis/clients/jedis/Protocol.java | 20 ---------------- .../clients/jedis/args/LatencyEvent.java | 24 +++++++++++++++++++ .../jedis/commands/ServerCommands.java | 6 ++--- .../commands/jedis/ControlCommandsTest.java | 3 ++- 5 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/args/LatencyEvent.java diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f70a09d271..8595a14de7 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -9287,13 +9287,13 @@ public Map latencyLatest() { return BuilderFactory.LATENCY_LATEST_RESPONSE.build(connection.getOne()); } - public List latencyHistory(EventKeyword event) { + public List latencyHistory(LatencyEvent event) { checkIsInMultiOrPipeline(); connection.sendCommand(new CommandArguments(LATENCY).add(HISTORY).add(event)); return BuilderFactory.LATENCY_HISTORY_RESPONSE.build(connection.getOne()); } - public long latencyReset(EventKeyword... events) { + public long latencyReset(LatencyEvent... events) { checkIsInMultiOrPipeline(); CommandArguments arguments = new CommandArguments(LATENCY).add(Keyword.RESET); Arrays.stream(events).forEach(arguments::add); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 8109760fa8..24830637fb 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -371,24 +371,4 @@ public byte[] getRaw() { return raw; } } - - public static enum EventKeyword implements Rawable { - ACTIVE_DEFRAG_CYCLE("active-defrag-cycle"), AOF_FSYNC_ALWAYS("aof-fsync-always"), AOF_STAT("aof-stat"), - AOF_REWRITE_DIFF_WRITE("aof-rewrite-diff-write"), AOF_RENAME("aof-rename"), AOF_WRITE("aof-write"), - AOF_WRITE_ACTIVE_CHILD("aof-write-active-child"), AOF_WRITE_ALONE("aof-write-alone"), - AOF_WRITE_PENDING_FSYNC("aof-write-pending-fsync"), COMMAND("command"), EXPIRE_CYCLE("expire-cycle"), - EVICTION_CYCLE("eviction-cycle"), EVICTION_DEL("eviction-del"), FAST_COMMAND("fast-command"), - FORK("fork"), RDB_UNLINK_TEMP_FILE("rdb-unlink-temp-file"); - - private final byte[] raw; - - EventKeyword(String s) { - raw = SafeEncoder.encode(s); - } - - @Override - public byte[] getRaw() { - return raw; - } - } } diff --git a/src/main/java/redis/clients/jedis/args/LatencyEvent.java b/src/main/java/redis/clients/jedis/args/LatencyEvent.java new file mode 100644 index 0000000000..be82e6c25e --- /dev/null +++ b/src/main/java/redis/clients/jedis/args/LatencyEvent.java @@ -0,0 +1,24 @@ +package redis.clients.jedis.args; + +import redis.clients.jedis.util.SafeEncoder; + +public enum LatencyEvent implements Rawable { + + ACTIVE_DEFRAG_CYCLE("active-defrag-cycle"), AOF_FSYNC_ALWAYS("aof-fsync-always"), AOF_STAT("aof-stat"), + AOF_REWRITE_DIFF_WRITE("aof-rewrite-diff-write"), AOF_RENAME("aof-rename"), AOF_WRITE("aof-write"), + AOF_WRITE_ACTIVE_CHILD("aof-write-active-child"), AOF_WRITE_ALONE("aof-write-alone"), + AOF_WRITE_PENDING_FSYNC("aof-write-pending-fsync"), COMMAND("command"), EXPIRE_CYCLE("expire-cycle"), + EVICTION_CYCLE("eviction-cycle"), EVICTION_DEL("eviction-del"), FAST_COMMAND("fast-command"), + FORK("fork"), RDB_UNLINK_TEMP_FILE("rdb-unlink-temp-file"); + + private final byte[] raw; + + LatencyEvent(String s) { + raw = SafeEncoder.encode(s); + } + + @Override + public byte[] getRaw() { + return raw; + } +} diff --git a/src/main/java/redis/clients/jedis/commands/ServerCommands.java b/src/main/java/redis/clients/jedis/commands/ServerCommands.java index 9115ea433f..3aeff1153b 100644 --- a/src/main/java/redis/clients/jedis/commands/ServerCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ServerCommands.java @@ -1,7 +1,7 @@ package redis.clients.jedis.commands; -import redis.clients.jedis.Protocol; import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.LatencyEvent; import redis.clients.jedis.args.SaveMode; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.params.LolwutParams; @@ -255,7 +255,7 @@ default void shutdown(SaveMode saveMode) throws JedisException { Map latencyLatest(); - List latencyHistory(Protocol.EventKeyword events); + List latencyHistory(LatencyEvent events); - long latencyReset(Protocol.EventKeyword... events); + long latencyReset(LatencyEvent... events); } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java index 2cfff1e706..cb95a9489b 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java @@ -30,6 +30,7 @@ import redis.clients.jedis.JedisMonitor; import redis.clients.jedis.Protocol; import redis.clients.jedis.args.ClientPauseMode; +import redis.clients.jedis.args.LatencyEvent; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.HostAndPorts; import redis.clients.jedis.params.CommandListFilterByParams; @@ -450,7 +451,7 @@ public void latencyLatest() { @Test public void latencyHistoryFork() { - List report = jedis.latencyHistory(Protocol.EventKeyword.FORK); + List report = jedis.latencyHistory(LatencyEvent.FORK); assertNotNull(report); }