2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

Simplifies the serializer.

This commit is contained in:
Marcelo Zimbres
2022-04-03 20:51:08 +02:00
parent 2c96b07623
commit be79f58808
16 changed files with 51 additions and 43 deletions

View File

@@ -62,7 +62,7 @@ template <>
struct response_traits<void>
{
using response_type = void;
using adapter_type = resp3::ignore_response;
using adapter_type = resp3::detail::ignore_response;
static auto adapt() noexcept { return adapter_type{}; }
};

View File

@@ -23,7 +23,7 @@
namespace aedis {
namespace generic {
/** \brief A high level redis client.
/** \brief A high level resp3 client.
* \ingroup any
*
* This Redis client keeps a connection to the database open and
@@ -191,7 +191,7 @@ public:
{
auto const can_write = prepare_next();
resp3::serializer<std::string, Command> sr(requests_);
resp3::serializer<std::string> sr(requests_);
auto const before = std::size(requests_);
sr.push(cmd, args...);
auto const after = std::size(requests_);
@@ -217,7 +217,7 @@ public:
auto const can_write = prepare_next();
resp3::serializer<std::string, Command> sr(requests_);
resp3::serializer<std::string> sr(requests_);
auto const before = std::size(requests_);
sr.push_range2(cmd, key, begin, end);
auto const after = std::size(requests_);
@@ -243,7 +243,7 @@ public:
auto const can_write = prepare_next();
resp3::serializer<std::string, Command> sr(requests_);
resp3::serializer<std::string> sr(requests_);
auto const before = std::size(requests_);
sr.push_range2(cmd, begin, end);
auto const after = std::size(requests_);

View File

@@ -13,6 +13,9 @@
namespace aedis {
namespace redis {
/** @brief Convenience typedef for redis clients.
* @ingroup any
*/
template <class AsyncReadWriteStream>
using client = generic::client<AsyncReadWriteStream, command>;

View File

@@ -456,16 +456,5 @@ std::ostream& operator<<(std::ostream& os, command c);
*/
bool has_push_response(command cmd);
/** \brief Creates a serializer for a \c std::string.
* \ingroup any
* \param storage The string.
*/
template <class CharT, class Traits, class Allocator>
resp3::serializer<std::string, command>
make_serializer(std::basic_string<CharT, Traits, Allocator>& storage)
{
return resp3::serializer<std::basic_string<CharT, Traits, Allocator>, command>(storage);
}
} // redis
} // aedis

View File

