Created
January 29, 2018 09:19
-
-
Save luchenqun/5c2fdb39b771befd6e944f12b4c905b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <thread> | |
| #include "RedisClient.h" | |
| void f(int index){ | |
| std::string strKey = "name"; | |
| std::string strVal; | |
| CRedisClient* r = CRedisClient::Instance(); | |
| int ret = r->Get(strKey, &strVal); | |
| std::cout << index << ":" << std::this_thread::get_id() << " request ret = " << ret << ", val = " << strVal << std::endl; | |
| } | |
| int main(int argc, char **argv) { | |
| CRedisClient* redisCli = CRedisClient::Instance(); | |
| if (!redisCli->Initialize("127.0.0.1", 6379, 2, 30)) | |
| { | |
| std::cout << "connect to redis failed" << std::endl; | |
| return -1; | |
| } | |
| std::vector<std::thread> tv; //保存线程的情况 | |
| for(int j = 1; j <= 20 ; ++j) { | |
| std::thread t(f, j); | |
| tv.push_back(std::move(t)); | |
| } | |
| for(auto &thread : tv) { | |
| thread.join(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment