Boost.Redis 1.4.2
A redis client library
Loading...
Searching...
No Matches
result.hpp
1
2/* Copyright (c) 2018-2023 Marcelo Zimbres Silva (mzimbres@gmail.com)
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE.txt)
6 */
7
8#ifndef BOOST_REDIS_ADAPTER_RESULT_HPP
9#define BOOST_REDIS_ADAPTER_RESULT_HPP
10
11#include <boost/redis/resp3/type.hpp>
12#include <boost/redis/error.hpp>
13#include <boost/system/result.hpp>
14#include <string>
15
16namespace boost::redis::adapter
17{
18
22struct error {
25
27 std::string diagnostic;
28};
29
36inline bool operator==(error const& a, error const& b)
37{
38 return a.data_type == b.data_type && a.diagnostic == b.diagnostic;
39}
40
47inline bool operator!=(error const& a, error const& b)
48{
49 return !(a == b);
50}
51
55template <class Value>
56using result = system::result<Value, error>;
57
58BOOST_NORETURN inline void
59throw_exception_from_error(error const & e, boost::source_location const &)
60{
61 system::error_code ec;
62 switch (e.data_type) {
65 break;
68 break;
71 break;
72 default:
73 BOOST_ASSERT_MSG(false, "Unexpected data type.");
74 }
75
76 throw system::system_error(ec, e.diagnostic);
77}
78
79} // boost::redis::adapter
80
81#endif // BOOST_REDIS_ADAPTER_RESULT_HPP
type
RESP3 data types.
Definition: type.hpp:23
system::result< Value, error > result
Stores response to individual Redis commands.
Definition: result.hpp:56
@ resp3_blob_error
Got RESP3 blob_error.
@ resp3_null
Got RESP3 null.
@ resp3_simple_error
Got RESP3 simple error.
Stores any resp3 error.
Definition: result.hpp:22
resp3::type data_type
RESP3 error data type.
Definition: result.hpp:24
bool operator!=(error const &a, error const &b)
Compares two error objects for difference.
Definition: result.hpp:47
bool operator==(error const &a, error const &b)
Compares two error objects for equality.
Definition: result.hpp:36
std::string diagnostic
Diagnostic error message sent by Redis.
Definition: result.hpp:27