From 7a5d858a573c59a16a73fa7139c9c2c06213aeab Mon Sep 17 00:00:00 2001 From: Catcher Wong Date: Sat, 28 Sep 2024 22:52:00 +0800 Subject: [PATCH] minor changes to support valkey (#68) --- src/RDBCli/Callbacks/MemoryCallback.cs | 6 ++++++ src/RDBCli/Commands/MemoryCommand.cs | 2 ++ src/RDBCli/Helpers/CommonHelper.Const.cs | 4 ++-- src/RDBCli/Stats/RdbDataInfo.cs | 5 +++++ src/RDBCli/Tpl/tpl.html | 3 ++- src/RDBParser/Constant.cs | 7 +++---- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/RDBCli/Callbacks/MemoryCallback.cs b/src/RDBCli/Callbacks/MemoryCallback.cs index 5bdbff9..747dc19 100644 --- a/src/RDBCli/Callbacks/MemoryCallback.cs +++ b/src/RDBCli/Callbacks/MemoryCallback.cs @@ -49,11 +49,17 @@ public void AuxField(byte[] key, byte[] value) else if (keyStr.Equals("redis-bits")) { _rdbDataInfo.RedisBits = RedisRdbObjectHelper.ConvertBytesToInteger(value); + _rdbDataInfo.RedisType = "Redis"; } else if (keyStr.Equals("ctime")) { _rdbDataInfo.CTime = RedisRdbObjectHelper.ConvertBytesToInteger(value); } + else if (keyStr.Equals("valkey-ver")) + { + _rdbDataInfo.RedisVer = System.Text.Encoding.UTF8.GetString(value); + _rdbDataInfo.RedisType = "Valkey"; + } } public void DbSize(uint dbSize, uint expiresSize) diff --git a/src/RDBCli/Commands/MemoryCommand.cs b/src/RDBCli/Commands/MemoryCommand.cs index d4d4655..6cd810e 100644 --- a/src/RDBCli/Commands/MemoryCommand.cs +++ b/src/RDBCli/Commands/MemoryCommand.cs @@ -240,6 +240,7 @@ public class MemoryAnslysisResult public int count { get; set; } public int rdbVer { get; set; } public string redisVer { get; set; } + public string redisType { get; set; } public long redisBits { get; set; } public int expCount { get; set; } public int permCount { get; set; } @@ -265,6 +266,7 @@ internal static MemoryAnslysisResult BuildBasicFromRdbDataInfo(RdbDataInfo rdbDa redisVer = string.IsNullOrWhiteSpace(rdbDataInfo.RedisVer) ? CommonHelper.GetFuzzyRedisVersion(rdbDataInfo.RdbVer) : rdbDataInfo.RedisVer, redisBits = rdbDataInfo.RedisBits, functions = rdbDataInfo.Functions, + redisType = rdbDataInfo.RedisType, }; return result; diff --git a/src/RDBCli/Helpers/CommonHelper.Const.cs b/src/RDBCli/Helpers/CommonHelper.Const.cs index 13b5e61..fe92df1 100644 --- a/src/RDBCli/Helpers/CommonHelper.Const.cs +++ b/src/RDBCli/Helpers/CommonHelper.Const.cs @@ -5,8 +5,8 @@ namespace RDBCli internal static partial 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


Expired Keys

Memory Usage by Expired Keys

Permanent Keys

Memory Usage by Permanent Keys


Details Information










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

Basic Information


RDB Version:
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"; diff --git a/src/RDBCli/Stats/RdbDataInfo.cs b/src/RDBCli/Stats/RdbDataInfo.cs index 12ee105..288d681 100644 --- a/src/RDBCli/Stats/RdbDataInfo.cs +++ b/src/RDBCli/Stats/RdbDataInfo.cs @@ -51,5 +51,10 @@ internal class RdbDataInfo /// The information about the functions and libraries /// public List Functions { get; set; } = new List(); + + /// + /// The information about the redis type, Redis or Valkey + /// + public string RedisType { get; set; } = "Redis"; } } diff --git a/src/RDBCli/Tpl/tpl.html b/src/RDBCli/Tpl/tpl.html index dc8d2af..762fd90 100644 --- a/src/RDBCli/Tpl/tpl.html +++ b/src/RDBCli/Tpl/tpl.html @@ -37,7 +37,7 @@

RDB Version:
- Redis Version: + Version:
@@ -168,6 +168,7 @@

$('#rdbVer').text(cliData.rdbVer); $('#redisVer').text(cliData.redisVer); + $('#redisType').text(cliData.redisType); $('#totalKeyBytes').text(formatBytes(cliData.usedMem)); $('#totalKeyNum').text(formatNumber(cliData.count)); $('#expKeyNum').text(formatNumber(cliData.expCount)); diff --git a/src/RDBParser/Constant.cs b/src/RDBParser/Constant.cs index 1ec1c00..a597eff 100755 --- a/src/RDBParser/Constant.cs +++ b/src/RDBParser/Constant.cs @@ -10,10 +10,9 @@ public static class RdbVersion public const int Min = 1; // Redis 6.2.14 9 - // Redis 7.0-rc1 10 - // Redis 7.0.15 10 - // Redis 7.2-rc1 11 - // Redis 7.2.4 11 + // Redis 7.0-rc1~~7.0.15 10 + // Redis 7.2-rc1~~7.4.0 11 + // Valkey 7.2.4-rc1~~8.0.0 11 public const int Max = 11; }