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 size() const noexcept -> std::
size_t
91 [[nodiscard]]
auto payload() const noexcept -> std::string_view
94 [[nodiscard]]
auto has_hello_priority() const noexcept -> auto const&
95 {
return has_hello_priority_;}
102 has_hello_priority_ =
false;
107 { payload_.reserve(new_cap); }
110 [[nodiscard]]
auto get_config() const noexcept -> auto const& {
return cfg_; }
113 [[nodiscard]]
auto get_config() noexcept -> auto& {
return cfg_; }
140 template <
class... Ts>
141 void push(std::string_view cmd, Ts
const&... args)
143 auto constexpr pack_size =
sizeof...(Ts);
145 resp3::add_bulk(payload_, cmd);
146 resp3::add_bulk(payload_, std::tie(std::forward<Ts const&>(args)...));
182 template <
class ForwardIterator>
185 std::string_view
const& cmd,
186 std::string_view
const& key,
187 ForwardIterator begin,
189 typename std::iterator_traits<ForwardIterator>::value_type * =
nullptr)
191 using value_type =
typename std::iterator_traits<ForwardIterator>::value_type;
196 auto constexpr size = resp3::bulk_counter<value_type>::size;
197 auto const distance = std::distance(begin, end);
199 resp3::add_bulk(payload_, cmd);
200 resp3::add_bulk(payload_, key);
202 for (; begin != end; ++begin)
203 resp3::add_bulk(payload_, *begin);
235 template <
class ForwardIterator>
238 std::string_view
const& cmd,
239 ForwardIterator begin,
241 typename std::iterator_traits<ForwardIterator>::value_type * =
nullptr)
243 using value_type =
typename std::iterator_traits<ForwardIterator>::value_type;
248 auto constexpr size = resp3::bulk_counter<value_type>::size;
249 auto const distance = std::distance(begin, end);
251 resp3::add_bulk(payload_, cmd);
253 for (; begin != end; ++begin)
254 resp3::add_bulk(payload_, *begin);
269 template <
class Range>
272 std::string_view
const& cmd,
273 std::string_view
const& key,
275 decltype(std::begin(range)) * =
nullptr)
279 push_range(cmd, key, begin(range), end(range));
291 template <
class Range>
294 std::string_view cmd,
296 decltype(std::cbegin(range)) * =
nullptr)
304 void check_cmd(std::string_view cmd)
306 if (!detail::has_response(cmd))
314 std::string payload_;
315 std::size_t commands_ = 0;
316 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.