@@ -13,6 +13,9 @@
namespace aedis {
namespace redis {
/** @brief Convenience typedef for the Redis receiver_base.
* @ingroup any
*/
template <class ...Ts>
using receiver_base = generic::receiver_base<command, Ts...>;

View File

@@ -22,6 +22,13 @@ namespace detail {
#include <boost/asio/yield.hpp>
struct ignore_response {
void
operator()(
resp3::type, std::size_t, std::size_t, char const*, std::size_t,
boost::system::error_code&) { }
};
template <
class AsyncReadStream,
class DynamicBuffer,

View File

@@ -86,16 +86,6 @@ read(
return consumed;
}
/** \brief Adapter that ignores responses.
* \ingroup any
*/
struct ignore_response {
void
operator()(
resp3::type, std::size_t, std::size_t, char const*, std::size_t,
boost::system::error_code&) { }
};
/** \brief Reads the reponse to a command.
* \ingroup functions
*
@@ -111,7 +101,7 @@ struct ignore_response {
template<
class SyncReadStream,
class DynamicBuffer,
class ResponseAdapter = ignore_response>
class ResponseAdapter = detail::ignore_response>
std::size_t
read(
SyncReadStream& stream,
@@ -150,7 +140,7 @@ read(
template <
class AsyncReadStream,
class DynamicBuffer,
class ResponseAdapter = ignore_response,
class ResponseAdapter = detail::ignore_response,
class CompletionToken = boost::asio::default_completion_token_t<typename AsyncReadStream::executor_type>
>
auto async_read(

View File

@@ -44,7 +44,7 @@ namespace resp3 {
//
// NOTE: For some commands like hset it would be a good idea to assert
// the value type is a pair.
template <class Storage, class Command>
template <class Storage>
class serializer {
private:
Storage* request_;
@@ -74,7 +74,7 @@ public:
* \param args The arguments of the Redis command.
*
*/
template <class... Ts>
template <class Command, class... Ts>
void push(Command cmd, Ts const&... args)
{
auto constexpr pack_size = sizeof...(Ts);
@@ -104,7 +104,7 @@ public:
* \param begin Iterator to the begin of the range.
* \param end Iterator to the end of the range.
*/
template <class Key, class ForwardIterator>
template <class Command, class Key, class ForwardIterator>
void push_range2(Command cmd, Key const& key, ForwardIterator begin, ForwardIterator end)
{
using value_type = typename std::iterator_traits<ForwardIterator>::value_type;
@@ -139,7 +139,7 @@ public:
* \param begin Iterator to the begin of the range.
* \param end Iterator to the end of the range.
*/
template <class ForwardIterator>
template <class Command, class ForwardIterator>
void push_range2(Command cmd, ForwardIterator begin, ForwardIterator end)
{
using value_type = typename std::iterator_traits<ForwardIterator>::value_type;
@@ -158,7 +158,7 @@ public:
/** \brief Sends a range.
*/
template <class Key, class Range>
template <class Command, class Key, class Range>
void push_range(Command cmd, Key const& key, Range const& range)
{
using std::begin;
@@ -168,15 +168,25 @@ public:
/** \brief Sends a range.
*/
template <class Range>
template <class Command, class Range>
void push_range(Command cmd, Range const& range)
{
using std::begin;
using std::end;
push_range2(cmd, begin(range), end(range));
}
};
/** \brief Creates a serializer for Sentinel commands.
* \ingroup any
* \param storage The string.
*/
template <class CharT, class Traits, class Allocator>
serializer<std::basic_string<CharT, Traits, Allocator>>
make_serializer(std::basic_string<CharT, Traits, Allocator>& storage)
{
return serializer<std::basic_string<CharT, Traits, Allocator>>(storage);
}
} // resp3
} // aedis

View File

@@ -13,6 +13,9 @@
namespace aedis {
namespace sentinel {
/** @brief Convenience typedef for Redis sentinel clients.
* @ingroup any
*/
template <class AsyncReadWriteStream>
using client = generic::client<AsyncReadWriteStream, command>;

View File

@@ -13,6 +13,9 @@
namespace aedis {
namespace sentinel {
/** @brief Convenience typedef for the Redis sentinel receiver_base.
* @ingroup any
*/
template <class ...Ts>
using receiver_base = generic::receiver_base<command, Ts...>;

View File

@@ -18,7 +18,7 @@ namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::resp3::make_serializer;
using net::ip::tcp;
using net::write;
using net::buffer;

View File

@@ -18,7 +18,7 @@ namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::resp3::make_serializer;
using aedis::adapter::adapt;
using net::ip::tcp;
using net::write;

View File

@@ -17,10 +17,10 @@
namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::adapter::adapt;
using aedis::resp3::make_serializer;
using aedis::resp3::node;
using aedis::redis::command;
using aedis::adapter::adapt;
using net::ip::tcp;
using net::write;
using net::buffer;

View File

@@ -17,7 +17,7 @@ namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::resp3::make_serializer;
using aedis::adapter::adapt;
using net::dynamic_buffer;
using net::ip::tcp;

View File

@@ -25,7 +25,7 @@ namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::resp3::make_serializer;
using aedis::adapter::adapt;
using node_type = aedis::resp3::node<std::string>;
using tcp = net::ip::tcp;

View File

@@ -18,7 +18,7 @@ namespace net = boost::asio;
namespace resp3 = aedis::resp3;
using aedis::redis::command;
using aedis::redis::make_serializer;
using aedis::resp3::make_serializer;
using aedis::resp3::node;
using aedis::adapter::adapt;
using net::ip::tcp;