cpp_redis  4.0.0
cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.
reply.hpp
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <iostream>
26 #include <string>
27 #include <vector>
28 
29 #include <stdint.h>
30 
31 namespace cpp_redis {
32 
33 class reply {
34 public:
35 #define __CPP_REDIS_REPLY_ERR 0
36 #define __CPP_REDIS_REPLY_BULK 1
37 #define __CPP_REDIS_REPLY_SIMPLE 2
38 #define __CPP_REDIS_REPLY_NULL 3
39 #define __CPP_REDIS_REPLY_INT 4
40 #define __CPP_REDIS_REPLY_ARRAY 5
41 
45  enum class type {
52  };
53 
57  enum class string_type {
61  };
62 
63 public:
67  reply(void);
68 
75  reply(const std::string& value, string_type reply_type);
76 
82  reply(int64_t value);
83 
90  reply(const std::vector<reply>& rows);
91 
93  ~reply(void) = default;
95  reply(const reply&) = default;
97  reply& operator=(const reply&) = default;
98 
99 public:
103  bool is_array(void) const;
104 
108  bool is_string(void) const;
109 
113  bool is_simple_string(void) const;
114 
118  bool is_bulk_string(void) const;
119 
123  bool is_error(void) const;
124 
128  bool is_integer(void) const;
129 
133  bool is_null(void) const;
134 
135 public:
139  bool ok(void) const;
140 
144  bool ko(void) const;
145 
149  operator bool(void) const;
150 
151 public:
155  const std::string& error(void) const;
156 
160  const std::vector<reply>& as_array(void) const;
161 
165  const std::string& as_string(void) const;
166 
170  int64_t as_integer(void) const;
171 
172 public:
176  void set(void);
177 
184  void set(const std::string& value, string_type reply_type);
185 
191  void set(int64_t value);
192 
198  void set(const std::vector<reply>& rows);
199 
206  reply& operator<<(const reply& reply);
207 
208 public:
212  type get_type(void) const;
213 
214 private:
216  std::vector<cpp_redis::reply> m_rows;
217  std::string m_strval;
218  int64_t m_intval;
219 };
220 
221 } // namespace cpp_redis
222 
224 std::ostream& operator<<(std::ostream& os, const cpp_redis::reply& reply);
std::string m_strval
Definition: reply.hpp:217
int64_t m_intval
Definition: reply.hpp:218
bool ko(void) const
reply & operator<<(const reply &reply)
bool ok(void) const
#define __CPP_REDIS_REPLY_ARRAY
Definition: reply.hpp:40
#define __CPP_REDIS_REPLY_INT
Definition: reply.hpp:39
int64_t as_integer(void) const
#define __CPP_REDIS_REPLY_SIMPLE
Definition: reply.hpp:37
Definition: reply.hpp:33
const std::vector< reply > & as_array(void) const
const std::string & as_string(void) const
bool is_simple_string(void) const
bool is_bulk_string(void) const
#define __CPP_REDIS_REPLY_NULL
Definition: reply.hpp:38
type m_type
Definition: reply.hpp:215
bool is_integer(void) const
bool is_array(void) const
bool is_string(void) const
bool is_error(void) const
type
Definition: reply.hpp:45
string_type
Definition: reply.hpp:57
bool is_null(void) const
reply & operator=(const reply &)=default
assignment operator
#define __CPP_REDIS_REPLY_ERR
Definition: reply.hpp:35
~reply(void)=default
dtor
std::vector< cpp_redis::reply > m_rows
Definition: reply.hpp:216
#define __CPP_REDIS_REPLY_BULK
Definition: reply.hpp:36
Definition: array_builder.hpp:29
type get_type(void) const