Skip to content

Commit 5e442bc

Browse files
author
zhengshuxin
committed
Optimize and test redis module in pipeline mode.
1 parent ca4a70d commit 5e442bc

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

lib_acl_cpp/include/acl_cpp/redis/redis_client_pipeline.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ class redis_pipeline_message {
6767
void set_option(size_t nchild, const int* timeout);
6868

6969
// Called in redis_command::run()
70-
void move(dbuf_pool* dbuf);
70+
void set(dbuf_pool* dbuf);
7171

7272
// Called in redis_command::build_request().
73-
void move(const string* req);
73+
void set(const string* req);
7474

7575
// Called in redis_command::build_request().
7676
void set_slot(size_t slot);
@@ -135,8 +135,6 @@ class redis_pipeline_message {
135135
size_t nchild_;
136136
dbuf_pool* dbuf_;
137137
const string* req_;
138-
std::vector<dbuf_pool*> dbufs_;
139-
std::vector<const string*> reqs_;
140138

141139
const redis_result* result_;
142140

lib_acl_cpp/include/acl_cpp/redis/redis_command.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ class ACL_CPP_API redis_command : public noncopyable {
446446

447447
private:
448448
void init();
449+
dbuf_pool *dbuf_create();
449450

450451
public:
451452
// compute hash slot of the given key and store it in the current

lib_acl_cpp/src/redis/redis_client_pipeline.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ redis_pipeline_message::redis_pipeline_message(redis_pipeline_type_t type,
3131
}
3232

3333
redis_pipeline_message::~redis_pipeline_message() {
34-
for (std::vector<const string*>::iterator it = reqs_.begin();
35-
it != reqs_.end(); ++it) {
36-
delete *it;
37-
COUNTER_DEC(pipeline_req);
38-
}
39-
40-
for (std::vector<dbuf_pool*>::iterator it = dbufs_.begin();
41-
it != dbufs_.end(); ++it) {
42-
(*it)->destroy();
43-
COUNTER_DEC(pipeline_dbuf);
44-
}
4534
delete box_;
4635
COUNTER_DEC(redis_pipeline_message);
4736
}
@@ -58,21 +47,11 @@ void redis_pipeline_message::set_slot(size_t slot) {
5847
slot_ = slot;
5948
}
6049

61-
void redis_pipeline_message::move(const string* req) {
62-
if (req) {
63-
reqs_.push_back(req);
64-
COUNTER_INC(pipeline_req);
65-
}
66-
50+
void redis_pipeline_message::set(const string* req) {
6751
req_ = req;
6852
}
6953

70-
void redis_pipeline_message::move(dbuf_pool* dbuf) {
71-
if (dbuf) {
72-
dbufs_.push_back(dbuf);
73-
COUNTER_INC(pipeline_dbuf);
74-
}
75-
54+
void redis_pipeline_message::set(dbuf_pool* dbuf) {
7655
dbuf_ = dbuf;
7756
}
7857

lib_acl_cpp/src/redis/redis_command.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace acl {
2121
#defineLONG_LEN21
2222
#defineREDIS_DBUF_NBLOCK1
2323

24-
static dbuf_pool *dbuf_alloc()
24+
dbuf_pool *redis_command::dbuf_create()
2525
{
2626
#ifdef ACL_DBUF_HOOK_NEW
2727
return new (REDIS_DBUF_NBLOCK) dbuf_pool();
@@ -51,7 +51,7 @@ void redis_command::init()
5151
result_ = NULL;
5252
pipe_msg_ = NULL;
5353
addr_[0] = 0;
54-
dbuf_ = dbuf_alloc();
54+
dbuf_ = dbuf_create();
5555

5656
COUNTER_INC(redis_comand);
5757
}
@@ -400,12 +400,8 @@ const redis_result* redis_command::run(size_t nchild /* = 0 */,
400400
if (pipeline_ != NULL) {
401401
assert(pipe_msg_); // build_request() must have been called first.
402402
pipe_msg_->set_option(nchild, timeout);
403-
pipe_msg_->move(dbuf_);
404-
dbuf_ = dbuf_alloc();
403+
pipe_msg_->set(dbuf_);
405404
result_ = pipeline_->exec(pipe_msg_);
406-
pipe_msg_->unrefer();
407-
pipe_msg_ = NULL;
408-
409405
return result_;
410406
}
411407
if (cluster_ != NULL) {
@@ -997,8 +993,7 @@ void redis_command::build_request(size_t argc, const char* argv[], const size_t
997993
if (pipeline_) {
998994
redis_pipeline_message* msg = get_pipeline_message();
999995
build_request1(argc, argv, lens);
1000-
msg->move(request_buf_);
1001-
request_buf_ = NULL;
996+
msg->set(request_buf_);
1002997
msg->set_slot(static_cast<size_t>(slot_));
1003998
} else if (slice_req_) {
1004999
build_request2(argc, argv, lens);

0 commit comments

Comments
 (0)