Skip to content

Commit

Permalink
adjust code format, fix set asking bug in ComplexRedisTask::message_in
Browse files Browse the repository at this point in the history
  • Loading branch information
kedixa committed Mar 11, 2021
1 parent 050fff3 commit d14f4c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
27 changes: 14 additions & 13 deletions src/factory/RedisTaskImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Authors: Wu Jiaxu ([email protected])
Li Yingxin ([email protected])
Liu Kai ([email protected])
*/

#include <stdio.h>
Expand Down Expand Up @@ -109,10 +110,13 @@ CommMessageOut *ComplexRedisTask::message_out()

CommMessageIn *ComplexRedisTask::message_in()
{
auto *req = this->get_req();
auto *resp = this->get_resp();
if (req->is_asking())
resp->set_asking(true);
RedisRequest *req = this->get_req();
RedisResponse *resp = this->get_resp();

if (is_user_request_)
resp->set_asking(req->is_asking());
else
resp->set_asking(false);

return this->WFClientTask::message_in();
}
Expand Down Expand Up @@ -175,6 +179,7 @@ bool ComplexRedisTask::need_redirect()
RedisRequest *client_req = this->get_req();
RedisResponse *client_resp = this->get_resp();
redis_reply_t *reply = client_resp->result_ptr();

if (reply->type == REDIS_REPLY_TYPE_ERROR)
{
if (reply->str == NULL)
Expand All @@ -194,34 +199,29 @@ bool ComplexRedisTask::need_redirect()
if (split_result.size() == 3)
{
client_req->set_asking(asking);

// format: COMMAND SLOT HOSTPORT
// example: MOVED/ASK 123 127.0.0.1:6379
std::string& hostport = split_result[2];
redirect_count_++;

ParsedURI uri;
std::string url;
if (uri_.scheme)
url.append(uri_.scheme);
else
url.append("redis");
url.append(uri_.scheme);
url.append("://");
url.append(hostport);

URIParser::parse(url, uri);
password_.clear();
db_num_ = 0;

std::swap(uri.host, uri_.host);
std::swap(uri.port, uri_.port);
std::swap(uri.state, uri_.state);
std::swap(uri.error, uri_.error);
if (uri.userinfo)
std::swap(uri.userinfo, uri_.userinfo);

return true;
}
return false;
}

return false;
}

Expand Down Expand Up @@ -253,6 +253,7 @@ bool ComplexRedisTask::finish_once()
else if (this->state != WFT_STATE_SUCCESS)
this->disable_retry();
}

return true;
}

Expand Down
9 changes: 6 additions & 3 deletions src/protocol/RedisMessage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
Authors: Wu Jiaxu ([email protected])
Liu Kai ([email protected])
*/

#include <errno.h>
Expand Down Expand Up @@ -677,17 +678,19 @@ int RedisRequest::encode(struct iovec vectors[], int max)
int RedisRequest::append(const void *buf, size_t *size)
{
int ret = RedisMessage::append(buf, size);

if (ret > 0)
{
std::string command;
if (this->get_command(command) &&
if (get_command(command) &&
strcasecmp(command.c_str(), REDIS_ASK_COMMAND) == 0)
{
redis_parser_deinit(this->parser_);
redis_parser_init(this->parser_);
set_asking(true);
if (feedback(REDIS_ASK_RESPONSE, strlen(REDIS_ASK_RESPONSE)) !=
strlen(REDIS_ASK_RESPONSE))

size_t size = strlen(REDIS_ASK_RESPONSE);
if (this->feedback(REDIS_ASK_RESPONSE, size) != size)
{
errno = EAGAIN;
ret = -1;
Expand Down
1 change: 1 addition & 0 deletions src/protocol/RedisMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
Authors: Wu Jiaxu ([email protected])
Liu Kai ([email protected])
*/

#ifndef _REDISMESSAGE_H_
Expand Down

0 comments on commit d14f4c0

Please sign in to comment.