mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
test redis_pipeline
This commit is contained in:
parent
16e51c46ed
commit
f4c6ef3dc4
@ -443,14 +443,16 @@ protected:
|
||||
protected:
|
||||
dbuf_pool* dbuf_;
|
||||
|
||||
// 根据键值计算哈希槽值
|
||||
void hash_slot(const char* key);
|
||||
void hash_slot(const char* key, size_t len);
|
||||
|
||||
private:
|
||||
void init(void);
|
||||
|
||||
public:
|
||||
// compute hash slot of the given key and store it in the current
|
||||
// redis command will be used in the next operation for redis cluster.
|
||||
void hash_slot(const char* key);
|
||||
void hash_slot(const char* key, size_t len);
|
||||
|
||||
// get the current hash slot stored internal
|
||||
int get_slot(void) const {
|
||||
return slot_;
|
||||
}
|
||||
|
@ -14,6 +14,11 @@ public:
|
||||
argv_[1] = "test-key";
|
||||
lens_[0] = strlen(argv_[0]);
|
||||
lens_[1] = strlen(argv_[1]);
|
||||
|
||||
// computer the hash slot for redis cluster node
|
||||
cmd_.hash_slot(argv_[1]);
|
||||
|
||||
// build redis request command with the given args.
|
||||
cmd_.build_request(argc_, argv_, lens_);
|
||||
}
|
||||
|
||||
@ -23,6 +28,12 @@ public:
|
||||
return msg_;
|
||||
}
|
||||
|
||||
void clear(void) {
|
||||
// we want to reuse the hash slot in next operation,
|
||||
// so the parameter save_slot was set to true.
|
||||
cmd_.clear(true);
|
||||
}
|
||||
|
||||
private:
|
||||
acl::redis cmd_;
|
||||
acl::redis_pipeline_message& msg_;
|
||||
@ -48,6 +59,7 @@ public:
|
||||
protected:
|
||||
// @override
|
||||
void* run(void) {
|
||||
// parepare for a lot of redis commands in one request
|
||||
std::vector<redis_command*> commands;
|
||||
for (size_t i = 0; i < (size_t) once_count_; i++) {
|
||||
redis_command* command = new redis_command(pipeline_);
|
||||
@ -58,6 +70,7 @@ protected:
|
||||
request(commands);
|
||||
}
|
||||
|
||||
// free all requests commands
|
||||
for (std::vector<redis_command*>::iterator it = commands.begin();
|
||||
it != commands.end(); ++it) {
|
||||
delete *it;
|
||||
@ -90,6 +103,9 @@ private:
|
||||
printf("wait result error\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// clear the temp memroy internal allocated by dbuf
|
||||
(*it)->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user