optimize redis_pipeline

This commit is contained in:
shuxin   zheng 2021-01-05 10:02:53 +08:00
parent 52181516f3
commit a7d14d6744
3 changed files with 36 additions and 1 deletions

View File

@ -32,6 +32,9 @@ public:
, result_(NULL)
, redirect_addr_(NULL)
, redirect_count_(0)
, argc_(0)
, argv_(NULL)
, lens_(NULL)
{}
~redis_pipeline_message(void) {}
@ -48,6 +51,12 @@ public:
redirect_count_ = 0;
}
void set_request(size_t argc, const char** argv, size_t* lens) {
argc_ = argc;
argv_ = argv;
lens_ = lens;
}
void set_redirect_addr(const char* addr) {
redirect_addr_ = addr;
if (addr) {
@ -90,6 +99,11 @@ private:
const redis_result* result_;
const char* redirect_addr_;
size_t redirect_count_;
public:
size_t argc_;
const char** argv_;
size_t* lens_;
};
class redis_client_pipeline;

View File

@ -61,11 +61,29 @@ void redis_pipeline_channel::flush(void)
return;
}
char buf[64];
buf_.clear();
for (std::vector<redis_pipeline_message*>::iterator it = msgs_.begin();
it != msgs_.end(); ++it) {
#if 0
string* req = (*it)->get_cmd().get_request_buf();
buf_.append(req->c_str(), req->size());
#else
acl_ui64toa_radix((acl_uint64) (*it)->argc_, buf, sizeof(buf), 10);
buf_.append("*");
buf_.append(buf);
buf_.append("\r\n");
for (size_t i = 0; i < (*it)->argc_; i++) {
acl_ui64toa_radix((acl_uint64) (*it)->lens_[i], buf, sizeof(buf), 10);
buf_.append("$");
buf_.append(buf);
buf_.append("\r\n");
buf_.append((*it)->argv_[i], (*it)->lens_[i]);
buf_.append("\r\n");
}
#endif
}
msgs_.clear();

View File

@ -942,7 +942,10 @@ void redis_command::clear_request(void)
void redis_command::build_request(size_t argc, const char* argv[], size_t lens[])
{
if (slice_req_) {
if (pipeline_) {
redis_pipeline_message& msg = get_pipeline_message();
msg.set_request(argc, argv, lens);
} else if (slice_req_) {
build_request2(argc, argv, lens);
} else {
build_request1(argc, argv, lens);