WanwanLinLin
WanwanLinLin
那我想封装一个Interface类,像上面的代码那样有一个setex和get方法,那这个时候我的wait group该定义在哪里?特别是get接口,我需要redis_callback运行完成后的返回值,这时候我应该要等异步任务运行完获取到结果才能结束掉这个get接口吧?
这是我的源代码,现在就卡在这个get接口这里了,麻烦帮我看一下 ``` namespace RedisCli { struct redis_input_data { std::string url; std::string key; std::string res; }; Interface::Interface(std:: string& url) : url(url) {}; void redis_callback(WFRedisTask *task){ protocol::RedisRequest *req = task->get_req(); protocol::RedisResponse *resp...
wait_group也写在get函数的话,那redis_callback要用到wait_group咋办?
试了很久都没有办法,有时候查询还会失败,所以最后还是决定使用create_go_task + hiredis 了
interface.h ``` #ifndef REDIS_INTER_H #define REDIS_INTER_H #define RETRY_MAX 2 #include #include // #include "_global.h" #include "workflow/RedisMessage.h" #include "workflow/WFTaskFactory.h" #include "workflow/WFFacilities.h" namespace RedisCli { static WFFacilities::WaitGroup wait_group(1); struct redis_input_data { std::string...
interface.cpp ``` #include "interface.h" namespace RedisCli { Interface::Interface(std:: string& url) : url(url) {}; void Interface::redis_callback(WFRedisTask *task){ protocol::RedisRequest *req = task->get_req(); protocol::RedisResponse *resp = task->get_resp(); int state = task->get_state(); int error...
main.cpp ``` #include "interface.h" #include #include int main() { std:: string url = "redis://127.0.0.1:6379/0"; std:: string key = "a"; std:: string val = "b"; std:: string time = "600"; RedisCli::Interface...
这是我的源代码,麻烦帮忙看一下
好,我先看一下
我定义了redis的输入结构,但不知道wai_group应该定义在哪里,以及如何再callback使用 struct redis_input_data { std::string url; std::string key; std::string res; };