Skip to content

Commit

Permalink
add batch recv for pika_to_redis (OpenAtomFoundation#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
fancy-rabbit authored and Leviathan1995 committed Mar 20, 2018
1 parent d419119 commit 1e4885b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/pika_to_redis/sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void Sender::SendCommand(std::string &command, const std::string &key) {
void *Sender::ThreadMain() {
log_info("Start sender thread...");
expire_command_.clear();
int cnt = 0;

while (!should_exit_ || QueueSize() != 0 || !expire_command_.empty()) {
std::string command;
Expand Down Expand Up @@ -180,6 +181,7 @@ void *Sender::ThreadMain() {

pink::SerializeRedisCommand(argv, &command);
SendCommand(command, key);
cnt++;
}
delete iter;
} else if (type == nemo::DataType::kSSize) { // Set
Expand All @@ -194,6 +196,7 @@ void *Sender::ThreadMain() {

pink::SerializeRedisCommand(argv, &command);
SendCommand(command, key);
cnt++;
}
delete iter;
} else if (type == nemo::DataType::kLMeta) { // List
Expand All @@ -217,6 +220,7 @@ void *Sender::ThreadMain() {
}
pink::SerializeRedisCommand(argv, &command);
SendCommand(command, key);
cnt++;

pos += len;
ivs.clear();
Expand All @@ -238,14 +242,24 @@ void *Sender::ThreadMain() {

pink::SerializeRedisCommand(argv, &command);
SendCommand(command, key);
cnt++;
}
delete iter;
} else if (type == nemo::DataType::kKv) { // Kv
std::string k_key = key.substr(1);
command = k_key;
SendCommand(command, key);
cnt++;
}

if (cnt >= 200) {
for(; cnt > 0; cnt--) {
cli_->Recv(NULL);
}
}

continue;

// expire command
if (type != nemo::DataType::kKv) {
int64_t ttl = -1;
Expand Down Expand Up @@ -274,6 +288,9 @@ void *Sender::ThreadMain() {
}
}
}
for(; cnt > 0; cnt--) {
cli_->Recv(NULL);
}

delete cli_;
log_info("Sender thread complete");
Expand Down

0 comments on commit 1e4885b

Please sign in to comment.