-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisMgr.h
73 lines (58 loc) · 1.61 KB
/
RedisMgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef H_RedisMgrSDF_H
#define H_RedisMgrSDF_H
#include <string>
#include <vector>
#include <unordered_map>
#include "connecPool.hpp"
#include "RedisConnect.h"
class RedisMgr
{
private:
struct node{
int port;
std::string ip;
};
public:
explicit RedisMgr(std::string file);
~RedisMgr();
void initialize();
void renewClusterSlots();
bool pipeInsert_compatible(int, std::string& command, std::string& key, std::vector<std::pair<std::string, std::string>> &);
void idlehearbt();
public:
template<typename E>
bool RedisExpress(size_t slot,const E& exe)
{
bool bReturn = false;
connecPool<CMasterConnect>* pool = slots_map_[slot];
auto pConn = pool->acquire();
do
{
if (!pConn || !exe(pConn)) break;
bReturn = true;
} while (0);
return bReturn;
}
std::string getCurrTime();
private:
size_t getSlotFromKey(std::string key);
std::unique_ptr<CMasterConnect, std::function<void(CMasterConnect*)> > getConncFromSlot(size_t slot);
private:
void initializeSlotsCache();
void s2node(std::string&,struct node&); //splic string ip:port to node struct
void discoverMasterSlots(std::vector<struct nodeMaster>&);
void reset();
connecPool<CMasterConnect>* setupNewNodePool(const struct nodeMaster&);
void assignSlotNodeCache(std::vector<struct nodeMaster>&);
private:
std::string config_file;
std::string passwrd_;
int connec_size;
bool rediscovering;//process updating the culster info
int maxAttempt;
std::vector<struct node> nodes_;
std::unordered_map<std::string, connecPool<CMasterConnect>* > node_map_;
std::unordered_map<int, connecPool<CMasterConnect>* > slots_map_;
std::mutex lc_;
};
#endif