diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc index e8b5f78d6c6..141883b620b 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 e51f66ab72e..c90a349aa75 100644 --- a/src/server/redis_connection.h +++ b/src/server/redis_connection.h @@ -86,6 +86,10 @@ class Connection : public EvbufCallbackBase { return protocol_version_ == RESP::v3 ? "%" + std::to_string(len) + CRLF : MultiLen(len * 2); } std::string MapOfBulkStrings(const std::vector &elems) const; + template , int> = 0> + std::string HeaderOfAttribute(T len) const { + return "|" + std::to_string(len) + CRLF; + } using UnsubscribeCallback = std::function; 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 61db7cf1bf7..f2a3432dcb0 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}