git-hulk commented on code in PR #3294:
URL: https://github.com/apache/kvrocks/pull/3294#discussion_r2619527842
##########
src/server/redis_connection.cc:
##########
@@ -68,9 +68,31 @@ Connection::~Connection() {
}
std::string Connection::ToString() {
- return fmt::format("id={} addr={} fd={} name={} age={} idle={} flags={}
namespace={} qbuf={} obuf={} cmd={}\n", id_,
- addr_, bufferevent_getfd(bev_), name_, GetAge(),
GetIdleTime(), GetFlags(), ns_,
- evbuffer_get_length(Input()),
evbuffer_get_length(Output()), last_cmd_);
+ std::string result;
+
+ // When redis-databases > 0 (SELECT compatibility mode), show db field
instead of namespace
+ if (srv_->GetConfig()->redis_databases > 0) {
+ // Parse db number from namespace (format: "db0001", "db0002", etc.)
+ int db_num = 0;
+ if (ns_ != kDefaultNamespace && ns_.size() >= 3 && ns_.substr(0, 2) ==
"db") {
+ try {
+ db_num = std::stoi(ns_.substr(2));
+ } catch (...) {
+ // If parsing fails, default to 0
+ db_num = 0;
+ }
Review Comment:
```suggestion
db_num = ParseInt<int>(ns_.substr(2), 10).ValueOr(0);
```
--
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]