boost::redis::request::push_range

Appends a new command to the end of the request.

Synopsis

Declared in <boost/redis/request.hpp>

template<class ForwardIterator>
void
push_range(
    std::string_view cmd,
    std::string_view key,
    ForwardIterator begin,
    ForwardIterator end,
    std::iterator_traits<ForwardIterator>::value_type* = nullptr);

Description

This overload is useful for commands that have a key and have a dynamic range of arguments. For example:

std::map<std::string, std::string> map
   { {"key1", "value1"}
   , {"key2", "value2"}
   , {"key3", "value3"}
   };

request req;
req.push_range("HSET", "key", map.cbegin(), map.cend());

This will generate the following command:

HSET key key1 value1 key2 value2 key3 value3

If the passed range is empty, no command is added and this function becomes a no‐op.

The value type of the passed range should satisfy one of the following:

  • The type is convertible to `std::string_view`. One argument is added per element in the range.

  • The type is an integral type. One argument is added per element in the range.

  • The type supports the `boost_redis_to_bulk` function. One argument is added per element in the range. This function is a customization point that must be made available using ADL and must have the signature `void boost_redis_to_bulk(std::string& to, T const& t);`.

  • The type is a `std::pair` instantiation, with both arguments supporting one of the points above. Two arguments are added per element in the range. Nested pairs are not allowed.

  • The type is a `std::tuple` instantiation, with every argument supporting one of the points above. N arguments are added per element in the range, with N being the tuple size. Nested tuples are not allowed.

See cpp20_serialization.cpp

Template Parameters

Name Description

ForwardIterator

A forward iterator with an element type that supports one of the points above.

Parameters

Name Description

cmd

The command to execute. It should be a redis or sentinel command, like "SET".

key

The command key. It will be added as the first argument to the command.

begin

Iterator to the begin of the range.

end

Iterator to the end of the range.

Created with MrDocs