PragmaTwice commented on code in PR #3294:
URL: https://github.com/apache/kvrocks/pull/3294#discussion_r2619645681


##########
src/commands/cmd_server.cc:
##########
@@ -201,8 +204,32 @@ class CommandPing : public Commander {
 
 class CommandSelect : public Commander {
  public:
-  Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] 
Server *srv, [[maybe_unused]] Connection *conn,
-                 std::string *output) override {
+  Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, 
Connection *conn, std::string *output) override {
+    Config *config = srv->GetConfig();
+    // If redis-databases is 0, just return OK (default behavior)
+    if (config->redis_databases == 0) {
+      *output = redis::RESP_OK;
+      return Status::OK();
+    }
+
+    // Parse database index
+    auto parse_result = ParseInt<int>(args_[1], 10);
+    if (!parse_result) {
+      return {Status::RedisParseErr, "Invalid DB index"};
+    }
+    int db_index = *parse_result;
+    // Validate database index range
+    if (db_index < 0 || db_index >= config->redis_databases) {
+      return {Status::RedisParseErr, "Invalid DB index"};

Review Comment:
   ```suggestion
         return {Status::RedisParseErr, "DB number is out of range"};
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to