7#ifndef BOOST_REDIS_REQUEST_HPP
8#define BOOST_REDIS_REQUEST_HPP
10#include <boost/redis/resp3/type.hpp>
11#include <boost/redis/resp3/serialization.hpp>
20namespace boost::redis {
23auto has_response(std::string_view cmd) -> bool;
88 [[nodiscard]]
auto get_expected_responses() const noexcept -> std::
size_t
89 {
return expected_responses_;};
92 [[nodiscard]]
auto get_commands() const noexcept -> std::
size_t
95 [[nodiscard]]
auto payload() const noexcept -> std::string_view
98 [[nodiscard]]
auto has_hello_priority() const noexcept -> auto const&
99 {
return has_hello_priority_;}
106 expected_responses_ = 0;
107 has_hello_priority_ =
false;
112 { payload_.reserve(new_cap); }
115 [[nodiscard]]
auto get_config() const noexcept -> auto const& {
return cfg_; }
118 [[nodiscard]]
auto get_config() noexcept -> auto& {
return cfg_; }
145 template <
class... Ts>
146 void push(std::string_view cmd, Ts
const&... args)
148 auto constexpr pack_size =
sizeof...(Ts);
150 resp3::add_bulk(payload_, cmd);
151 resp3::add_bulk(payload_, std::tie(std::forward<Ts const&>(args)...));
187 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>
243 std::string_view
const& cmd,
244 ForwardIterator begin,
246 typename std::iterator_traits<ForwardIterator>::value_type * =
nullptr)
248 using value_type =
typename std::iterator_traits<ForwardIterator>::value_type;
253 auto constexpr size = resp3::bulk_counter<value_type>::size;
254 auto const distance = std::distance(begin, end);
256 resp3::add_bulk(payload_, cmd);
258 for (; begin != end; ++begin)
259 resp3::add_bulk(payload_, *begin);
274 template <
class Range>
277 std::string_view
const& cmd,
278 std::string_view
const& key,
280 decltype(std::begin(range)) * =
nullptr)
284 push_range(cmd, key, begin(range), end(range));
296 template <
class Range>
299 std::string_view cmd,
301 decltype(std::cbegin(range)) * =
nullptr)
309 void check_cmd(std::string_view cmd)
313 if (!detail::has_response(cmd))
314 ++expected_responses_;
321 std::string payload_;
322 std::size_t commands_ = 0;
323 std::size_t expected_responses_ = 0;
324 bool has_hello_priority_ =
false;
bool cancel_if_not_connected
If true the request will complete with boost::redis::error::not_connected if async_exec is called bef...
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 boost::redis::connection::async_exec will not automatically cancel this request if the conne...
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 boost::redis::connection::async_exec will complete with error if the connection is lost....
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.