xRedis API  1.5.0
The C++ Client API for Redis server
 All Classes
xRedisClusterClient.h
1 /*
2  * ----------------------------------------------------------------------------
3  * Copyright (c) 2013-2021, xSky <guozhw at gmail dot com>
4  * All rights reserved.
5  * Distributed under GPL license.
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef _XREDIS_CLUSTER_CLIENT_H_
10 #define _XREDIS_CLUSTER_CLIENT_H_
11 
12 #include "hiredis.h"
13 #include "xLock.h"
14 #include <list>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <string>
19 #include <vector>
20 
21 namespace xrc {
22 
23 #define LOG_LEVEL_ERROR 0
24 #define LOG_LEVEL_WARN 1
25 #define LOG_LEVEL_INFO 2
26 #define LOG_LEVEL_DEBUG 3
27 
28 class xRedisClusterManager;
29 class RedisResult;
30 typedef std::vector<std::string> VString;
31 class ClusterInfo;
32 
33 class RedisResult {
34 public:
35  RedisResult() { }
36  ~RedisResult()
37  {
38  if (Reply.reply) {
39  freeReplyObject((void*)Reply.reply);
40  }
41  }
42 
43 public:
44  class RedisReply {
45  public:
46  RedisReply(redisReply* r) { reply = r; }
47  RedisReply(const RedisReply& r) { reply = r.reply; }
48  RedisReply() { reply = NULL; }
49  ~RedisReply() { }
50 
51  inline int32_t type() const { return reply->type; }
52  inline long long integer() const { return reply->integer; }
53  inline int32_t len() const { return reply->len; }
54  inline char* str() const { return reply->str; }
55  inline size_t elements() const { return reply->elements; }
56  inline struct RedisReply element(uint32_t index) const
57  {
58  return RedisReply(reply->element[index]);
59  }
60 
61  private:
62  friend class RedisResult;
63  redisReply* reply;
64  };
65 
66  inline void Init(redisReply* r)
67  {
68  if (Reply.reply) {
69  freeReplyObject((void*)Reply.reply);
70  }
71  Reply.reply = r;
72  }
73  inline int32_t type() const { return Reply.type(); }
74  inline long long integer() const { return Reply.integer(); }
75  inline int32_t len() const { return Reply.len(); }
76  inline char* str() const { return Reply.str(); }
77  inline size_t elements() const { return Reply.elements(); }
78  inline RedisReply element(uint32_t index) const { return Reply.element(index); }
79 
80 private:
81  RedisReply Reply;
82 };
83 
85 public:
88 
89 public:
90  bool connect(const std::string& host, uint32_t port,
91  const std::string& pass, uint32_t poolsize);
92  void keepalive();
93  bool commandArgv(const VString& vDataIn, RedisResult& result);
94  bool command(RedisResult& result, const char* format, ...);
95  void setLogLevel(uint32_t level, void (*emit)(int level, const char* line));
96 
97 private:
98  xRedisClusterManager* mClusterManager_free;
99  xRedisClusterManager* mClusterManager;
100  ClusterInfo* mRedisInfo;
101 };
102 
103 } // namespace xrc
104 
105 #endif
Definition: xRedisClusterClient.h:44
Definition: xRedisClusterClient.h:33
Definition: xRedisClusterManager.h:213
Definition: xRedisClusterClient.h:84
Definition: xRedisClusterManager.h:203

Generated on Mon Mar 21 2022 10:57:13 for xRedis API version 1.5.0.