18
18
#include < thread>
19
19
#include < chrono>
20
20
#include < atomic>
21
+ #include < memory>
21
22
#include " utils.h"
22
23
23
24
namespace sw {
@@ -26,7 +27,9 @@ namespace redis {
26
27
27
28
namespace test {
28
29
29
- ThreadsTest::ThreadsTest (const ConnectionOptions &opts) : _opts(opts) {}
30
+ ThreadsTest::ThreadsTest (const ConnectionOptions &opts,
31
+ const ConnectionOptions &cluster_opts) : _opts(opts),
32
+ _cluster_opts (cluster_opts) {}
30
33
31
34
void ThreadsTest::run () {
32
35
// 100 * 10000 = 1 million writes
@@ -36,23 +39,32 @@ void ThreadsTest::run() {
36
39
// Default pool options: single connection and wait forever.
37
40
_test_multithreads (Redis (_opts), thread_num, times);
38
41
42
+ _test_multithreads (RedisCluster (_cluster_opts), thread_num, times);
43
+
39
44
// Pool with 10 connections.
40
45
ConnectionPoolOptions pool_opts;
41
46
pool_opts.size = 10 ;
42
47
_test_multithreads (Redis (_opts, pool_opts), thread_num, times);
43
48
49
+ _test_multithreads (RedisCluster (_cluster_opts, pool_opts), thread_num, times);
50
+
44
51
_test_timeout ();
45
52
}
46
53
47
- void ThreadsTest::_test_multithreads (Redis redis, int thread_num, int times) {
54
+ template <typename RedisType>
55
+ void ThreadsTest::_test_multithreads (RedisType redis, int thread_num, int times) {
48
56
std::vector<std::string> keys;
49
57
keys.reserve (thread_num);
50
58
for (auto idx = 0 ; idx != thread_num; ++idx) {
51
59
auto key = test_key (" multi-threads::" + std::to_string (idx));
52
60
keys.push_back (key);
53
61
}
54
62
55
- KeyDeleter deleter (redis, keys.begin (), keys.end ());
63
+ using DeleterUPtr = std::unique_ptr<KeyDeleterTpl<RedisType>>;
64
+ std::vector<DeleterUPtr> deleters;
65
+ for (const auto &key : keys) {
66
+ deleters.emplace_back (new KeyDeleterTpl<RedisType>(redis, key));
67
+ }
56
68
57
69
std::vector<std::thread> workers;
58
70
workers.reserve (thread_num);
0 commit comments