From 2cf09579e7ea6b10a1a31f11e70f03521a4e8911 Mon Sep 17 00:00:00 2001 From: Catcher Wong Date: Fri, 17 Nov 2023 00:43:29 +0000 Subject: [PATCH] basic info add exp and perm keys related (#49) * basic info add exp and perm keys related * update cli version to 0.8.1 --------- Signed-off-by: catcherwong --- build/version.props | 2 +- src/RDBCli/Commands/MemoryCommand.cs | 12 +++++++++ src/RDBCli/Helpers/CommonHelper.cs | 20 ++++++++------ src/RDBCli/Tpl/tpl.html | 39 ++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/build/version.props b/build/version.props index f799351..de1f871 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 0.6.0 - 0.8.0 + 0.8.1 \ No newline at end of file diff --git a/src/RDBCli/Commands/MemoryCommand.cs b/src/RDBCli/Commands/MemoryCommand.cs index 231e788..5348e0a 100644 --- a/src/RDBCli/Commands/MemoryCommand.cs +++ b/src/RDBCli/Commands/MemoryCommand.cs @@ -4,6 +4,7 @@ using System.CommandLine.Invocation; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text.Json; using CliCB = RDBCli.Callbacks; @@ -88,6 +89,13 @@ private void Do(InvocationContext context, CommandOptions options) dict.expiryInfo = expiryInfo; dict.largestStreams = streamRecords; + var exp = expiryInfo.FirstOrDefault(x => x.Expiry.Equals(CommonHelper.AlreadyExpired)); + var perm = expiryInfo.FirstOrDefault(x => x.Expiry.Equals(CommonHelper.Permanent)); + dict.expCount = (int)(exp?.Num ?? 0); + dict.expMem = (long)(exp?.Bytes ?? 0); + dict.permCount = (int)(perm?.Num ?? 0); + dict.permMem = (long)(perm?.Bytes ?? 0); + var path = WriteFile(dict, options.Output, options.OutputType); sw.Stop(); @@ -213,6 +221,10 @@ public class MemoryAnslysisResult public int rdbVer { get; set; } public string redisVer { get; set; } public long redisBits { get; set; } + public int expCount { get; set; } + public int permCount { get; set; } + public long expMem { get; set; } + public long permMem { get; set; } public List typeRecords { get; set; } public List largestRecords { get; set; } public List largestKeyPrefix { get; set; } diff --git a/src/RDBCli/Helpers/CommonHelper.cs b/src/RDBCli/Helpers/CommonHelper.cs index 3293f4c..49e8f0b 100644 --- a/src/RDBCli/Helpers/CommonHelper.cs +++ b/src/RDBCli/Helpers/CommonHelper.cs @@ -5,8 +5,12 @@ namespace RDBCli internal static class CommonHelper { // compress Tpl/tpl.html to get this value. - internal const string TplHtmlString = "rdb-cli,offline key analysis

Basic Information


RDB Version:
Redis Version:

Total Memory Usage of Keys

Total Number of Keys


Details Information






" + - ""; + internal const string TplHtmlString = "rdb-cli,offline key analysis

Basic Information


RDB Version:
Redis Version:

Total Memory Usage of Keys

Total Number of Keys


Expired Keys

Memory Usage by Expired Keys

Permanent Keys

Memory Usage by Permanent Keys


Details Information






" + + "" + + ""; + + internal const string AlreadyExpired = "Already Expired"; + internal const string Permanent = "Permanent"; /// /// Get a fuzzy redis version from a rdb version. @@ -46,7 +50,7 @@ internal static string GetFuzzyRedisVersion(int rdbVer) { ver = "2.x"; } - + return ver; } @@ -62,7 +66,7 @@ internal static string GetExpireString(long exp) var hour = sub.TotalHours; if (hour <= 0) { - res = "Already Expired"; + res = AlreadyExpired; } else if (hour > 0 && hour < 1) { @@ -95,23 +99,23 @@ internal static string GetExpireString(long exp) } else if (exp == 0) { - res = "Permanent"; + res = Permanent; } return res; } - + internal const char SplitChar = ':'; internal static string GetShortKey(string key) { var len = key.Length; - if(len > 1024) + if (len > 1024) { var span = key.AsSpan(); var b = span.Slice(0, 10).ToString(); - var e = span.Slice(len - 6 , 5).ToString(); + var e = span.Slice(len - 6, 5).ToString(); var n = $"{b}...({len - 15} more bytes)...{e}"; return n; diff --git a/src/RDBCli/Tpl/tpl.html b/src/RDBCli/Tpl/tpl.html index 62c17d9..7e04325 100644 --- a/src/RDBCli/Tpl/tpl.html +++ b/src/RDBCli/Tpl/tpl.html @@ -60,6 +60,41 @@


+
+
+
+
+
+

Expired Keys

+
+
+
+
+
+
+
+

Memory Usage by Expired Keys

+
+
+
+
+
+
+
+

Permanent Keys

+
+
+
+
+
+
+
+

Memory Usage by Permanent Keys

+
+
+
+
+