optimize and test redis_pipeline module

This commit is contained in:
zhengshuxin 2021-01-05 15:42:25 +08:00
parent a7d14d6744
commit ebc4adb376
4 changed files with 26 additions and 27 deletions

View File

@ -472,6 +472,9 @@ public:
redis_pipeline_message& get_pipeline_message(void); redis_pipeline_message& get_pipeline_message(void);
static void build_request(size_t argc, const char* argv[],
size_t lens[], string& out);
protected: protected:
/************************** request ********************************/ /************************** request ********************************/
bool slice_req_; bool slice_req_;

View File

@ -61,7 +61,6 @@ void redis_pipeline_channel::flush(void)
return; return;
} }
char buf[64];
buf_.clear(); buf_.clear();
for (std::vector<redis_pipeline_message*>::iterator it = msgs_.begin(); for (std::vector<redis_pipeline_message*>::iterator it = msgs_.begin();
@ -70,19 +69,8 @@ void redis_pipeline_channel::flush(void)
string* req = (*it)->get_cmd().get_request_buf(); string* req = (*it)->get_cmd().get_request_buf();
buf_.append(req->c_str(), req->size()); buf_.append(req->c_str(), req->size());
#else #else
acl_ui64toa_radix((acl_uint64) (*it)->argc_, buf, sizeof(buf), 10); redis_command::build_request((*it)->argc_, (*it)->argv_,
buf_.append("*"); (*it)->lens_, buf_);
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 #endif
} }
msgs_.clear(); msgs_.clear();

View File

@ -959,40 +959,46 @@ void redis_command::build_request1(size_t argc, const char* argv[], size_t lens[
} else { } else {
request_buf_->clear(); request_buf_->clear();
} }
build_request(argc, argv, lens, *request_buf_);
}
void redis_command::build_request(size_t argc, const char* argv[],
size_t lens[], string& out)
{
//#define USE_FORMAT //#define USE_FORMAT
//#define USE_SNPRINTF //#define USE_SNPRINTF
#if defined(USE_FORMAT) #if defined(USE_FORMAT)
request_buf_->format("*%lu\r\n", (unsigned long) argc); out.format("*%lu\r\n", (unsigned long) argc);
#elif defined(USE_SNPRINTF) #elif defined(USE_SNPRINTF)
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "*%lu\r\n", (unsigned long) argc); snprintf(buf, sizeof(buf), "*%lu\r\n", (unsigned long) argc);
request_buf_->append(buf); out.append(buf);
#else #else
char buf[64]; char buf[64];
acl_ui64toa_radix((acl_uint64) argc, buf, sizeof(buf), 10); acl_ui64toa_radix((acl_uint64) argc, buf, sizeof(buf), 10);
request_buf_->append("*"); out.append("*");
request_buf_->append(buf); out.append(buf);
request_buf_->append("\r\n"); out.append("\r\n");
#endif #endif
for (size_t i = 0; i < argc; i++) { for (size_t i = 0; i < argc; i++) {
#if defined(USE_FORMAT) #if defined(USE_FORMAT)
request_buf_->format_append("$%lu\r\n", (unsigned long) lens[i]); out.format_append("$%lu\r\n", (unsigned long) lens[i]);
#elif defined(USE_SNPRINTF) #elif defined(USE_SNPRINTF)
snprintf(buf, sizeof(buf), "$%lu\r\n", (unsigned long) lens[i]); snprintf(buf, sizeof(buf), "$%lu\r\n", (unsigned long) lens[i]);
request_buf_->append(buf); out.append(buf);
#else #else
acl_ui64toa_radix((acl_uint64) lens[i], buf, sizeof(buf), 10); acl_ui64toa_radix((acl_uint64) lens[i], buf, sizeof(buf), 10);
request_buf_->append("$"); out.append("$");
request_buf_->append(buf); out.append(buf);
request_buf_->append("\r\n"); out.append("\r\n");
#endif #endif
request_buf_->append(argv[i], lens[i]); out.append(argv[i], lens[i]);
request_buf_->append("\r\n"); out.append("\r\n");
} }
//printf("%s:\r\n%s\r\n", __FUNCTION__, request_buf_->c_str());
//printf("%s:\r\n%s\r\n", __FUNCTION__, out.c_str());
} }
void redis_command::build_request2(size_t argc, const char* argv[], size_t lens[]) void redis_command::build_request2(size_t argc, const char* argv[], size_t lens[])

View File

@ -191,11 +191,13 @@ protected:
break; break;
} }
/*
if (i > 0 && i % 50000 == 0) { if (i > 0 && i % 50000 == 0) {
char tmp[128]; char tmp[128];
acl::safe_snprintf(tmp, sizeof(tmp), "%d", i); acl::safe_snprintf(tmp, sizeof(tmp), "%d", i);
acl::meter_time(__FILE__, __LINE__, tmp); acl::meter_time(__FILE__, __LINE__, tmp);
} }
*/
cmd_string.clear(); cmd_string.clear();
cmd_key.clear(); cmd_key.clear();