mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-15 17:51:06 +00:00
Update response to HELLO command (#102)
* Update response to HELLO command
Update response from HELLO command to match the api of redis.
Notes:
- For any protocol version other than 2 an error matching what redis
returns for !2,3 is returned
* Add test for redis HELLO command
* Extract version building to GetVersion function
* Update contributors file
* Add HELLO command to README readiness matrix
* Revert "Add HELLO command to README readiness matrix"
This reverts commit 069f590ad0
.
* Add HELLO command to api_status document
This commit is contained in:
parent
1fe3862e57
commit
2caa2b0df2
8 changed files with 50 additions and 3 deletions
|
@ -4,3 +4,4 @@
|
||||||
* Helm Chart
|
* Helm Chart
|
||||||
* **[Ryan Russell](https://github.com/ryanrussell)**
|
* **[Ryan Russell](https://github.com/ryanrussell)**
|
||||||
* Docs & Code Readability
|
* Docs & Code Readability
|
||||||
|
* **[Ali-Akber Saifee](https://github.com/alisaifee)**
|
||||||
|
|
|
@ -57,6 +57,7 @@ with respect to Memcached and Redis APIs.
|
||||||
- [X] EXEC
|
- [X] EXEC
|
||||||
- [X] FLUSHALL
|
- [X] FLUSHALL
|
||||||
- [X] FLUSHDB
|
- [X] FLUSHDB
|
||||||
|
- [X] HELLO
|
||||||
- [X] INFO
|
- [X] INFO
|
||||||
- [X] MULTI
|
- [X] MULTI
|
||||||
- [X] SHUTDOWN
|
- [X] SHUTDOWN
|
||||||
|
|
|
@ -284,6 +284,10 @@ string Connection::GetClientInfo() const {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 Connection::GetClientId() const {
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
io::Result<bool> Connection::CheckForHttpProto(FiberSocketBase* peer) {
|
io::Result<bool> Connection::CheckForHttpProto(FiberSocketBase* peer) {
|
||||||
size_t last_len = 0;
|
size_t last_len = 0;
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -70,6 +70,7 @@ class Connection : public util::Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetClientInfo() const;
|
std::string GetClientInfo() const;
|
||||||
|
uint32 GetClientId() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnShutdown() override;
|
void OnShutdown() override;
|
||||||
|
|
|
@ -294,6 +294,20 @@ TEST_F(DflyEngineTest, EvalResp) {
|
||||||
EXPECT_THAT(resp.GetVec(), ElementsAre(IntArg(5), "foo", "17.5"));
|
EXPECT_THAT(resp.GetVec(), ElementsAre(IntArg(5), "foo", "17.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DflyEngineTest, Hello) {
|
||||||
|
auto resp_no_param = Run({"hello"});
|
||||||
|
ASSERT_THAT(resp_no_param, ArrLen(12));
|
||||||
|
|
||||||
|
auto resp = Run({"hello", "2"});
|
||||||
|
ASSERT_THAT(resp, ArrLen(12));
|
||||||
|
EXPECT_THAT(resp.GetVec(),
|
||||||
|
ElementsAre("server", "redis", "version", "df-dev", "proto",
|
||||||
|
IntArg(2), "id", ArgType(RespExpr::INT64), "mode",
|
||||||
|
"standalone", "role", "master"));
|
||||||
|
|
||||||
|
EXPECT_THAT(Run({"hello", "3"}), ErrArg("ERR NOPROTO unsupported protocol"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DflyEngineTest, EvalSha) {
|
TEST_F(DflyEngineTest, EvalSha) {
|
||||||
auto resp = Run({"script", "load", "return 5"});
|
auto resp = Run({"script", "load", "return 5"});
|
||||||
EXPECT_THAT(resp, ArgType(RespExpr::STRING));
|
EXPECT_THAT(resp, ArgType(RespExpr::STRING));
|
||||||
|
|
|
@ -777,7 +777,7 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
|
||||||
if (should_enter("SERVER")) {
|
if (should_enter("SERVER")) {
|
||||||
ADD_HEADER("# Server");
|
ADD_HEADER("# Server");
|
||||||
|
|
||||||
append("redis_version", StrCat("df-", kGitTag));
|
append("redis_version", GetVersion());
|
||||||
append("redis_mode", "standalone");
|
append("redis_mode", "standalone");
|
||||||
append("arch_bits", 64);
|
append("arch_bits", 64);
|
||||||
append("multiplexing_api", "iouring");
|
append("multiplexing_api", "iouring");
|
||||||
|
@ -950,7 +950,29 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerFamily::Hello(CmdArgList args, ConnectionContext* cntx) {
|
void ServerFamily::Hello(CmdArgList args, ConnectionContext* cntx) {
|
||||||
return (*cntx)->SendOk();
|
if (args.size() > 1) {
|
||||||
|
string_view proto_version = ArgS(args, 1);
|
||||||
|
|
||||||
|
if (proto_version != "2") {
|
||||||
|
(*cntx)->SendError("NOPROTO unsupported protocol version");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(*cntx)->StartArray(12);
|
||||||
|
(*cntx)->SendBulkString("server");
|
||||||
|
(*cntx)->SendBulkString("redis");
|
||||||
|
(*cntx)->SendBulkString("version");
|
||||||
|
(*cntx)->SendBulkString(GetVersion());
|
||||||
|
(*cntx)->SendBulkString("proto");
|
||||||
|
(*cntx)->SendLong(2);
|
||||||
|
(*cntx)->SendBulkString("id");
|
||||||
|
(*cntx)->SendLong(cntx->owner()->GetClientId());
|
||||||
|
(*cntx)->SendBulkString("mode");
|
||||||
|
(*cntx)->SendBulkString("standalone");
|
||||||
|
(*cntx)->SendBulkString("role");
|
||||||
|
(*cntx)->SendBulkString((*ServerState::tlocal()).is_master ? "master" : "slave");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerFamily::ReplicaOf(CmdArgList args, ConnectionContext* cntx) {
|
void ServerFamily::ReplicaOf(CmdArgList args, ConnectionContext* cntx) {
|
||||||
|
|
|
@ -13,4 +13,6 @@ const char kGitSha[] = "@GIT_SHA1@";
|
||||||
const char kGitClean[] = "@GIT_CLEAN_DIRTY@";
|
const char kGitClean[] = "@GIT_CLEAN_DIRTY@";
|
||||||
const char kBuildTime[] = "@PRJ_BUILD_TIME@";
|
const char kBuildTime[] = "@PRJ_BUILD_TIME@";
|
||||||
|
|
||||||
|
const char* GetVersion() { return "df-@GIT_VER@"; }
|
||||||
|
|
||||||
} // namespace dfly
|
} // namespace dfly
|
||||||
|
|
|
@ -11,4 +11,6 @@ extern const char kGitSha[];
|
||||||
extern const char kGitClean[];
|
extern const char kGitClean[];
|
||||||
extern const char kBuildTime[];
|
extern const char kBuildTime[];
|
||||||
|
|
||||||
|
const char* GetVersion();
|
||||||
|
|
||||||
} // namespace dfly
|
} // namespace dfly
|
||||||
|
|
Loading…
Reference in a new issue