Skip to content

Commit

Permalink
add pksetexat in pika-port (OpenAtomFoundation#2104)
Browse files Browse the repository at this point in the history
* add pksetexat

* add pksetexat
  • Loading branch information
a105531816 authored Nov 7, 2023
1 parent 5a3102a commit 8364fe5
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tools/pika-port/pika_port_3/master_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,44 @@ bool MasterConn::ProcessBinlogData(const net::RedisCmdArgsType& argv, const Port
if (1 < argv.size()) {
key = argv[1];
}
int ret = g_pika_port->SendRedisCommand(binlog_item.content(), key);

std::string command;
if (argv[0] == "pksetexat"){
//struct timeval now;
std::string temp("");
std::string time_out("");
std::string time_cmd("");
int start;
int old_time_size;
int new_time_size;
int diff;
temp = argv[2];
//gettimeofday(&now, NULL);
unsigned long int sec= time(NULL);
unsigned long int tot;
tot = std::stol(temp) - sec;
time_out = std::to_string(tot);

command = binlog_item.content();
command.erase(0,4);
command.replace(0, 13, "*4\r\n$5\r\nsetex");
//"*4\r\n$5\r\nsetex\r\n$48\r\n1691478611637921200018685540810_4932190141418052\r\n$10\r\n1691483848\r\n$1681\r\n(\265/\375`\332\024=4"}}
start = 13 + 3 + std::to_string(key.size()).size() + 2 + key.size() +3;
old_time_size = std::to_string(temp.size()).size() + 2 + temp.size();
new_time_size = std::to_string(time_out.size()).size() + 2 + time_out.size();
diff = old_time_size - new_time_size;
command.erase(start, diff);
time_cmd = std::to_string(time_out.size()) + "\r\n" + time_out;
command.replace(start, new_time_size, time_cmd);
} else {
command = binlog_item.content();
}

int ret = g_pika_port->SendRedisCommand(command, key);
if (ret != 0) {
LOG(WARNING) << "send redis command:" << binlog_item.ToString() << ", ret:" << ret;
LOG(WARNING) << "send redis command:" << command << ", ret:" << ret;
}

return true;
}

0 comments on commit 8364fe5

Please sign in to comment.