forked from gnblao/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjust code format, fix set asking bug in ComplexRedisTask::message_in
- Loading branch information
Showing
3 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
Authors: Wu Jiaxu ([email protected]) | ||
Li Yingxin ([email protected]) | ||
Liu Kai ([email protected]) | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
@@ -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(); | ||
} | ||
|
@@ -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) | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -253,6 +253,7 @@ bool ComplexRedisTask::finish_once() | |
else if (this->state != WFT_STATE_SUCCESS) | ||
this->disable_retry(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
limitations under the License. | ||
Authors: Wu Jiaxu ([email protected]) | ||
Liu Kai ([email protected]) | ||
*/ | ||
|
||
#include <errno.h> | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
limitations under the License. | ||
Authors: Wu Jiaxu ([email protected]) | ||
Liu Kai ([email protected]) | ||
*/ | ||
|
||
#ifndef _REDISMESSAGE_H_ | ||
|