|
||||
File indexing completed on 2025-01-18 09:51:19
0001 /* Copyright (c) 2018-2023 Marcelo Zimbres Silva (mzimbres@gmail.com) 0002 * 0003 * Distributed under the Boost Software License, Version 1.0. (See 0004 * accompanying file LICENSE.txt) 0005 */ 0006 0007 #ifndef BOOST_REDIS_ADAPTER_ADAPT_HPP 0008 #define BOOST_REDIS_ADAPTER_ADAPT_HPP 0009 0010 #include <boost/redis/resp3/node.hpp> 0011 #include <boost/redis/response.hpp> 0012 #include <boost/redis/adapter/detail/result_traits.hpp> 0013 #include <boost/redis/adapter/detail/response_traits.hpp> 0014 #include <boost/mp11.hpp> 0015 #include <boost/system.hpp> 0016 0017 #include <tuple> 0018 #include <limits> 0019 #include <string_view> 0020 #include <variant> 0021 0022 namespace boost::redis::adapter 0023 { 0024 0025 /** @brief Adapts a type to be used as a response. 0026 * 0027 * The type T must be either 0028 * 0029 * 1. a response<T1, T2, T3, ...> or 0030 * 2. std::vector<node<String>> 0031 * 0032 * The types T1, T2, etc can be any STL container, any integer type 0033 * and `std::string`. 0034 * 0035 * @param t Tuple containing the responses. 0036 */ 0037 template<class T> 0038 auto boost_redis_adapt(T& t) noexcept 0039 { 0040 return detail::response_traits<T>::adapt(t); 0041 } 0042 0043 /** @brief Adapts user data to read operations. 0044 * @ingroup low-level-api 0045 * 0046 * STL containers, \c resp3::response and built-in types are supported and 0047 * can be used in conjunction with \c std::optional<T>. 0048 * 0049 * Example usage: 0050 * 0051 * @code 0052 * std::unordered_map<std::string, std::string> cont; 0053 * co_await async_read(socket, buffer, adapt(cont)); 0054 * @endcode 0055 * 0056 * For a transaction 0057 * 0058 * @code 0059 * sr.push(command::multi); 0060 * sr.push(command::ping, ...); 0061 * sr.push(command::incr, ...); 0062 * sr.push_range(command::rpush, ...); 0063 * sr.push(command::lrange, ...); 0064 * sr.push(command::incr, ...); 0065 * sr.push(command::exec); 0066 * 0067 * co_await async_write(socket, buffer(request)); 0068 * 0069 * // Reads the response to a transaction 0070 * resp3::response<std::string, int, int, std::vector<std::string>, int> execs; 0071 * co_await resp3::async_read(socket, dynamic_buffer(buffer), adapt(execs)); 0072 * @endcode 0073 */ 0074 template<class T> 0075 auto adapt2(T& t = redis::ignore) noexcept 0076 { return detail::result_traits<T>::adapt(t); } 0077 0078 } // boost::redis::adapter 0079 0080 #endif // BOOST_REDIS_ADAPTER_ADAPT_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |