Skip to content

Commit

Permalink
Optimize AUTH request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Oct 31, 2023
1 parent df4082f commit 1d434f3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/factory/RedisTaskImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,31 @@ CommMessageOut *ComplexRedisTask::message_out()

if (seqid <= 1)
{
if (seqid == 0 && (!username_.empty() || !password_.empty()))
if (seqid == 0 && (!password_.empty() || !username_.empty()))
{
succ_ = false;
is_user_request_ = false;
auto *auth_req = new RedisRequest;

if (!username_.empty())
auth_req->set_request("AUTH", {username_, password_});
else
auth_req->set_request("AUTH", {password_});

succ_ = false;
is_user_request_ = false;
return auth_req;
}

if (db_num_ > 0 &&
(seqid == 0 || !password_.empty() || !username_.empty()))
{
succ_ = false;
is_user_request_ = false;
auto *select_req = new RedisRequest;
char buf[32];

sprintf(buf, "%d", db_num_);
select_req->set_request("SELECT", {buf});

succ_ = false;
is_user_request_ = false;
return select_req;
}
}
Expand Down Expand Up @@ -179,7 +181,7 @@ bool ComplexRedisTask::init_success()
if (uri_.path && uri_.path[0] == '/' && uri_.path[1])
db_num_ = atoi(uri_.path + 1);

size_t info_len = username_.size() + password_.size() + 32 + 16;
size_t info_len = username_.size() + password_.size() + 32 + 32;
char *info = new char[info_len];

sprintf(info, "redis|user:%s|pass:%s|db:%d", username_.c_str(),
Expand Down

0 comments on commit 1d434f3

Please sign in to comment.