Skip to content

Commit

Permalink
support slotinfo 244
Browse files Browse the repository at this point in the history
Signed-off-by: catcherwong <[email protected]>
  • Loading branch information
catcherwong committed Oct 4, 2024
1 parent 702d263 commit 7887675
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/RDBCli/Callbacks/KeysOnlyCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,9 @@ public void ZAdd(byte[] key, double score, byte[] member)
public void SetIdleOrFreq(int val)
{
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}
}
}
4 changes: 4 additions & 0 deletions src/RDBCli/Callbacks/MemoryCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,9 @@ public void SetIdleOrFreq(int val)
{
_idleOrFreq = val;
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}
}
}
9 changes: 9 additions & 0 deletions src/RDBParser/BinaryReaderRDBParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public void Parse(string path)
}
}

if (opType == Constant.OpCode.SLOTINFO)
{
var slotId = br.ReadLength();
var slotSize = br.ReadLength();
var expireSlotSize = br.ReadLength();
_callback.SetSlotInfo(slotId, slotSize, expireSlotSize);
continue;
}

if (opType == Constant.OpCode.SELECTDB)
{
if (!isFirstDb)
Expand Down
5 changes: 5 additions & 0 deletions src/RDBParser/Callbacks/DefaultConsoleReaderCallBack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void SetIdleOrFreq(int val)
Console.WriteLine($"SetIdleOrFreq, val={val}");
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
Console.WriteLine($"SetSlotInfo, slotId={slotId}, slotSize={slotSize}, expireSlotSize={expireSlotSize}");
}

public void StartDatabase(int database)
{
Console.WriteLine($"Start database = {database}");
Expand Down
8 changes: 8 additions & 0 deletions src/RDBParser/Callbacks/IReaderCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,13 @@ public interface IReaderCallback
/// </summary>
/// <param name="val"></param>
void SetIdleOrFreq(int val);

/// <summary>
/// Record Slot Info
/// </summary>
/// <param name="slotId"></param>
/// <param name="slotSize"></param>
/// <param name="expireSlotSize"></param>
void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize);
}
}
4 changes: 4 additions & 0 deletions src/RDBParser/Callbacks/NoOpReaderCallBack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void SetIdleOrFreq(int val)
{
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}

public void StartDatabase(int database)
{
}
Expand Down
8 changes: 7 additions & 1 deletion src/RDBParser/Constant.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace RDBParser
using System.Dynamic;

namespace RDBParser
{
public static class Constant
{
Expand Down Expand Up @@ -31,6 +33,10 @@ public static class MagicCount

public static class OpCode
{
/// <summary>
/// Individual slot info, such as slot id and size (cluster mode only).
/// </summary>
public const int SLOTINFO = 244;
public const int FUNCTION2 = 245;
public const int FUNCTION = 246;
public const int MODULE_AUX = 247;
Expand Down
5 changes: 5 additions & 0 deletions tests/RDBParserTests/TestReaderCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,10 @@ public void SetIdleOrFreq(int val)
{
_idleOrFreq = val;
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
System.Diagnostics.Trace.WriteLine($"{slotId}, {slotSize}, {expireSlotSize}");
}
}
}

0 comments on commit 7887675

Please sign in to comment.