diff --git a/src/redis_cmd.cc b/src/redis_cmd.cc index febe5e9b823..92023e669eb 100644 --- a/src/redis_cmd.cc +++ b/src/redis_cmd.cc @@ -242,7 +242,13 @@ class CommandFlushAll : public Commander { class CommandPing : public Commander { public: Status Execute(Server *svr, Connection *conn, std::string *output) override { - *output = Redis::SimpleString("PONG"); + if (args_.size() == 1) { + *output = Redis::SimpleString("PONG"); + } else if (args_.size() == 2) { + *output = Redis::BulkString(args_[1]); + } else { + return Status(Status::NotOK, errWrongNumOfArguments); + } return Status::OK(); } }; @@ -5833,7 +5839,7 @@ class CommandXTrim : public Commander { CommandAttributes redisCommandTable[] = { ADD_CMD("auth", 2, "read-only ok-loading", 0, 0, 0, CommandAuth), - ADD_CMD("ping", 1, "read-only", 0, 0, 0, CommandPing), + ADD_CMD("ping", -1, "read-only", 0, 0, 0, CommandPing), ADD_CMD("select", 2, "read-only", 0, 0, 0, CommandSelect), ADD_CMD("info", -1, "read-only ok-loading", 0, 0, 0, CommandInfo), ADD_CMD("role", 1, "read-only ok-loading", 0, 0, 0, CommandRole), diff --git a/tests/gocase/unit/introspection/introspection_test.go b/tests/gocase/unit/introspection/introspection_test.go new file mode 100644 index 00000000000..29da8b60eb3 --- /dev/null +++ b/tests/gocase/unit/introspection/introspection_test.go @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package command + +import ( + "testing" + + "github.com/apache/incubator-kvrocks/tests/gocase/util" + "github.com/stretchr/testify/require" +) + +func TestIntrospection(t *testing.T) { + srv := util.StartServer(t, map[string]string{}) + defer srv.Close() + + t.Run("PING", func(t *testing.T) { + c := srv.NewTCPClient() + defer func() { require.NoError(t, c.Close()) }() + require.NoError(t, c.WriteArgs("PING")) + r, err := c.ReadLine() + require.NoError(t, err) + require.Equal(t, r, "+PONG") + require.NoError(t, c.WriteArgs("PING", "PONG")) + r, err = c.ReadLine() + require.NoError(t, err) + require.Equal(t, r, "$4") + r, err = c.ReadLine() + require.NoError(t, err) + require.Equal(t, r, "PONG") + require.NoError(t, c.WriteArgs("ping", "hello", "redis")) + r, err = c.ReadLine() + require.NoError(t, err) + require.Equal(t, r, "-ERR wrong number of arguments") + }) +}