Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of RESP3 attribute type #2088

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
4 changes: 4 additions & 0 deletions src/server/redis_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/gocase/unit/protocol/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
Loading