acl  3.5.3.0
redis_role.hpp
浏览该文件的文档.
1 #pragma once
2 #include "../acl_cpp_define.hpp"
3 #include <map>
4 #include <vector>
5 #include "../stdlib/string.hpp"
6 #include "redis_command.hpp"
7 
8 #if !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
9 
10 namespace acl
11 {
12 
13 class redis_client;
14 class redis_result;
15 
17 {
18 public:
19  redis_role4slave(void) : port_(0), off_(0) {}
21 
22  void set_ip(const char* ip)
23  {
24  ip_ = ip;
25  }
26  void set_port(int port)
27  {
28  port_ = port;
29  }
30  void set_status(const char* status)
31  {
32  status_ = status;
33  }
34  void set_offset(long long off)
35  {
36  off_ = off;
37  }
38  const char* get_ip(void) const
39  {
40  return ip_.c_str();
41  }
42  int get_port(void) const
43  {
44  return port_;
45  }
46  const char* get_status(void) const
47  {
48  return status_.c_str();
49  }
50  long long get_offset(void) const
51  {
52  return off_;
53  }
54 
55 private:
56  string ip_;
57  int port_;
58  long long off_;
59  string status_;
60 };
61 
63 {
64 public:
65  redis_role4master(void) : off_(0) {}
67 
68  void set_offset(long long off)
69  {
70  off_ = off;
71  }
72  long long get_offset(void) const
73  {
74  return off_;
75  }
76  void add_slave(const redis_role4slave& slave)
77  {
78  slaves_.push_back(slave);
79  }
80  const std::vector<redis_role4slave>& get_slaves(void) const
81  {
82  return slaves_;
83  }
84 
85 private:
86  long long off_;
87  std::vector<redis_role4slave> slaves_;
88 };
89 
90 class ACL_CPP_API redis_role : virtual public redis_command
91 {
92 public:
93  redis_role(void);
94  redis_role(redis_client* conn);
95  virtual ~redis_role(void) {}
96 
97  bool role(void);
99  {
100  return role4master_;
101  }
102  const redis_role4slave& get_role4slave(void) const
103  {
104  return role4slave_;
105  }
106 
107  const char* get_role_name(void) const
108  {
109  return role_name_.c_str();
110  }
111 
112 private:
113  string role_name_;
114  std::vector<string> masters_;
115  redis_role4master role4master_;
116  redis_role4slave role4slave_;
117 
118  bool role_sentinel(const redis_result** a, size_t n);
119  bool role_master(const redis_result** a, size_t n);
120  bool role_slave(const redis_result** a, size_t n);
121 
122  bool add_one_slave(const redis_result* a, redis_role4master& out);
123 };
124 
125 }
126 
127 #endif // !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
void set_offset(long long off)
Definition: redis_role.hpp:68
void add_slave(const redis_role4slave &slave)
Definition: redis_role.hpp:76
long long get_offset(void) const
Definition: redis_role.hpp:50
void set_port(int port)
Definition: redis_role.hpp:26
int get_port(void) const
Definition: redis_role.hpp:42
void set_offset(long long off)
Definition: redis_role.hpp:34
virtual ~redis_role(void)
Definition: redis_role.hpp:95
const char * get_status(void) const
Definition: redis_role.hpp:46
void set_ip(const char *ip)
Definition: redis_role.hpp:22
const redis_role4slave & get_role4slave(void) const
Definition: redis_role.hpp:102
const char * get_ip(void) const
Definition: redis_role.hpp:38
const std::vector< redis_role4slave > & get_slaves(void) const
Definition: redis_role.hpp:80
#define ACL_CPP_API
const char * get_role_name(void) const
Definition: redis_role.hpp:107
void set_status(const char *status)
Definition: redis_role.hpp:30
long long get_offset(void) const
Definition: redis_role.hpp:72
const redis_role4master & get_role4master(void) const
Definition: redis_role.hpp:98