From 987777f9f0480938188727936fc2cf48551770fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9C=A0=EC=84=9D=28Yu=20Seok=20Kim=29?= Date: Sat, 23 Nov 2024 05:11:22 +0900 Subject: [PATCH] Fix Bugs, Caused by Hello Respones Types #811 (#818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Bugs, Caused by Hello Respones Types #811 * Fix: RespTests.cs update NewlineCount 바뀌었어요 --- libs/server/Resp/BasicCommands.cs | 18 +++++++++++++----- test/Garnet.test/RespTests.cs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/server/Resp/BasicCommands.cs b/libs/server/Resp/BasicCommands.cs index 0e5406c731..ba2c65fce4 100644 --- a/libs/server/Resp/BasicCommands.cs +++ b/libs/server/Resp/BasicCommands.cs @@ -1463,13 +1463,13 @@ void ProcessHelloCommand(byte? respProtocolVersion, ReadOnlySpan username, this.clientName = clientName; } - (string, string)[] helloResult = + (string, object)[] helloResult = [ ("server", "redis"), ("version", storeWrapper.redisProtocolVersion), ("garnet_version", storeWrapper.version), - ("proto", $"{this.respProtocolVersion}"), - ("id", "63"), + ("proto", this.respProtocolVersion), + ("id", 63), ("mode", storeWrapper.serverOptions.EnableCluster ? "cluster" : "standalone"), ("role", storeWrapper.serverOptions.EnableCluster && storeWrapper.clusterProvider.IsReplica() ? "replica" : "master"), ]; @@ -1488,8 +1488,16 @@ void ProcessHelloCommand(byte? respProtocolVersion, ReadOnlySpan username, { while (!RespWriteUtils.WriteAsciiBulkString(helloResult[i].Item1, ref dcurr, dend)) SendAndReset(); - while (!RespWriteUtils.WriteAsciiBulkString(helloResult[i].Item2, ref dcurr, dend)) - SendAndReset(); + if (helloResult[i].Item2 is int intValue) + { + while (!RespWriteUtils.WriteInteger(intValue, ref dcurr, dend)) + SendAndReset(); + } + else + { + while (!RespWriteUtils.WriteAsciiBulkString(helloResult[i].Item2.ToString(), ref dcurr, dend)) + SendAndReset(); + } } while (!RespWriteUtils.WriteAsciiBulkString("modules", ref dcurr, dend)) SendAndReset(); diff --git a/test/Garnet.test/RespTests.cs b/test/Garnet.test/RespTests.cs index d49c8c48e1..e945a44f71 100644 --- a/test/Garnet.test/RespTests.cs +++ b/test/Garnet.test/RespTests.cs @@ -3420,7 +3420,7 @@ public void AsyncTest1() // We use newline counting for HELLO response as the exact length can vary slightly across versions using var lightClientRequest = TestUtils.CreateRequest(countResponseType: CountResponseType.Newlines); - var expectedNewlineCount = 32; // 32 '\n' characters expected in response + var expectedNewlineCount = 30; // 30 '\n' characters expected in response var response = lightClientRequest.Execute($"hello 3", expectedNewlineCount); ClassicAssert.IsTrue(response.Length is > 180 and < 190);