7#ifndef BOOST_REDIS_REQUEST_HPP
8#define BOOST_REDIS_REQUEST_HPP
10#include <boost/redis/resp3/serialization.hpp>
11#include <boost/redis/resp3/type.hpp>
20namespace boost::redis {
23auto has_response(std::string_view cmd) -> bool;
88 [[nodiscard]]
auto get_expected_responses() const noexcept -> std::
size_t
90 return expected_responses_;
94 [[nodiscard]]
auto get_commands() const noexcept -> std::
size_t {
return commands_; };
96 [[nodiscard]]
auto payload() const noexcept -> std::string_view {
return payload_; }
98 [[nodiscard]]
auto has_hello_priority() const noexcept -> auto const&
100 return has_hello_priority_;
108 expected_responses_ = 0;
109 has_hello_priority_ =
false;
113 void reserve(std::size_t new_cap = 0) { payload_.reserve(new_cap); }
116 [[nodiscard]]
auto get_config() const noexcept -> auto const& {
return cfg_; }
119 [[nodiscard]]
auto get_config() noexcept -> auto& {
return cfg_; }
146 template <
class... Ts>
147 void push(std::string_view cmd, Ts
const&... args)
149 auto constexpr pack_size =
sizeof...(Ts);
151 resp3::add_bulk(payload_, cmd);
152 resp3::add_bulk(payload_, std::tie(std::forward<Ts const&>(args)...));
188 template <
class ForwardIterator>
190 std::string_view
const& cmd,
191 std::string_view
const& key,
192 ForwardIterator begin,
194 typename std::iterator_traits<ForwardIterator>::value_type* =
nullptr)
196 using value_type =
typename std::iterator_traits<ForwardIterator>::value_type;
201 auto constexpr size = resp3::bulk_counter<value_type>::size;
202 auto const distance = std::distance(begin, end);
204 resp3::add_bulk(payload_, cmd);
205 resp3::add_bulk(payload_, key);
207 for (; begin != end; ++begin)
208 resp3::add_bulk(payload_, *begin);
240 template <
class ForwardIterator>
242 std::string_view
const& cmd,
243 ForwardIterator begin,
245 typename std::iterator_traits<ForwardIterator>::value_type* =
nullptr)
247 using value_type =
typename std::iterator_traits<ForwardIterator>::value_type;
252 auto constexpr size = resp3::bulk_counter<value_type>::size;
253 auto const distance = std::distance(begin, end);
255 resp3::add_bulk(payload_, cmd);
257 for (; begin != end; ++begin)
258 resp3::add_bulk(payload_, *begin);
273 template <
class Range>
275 std::string_view
const& cmd,
276 std::string_view
const& key,
278 decltype(std::begin(range))* =
nullptr)
282 push_range(cmd, key, begin(range), end(range));
294 template <
class Range>
296 std::string_view cmd,
298 decltype(std::cbegin(range))* =
nullptr)
306 void check_cmd(std::string_view cmd)
310 if (!detail::has_response(cmd))
311 ++expected_responses_;
318 std::string payload_;
319 std::size_t commands_ = 0;
320 std::size_t expected_responses_ = 0;
321 bool has_hello_priority_ =
false;
bool cancel_if_not_connected
If true connection::async_exec will complete with boost::redis::error::not_connected if the call happ...
auto get_config() noexcept -> auto &
Returns a reference to the config object.
bool hello_with_priority
If this request has a HELLO command and this flag is true, the boost::redis::connection will move it ...
void push_range(std::string_view cmd, Range const &range, decltype(std::cbegin(range)) *=nullptr)
Appends a new command to the end of the request.
void reserve(std::size_t new_cap=0)
Calls std::string::reserve on the internal storage.
request(config cfg=config{true, false, true, true})
Constructor.
bool cancel_if_unresponded
If false connection::async_exec will not automatically cancel this request if the connection is lost....
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
void clear()
Clears the request preserving allocated memory.
void push_range(std::string_view const &cmd, std::string_view const &key, ForwardIterator begin, ForwardIterator end, typename std::iterator_traits< ForwardIterator >::value_type *=nullptr)
Appends a new command to the end of the request.
bool cancel_on_connection_lost
If true calls to connection::async_exec will complete with error if the connection is lost while the ...
auto get_config() const noexcept -> auto const &
Returns a const reference to the config object.
void push_range(std::string_view const &cmd, ForwardIterator begin, ForwardIterator end, typename std::iterator_traits< ForwardIterator >::value_type *=nullptr)
Appends a new command to the end of the request.
void push_range(std::string_view const &cmd, std::string_view const &key, Range const &range, decltype(std::begin(range)) *=nullptr)
Appends a new command to the end of the request.
Request configuration options.