This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 4a1a1be8 Add support of RESP3 attribute type (#2088)
4a1a1be8 is described below

commit 4a1a1be807b1caeea517e0b5882ef07476f30eb6
Author: hulk <[email protected]>
AuthorDate: Mon Feb 5 11:36:37 2024 +0800

    Add support of RESP3 attribute type (#2088)
---
 src/commands/cmd_server.cc                  | 9 ++++++++-
 src/server/redis_connection.h               | 4 ++++
 tests/gocase/unit/protocol/protocol_test.go | 2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc
index e8b5f78d..141883b6 100644
--- a/src/commands/cmd_server.cc
+++ b/src/commands/cmd_server.cc
@@ -641,10 +641,17 @@ class CommandDebug : public Commander {
         *output = conn->Bool(false);
       } else if (protocol_type_ == "null") {
         *output = conn->NilString();
+      } else if (protocol_type_ == "attrib") {
+        *output = conn->HeaderOfAttribute(1);
+        *output += redis::BulkString("key-popularity");
+        *output += redis::Array({
+            redis::BulkString("key:123"),
+            redis::Integer(90),
+        });
       } else {
         *output = redis::Error(
             "Wrong protocol type name. Please use one of the following: "
-            "string|integer|double|array|set|bignum|true|false|null");
+            "string|integer|double|array|set|bignum|true|false|null|attrib");
       }
     } else if (subcommand_ == "dbsize-limit") {
       srv->storage->SetDBSizeLimit(dbsize_limit_);
diff --git a/src/server/redis_connection.h b/src/server/redis_connection.h
index e51f66ab..c90a349a 100644
--- a/src/server/redis_connection.h
+++ b/src/server/redis_connection.h
@@ -86,6 +86,10 @@ class Connection : public EvbufCallbackBase<Connection> {
     return protocol_version_ == RESP::v3 ? "%" + std::to_string(len) + CRLF : 
MultiLen(len * 2);
   }
   std::string MapOfBulkStrings(const std::vector<std::string> &elems) const;
+  template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>
+  std::string HeaderOfAttribute(T len) const {
+    return "|" + std::to_string(len) + CRLF;
+  }
 
   using UnsubscribeCallback = std::function<void(std::string, int)>;
   void SubscribeChannel(const std::string &channel);
diff --git a/tests/gocase/unit/protocol/protocol_test.go 
b/tests/gocase/unit/protocol/protocol_test.go
index 61db7cf1..f2a3432d 100644
--- a/tests/gocase/unit/protocol/protocol_test.go
+++ b/tests/gocase/unit/protocol/protocol_test.go
@@ -161,6 +161,7 @@ func TestProtocolRESP2(t *testing.T) {
                        "true":    {":1"},
                        "false":   {":0"},
                        "null":    {"$-1"},
+                       "attrib":  {"|1", "$14", "key-popularity", "*2", "$7", 
"key:123", ":90"},
                }
                for typ, expected := range types {
                        args := []string{"DEBUG", "PROTOCOL", typ}
@@ -217,6 +218,7 @@ func TestProtocolRESP3(t *testing.T) {
                        "true":    {"#t"},
                        "false":   {"#f"},
                        "null":    {"_"},
+                       "attrib":  {"|1", "$14", "key-popularity", "*2", "$7", 
"key:123", ":90"},
                }
                for typ, expected := range types {
                        args := []string{"DEBUG", "PROTOCOL", typ}

Reply via email to