mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
optimize and test redis_pipeline module
This commit is contained in:
parent
a7d14d6744
commit
ebc4adb376
@ -472,6 +472,9 @@ public:
|
||||
|
||||
redis_pipeline_message& get_pipeline_message(void);
|
||||
|
||||
static void build_request(size_t argc, const char* argv[],
|
||||
size_t lens[], string& out);
|
||||
|
||||
protected:
|
||||
/************************** request ********************************/
|
||||
bool slice_req_;
|
||||
|
@ -61,7 +61,6 @@ void redis_pipeline_channel::flush(void)
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[64];
|
||||
buf_.clear();
|
||||
|
||||
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();
|
||||
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");
|
||||
}
|
||||
redis_command::build_request((*it)->argc_, (*it)->argv_,
|
||||
(*it)->lens_, buf_);
|
||||
#endif
|
||||
}
|
||||
msgs_.clear();
|
||||
|
@ -959,40 +959,46 @@ void redis_command::build_request1(size_t argc, const char* argv[], size_t lens[
|
||||
} else {
|
||||
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_SNPRINTF
|
||||
|
||||
#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)
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "*%lu\r\n", (unsigned long) argc);
|
||||
request_buf_->append(buf);
|
||||
out.append(buf);
|
||||
#else
|
||||
char buf[64];
|
||||
acl_ui64toa_radix((acl_uint64) argc, buf, sizeof(buf), 10);
|
||||
request_buf_->append("*");
|
||||
request_buf_->append(buf);
|
||||
request_buf_->append("\r\n");
|
||||
out.append("*");
|
||||
out.append(buf);
|
||||
out.append("\r\n");
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
#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)
|
||||
snprintf(buf, sizeof(buf), "$%lu\r\n", (unsigned long) lens[i]);
|
||||
request_buf_->append(buf);
|
||||
out.append(buf);
|
||||
#else
|
||||
acl_ui64toa_radix((acl_uint64) lens[i], buf, sizeof(buf), 10);
|
||||
request_buf_->append("$");
|
||||
request_buf_->append(buf);
|
||||
request_buf_->append("\r\n");
|
||||
out.append("$");
|
||||
out.append(buf);
|
||||
out.append("\r\n");
|
||||
#endif
|
||||
request_buf_->append(argv[i], lens[i]);
|
||||
request_buf_->append("\r\n");
|
||||
out.append(argv[i], lens[i]);
|
||||
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[])
|
||||
|
@ -191,11 +191,13 @@ protected:
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
if (i > 0 && i % 50000 == 0) {
|
||||
char tmp[128];
|
||||
acl::safe_snprintf(tmp, sizeof(tmp), "%d", i);
|
||||
acl::meter_time(__FILE__, __LINE__, tmp);
|
||||
}
|
||||
*/
|
||||
|
||||
cmd_string.clear();
|
||||
cmd_key.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user