|
13 | 13 | #include <aedis/connection.hpp>
|
14 | 14 | #include <aedis/resp3/read.hpp>
|
15 | 15 | #include <aedis/resp3/write.hpp>
|
16 |
| -#include <aedis/resp3/exec.hpp> |
17 | 16 | #include <aedis/resp3/request.hpp>
|
18 | 17 | #include <aedis/adapter/adapt.hpp>
|
19 | 18 |
|
|
66 | 65 | \endcode
|
67 | 66 |
|
68 | 67 | For a detailed comparison of Redis clients and the design
|
69 |
| - rationale behind Aedis jump to \ref why-aedis. |
| 68 | + rationale behind Aedis jump to \ref why-aedis. For benchmarks see [](https://github.com/mzimbres/aedis/blob/master/benchmarks/benchmarks.md) |
70 | 69 |
|
71 | 70 | \section requests Requests
|
72 | 71 |
|
|
80 | 79 | // Command with variable length of arguments.
|
81 | 80 | req.push("SET", "key", "some value", value, "EX", "2");
|
82 | 81 |
|
83 |
| - // Pushes a set. |
| 82 | + // Pushes a list. |
84 | 83 | std::list<std::string> list
|
85 | 84 | {"channel1", "channel2", "channel3"};
|
86 | 85 | req.push_range("SUBSCRIBE", list);
|
|
176 | 175 | subset of the RESP3 specification. Now let us see some examples
|
177 | 176 |
|
178 | 177 | @code
|
179 |
| - auto dbuffer = dynamic_buffer(buffer); |
180 |
| -
|
181 | 178 | // To ignore the response.
|
182 |
| - co_await resp3::async_read(socket, dbuffer, adapt()); |
| 179 | + co_await db->async_exec(req, adapt()); |
183 | 180 |
|
184 | 181 | // Read in a std::string e.g. get.
|
185 | 182 | std::string str;
|
186 |
| - co_await resp3::async_read(socket, dbuffer, adapt(str)); |
| 183 | + co_await db->async_exec(req, adapt(resp)); |
187 | 184 |
|
188 | 185 | // Read in a long long e.g. rpush.
|
189 |
| - long long number; |
190 |
| - co_await resp3::async_read(socket, dbuffer, adapt(number)); |
| 186 | + long long resp; |
| 187 | + co_await db->async_exec(req, adapt(resp)); |
191 | 188 |
|
192 | 189 | // Read in a std::set e.g. smembers.
|
193 |
| - std::set<T, U> set; |
194 |
| - co_await resp3::async_read(socket, dbuffer, adapt(set)); |
| 190 | + std::set<T, U> resp; |
| 191 | + co_await db->async_exec(req, adapt(resp)); |
195 | 192 |
|
196 | 193 | // Read in a std::map e.g. hgetall.
|
197 |
| - std::map<T, U> set; |
198 |
| - co_await resp3::async_read(socket, dbuffer, adapt(map)); |
| 194 | + std::map<T, U> resp; |
| 195 | + co_await db->async_exec(req, adapt(resp)); |
199 | 196 |
|
200 | 197 | // Read in a std::unordered_map e.g. hgetall.
|
201 |
| - std::unordered_map<T, U> umap; |
202 |
| - co_await resp3::async_read(socket, dbuffer, adapt(umap)); |
| 198 | + std::unordered_map<T, U> resp; |
| 199 | + co_await db->async_exec(req, adapt(resp)); |
203 | 200 |
|
204 | 201 | // Read in a std::vector e.g. lrange.
|
205 |
| - std::vector<T> vec; |
206 |
| - co_await resp3::async_read(socket, dbuffer, adapt(vec)); |
| 202 | + std::vector<T> resp; |
| 203 | + co_await db->async_exec(req, adapt(resp)); |
207 | 204 | @endcode
|
208 | 205 |
|
209 | 206 | In other words, it is straightforward, just pass the result of \c
|
|
219 | 216 | wrap your type around \c boost::optional like this
|
220 | 217 |
|
221 | 218 | @code
|
222 |
| - boost::optional<std::unordered_map<T, U>> umap; |
223 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(umap)); |
| 219 | + boost::optional<std::unordered_map<T, U>> resp; |
| 220 | + co_await db->async_exec(req, adapt(resp)); |
224 | 221 | @endcode
|
225 | 222 |
|
226 | 223 | Everything else stays the same, before accessing data, users will
|
|
261 | 258 | can be read in the following way
|
262 | 259 |
|
263 | 260 | @code
|
| 261 | + using trans_type = |
| 262 | + std::tuple< |
| 263 | + boost::optional<std::string>, // get |
| 264 | + boost::optional<std::vector<std::string>>, // lrange |
| 265 | + boost::optional<std::map<std::string, std::string>> // hgetall |
| 266 | + >; |
| 267 | +
|
264 | 268 | std::tuple<
|
265 |
| - boost::optional<std::string>, // Response to get |
266 |
| - boost::optional<std::vector<std::string>>, // Response to lrange |
267 |
| - boost::optional<std::map<std::string, std::string>> // Response to hgetall |
268 |
| - > trans; |
269 |
| -
|
270 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer)); // Ignore multi |
271 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer)); // Ignore get |
272 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer)); // Ignore lrange |
273 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer)); // Ignore hgetall |
274 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(trans)); |
| 269 | + aedis::ignore, // multi |
| 270 | + aedis::ignore, // get |
| 271 | + aedis::ignore, // lrange |
| 272 | + aedis::ignore, // hgetall |
| 273 | + trans_type, // exec |
| 274 | + > resp; |
| 275 | +
|
| 276 | + co_await db->async_exec(req, adapt(resp)); |
275 | 277 | @endcode
|
276 | 278 |
|
277 | 279 | Note that above we are not ignoring the response to the commands
|
|
317 | 319 |
|
318 | 320 | \subsection gen-case The general case
|
319 | 321 |
|
320 |
| - As already mentioned, there are cases where responses to Redis |
| 322 | + There are cases where responses to Redis |
321 | 323 | commands won't fit in the model presented above, some examples are
|
322 | 324 |
|
323 | 325 | @li Commands (like \c set) whose response don't have a fixed
|
|
356 | 358 | @code
|
357 | 359 | // Receives any RESP3 simple data type.
|
358 | 360 | node<std::string> resp;
|
359 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(resp)); |
| 361 | + co_await db->async_exec(req, adapt(resp)); |
360 | 362 |
|
361 | 363 | // Receives any RESP3 simple or aggregate data type.
|
362 | 364 | std::vector<node<std::string>> resp;
|
363 |
| - co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(resp)); |
| 365 | + co_await db->async_exec(req, adapt(resp)); |
364 | 366 | @endcode
|
365 | 367 |
|
366 | 368 | For example, suppose we want to retrieve a hash data structure
|
|
0 commit comments