From 90600751324545b8b8fa053fedfcbafd295f3694 Mon Sep 17 00:00:00 2001 From: Ondrej Babec Date: Mon, 13 May 2024 09:01:36 +0200 Subject: [PATCH] Redis flush --- database-manipulation-tool/README.md | 5 +++++ .../main/java/io/skodjob/dmt/resource/RedisResource.java | 7 +++++++ .../src/main/java/io/skodjob/dmt/service/RedisService.java | 4 ++++ .../java/io/skodjob/dmt/sinkSources/RedisDataSource.java | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/database-manipulation-tool/README.md b/database-manipulation-tool/README.md index 4461b02..936af68 100644 --- a/database-manipulation-tool/README.md +++ b/database-manipulation-tool/README.md @@ -118,6 +118,11 @@ You can reset all databases on DMT start with property `onstart.reset.database`. Sends a message specified in json body to the redis stream channel specified in as header argument + + GET + /Redis/reset + Flush whole Redis instance + ## Running the application in dev mode diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/resource/RedisResource.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/resource/RedisResource.java index ff16fc0..ef3dc4a 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/resource/RedisResource.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/resource/RedisResource.java @@ -72,4 +72,11 @@ public Response pollMessages(@QueryParam("max") Integer max, List channe return Response.ok(res).build(); } + @Path("reset") + @GET + public Response resetRedis() { + redisService.resetRedis(); + return Response.ok().build(); + } + } diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/RedisService.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/RedisService.java index 8fd0f2a..ca5ab5e 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/RedisService.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/service/RedisService.java @@ -51,4 +51,8 @@ public String insert(String channel, Map message) { public List>> get(int amount, List channels) { return redisDataSource.pollMessages(amount, channels); } + + public void resetRedis() { + redisDataSource.flushRedis(); + } } diff --git a/database-manipulation-tool/src/main/java/io/skodjob/dmt/sinkSources/RedisDataSource.java b/database-manipulation-tool/src/main/java/io/skodjob/dmt/sinkSources/RedisDataSource.java index d7b77bb..469e1ad 100644 --- a/database-manipulation-tool/src/main/java/io/skodjob/dmt/sinkSources/RedisDataSource.java +++ b/database-manipulation-tool/src/main/java/io/skodjob/dmt/sinkSources/RedisDataSource.java @@ -78,4 +78,9 @@ public List>> pollMessages(int maxAmount, Li return jedis.xread(XReadParams.xReadParams().count(maxAmount), streams); } + public void flushRedis() { + Jedis jedis = pool.getResource(); + jedis.flushAll(); + } + }