mirror of
https://github.com/boostorg/redis.git
synced 2026-01-19 04:42:09 +00:00
Prefix to_ and from_bulk with boost_redis_ (boost review).
This commit is contained in:
22
README.md
22
README.md
@@ -303,21 +303,21 @@ Sending a request to Redis is performed with `boost::redis::connection::async_ex
|
||||
|
||||
The `resp3::request::push` and `resp3::request::push_range` member functions work
|
||||
with integer data types e.g. `int` and `std::string` out of the box.
|
||||
To send your own data type define a `to_bulk` function like this
|
||||
To send your own data type define a `boost_redis_to_bulk` function like this
|
||||
|
||||
```cpp
|
||||
// User defined type.
|
||||
struct mystruct {...};
|
||||
|
||||
// Serialize it in to_bulk.
|
||||
void to_bulk(std::pmr::string& to, mystruct const& obj)
|
||||
// Serialize it in boost_redis_to_bulk.
|
||||
void boost_redis_to_bulk(std::pmr::string& to, mystruct const& obj)
|
||||
{
|
||||
std::string dummy = "Dummy serializaiton string.";
|
||||
boost::redis::resp3::to_bulk(to, dummy);
|
||||
boost::redis::resp3::boost_redis_to_bulk(to, dummy);
|
||||
}
|
||||
```
|
||||
|
||||
Once `to_bulk` is defined and visible over ADL `mystruct` can
|
||||
Once `boost_redis_to_bulk` is defined and visible over ADL `mystruct` can
|
||||
be passed to the `request`
|
||||
|
||||
```cpp
|
||||
@@ -535,11 +535,11 @@ As mentioned in the serialization section, it is common practice to
|
||||
serialize data before sending it to Redis e.g. as json strings. For
|
||||
performance and convenience reasons, we may also want to deserialize
|
||||
responses directly in their final data structure. Boost.Redis supports this
|
||||
use case by calling a user provided `from_bulk` function while parsing
|
||||
use case by calling a user provided `boost_redis_from_bulk` function while parsing
|
||||
the response. For example
|
||||
|
||||
```cpp
|
||||
void from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec)
|
||||
void boost_redis_from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec)
|
||||
{
|
||||
// Deserializes p into obj.
|
||||
}
|
||||
@@ -600,7 +600,7 @@ from Redis with `HGETALL`, some of the options are
|
||||
* `std::vector<node<std::string>`: Works always.
|
||||
* `std::vector<std::string>`: Efficient and flat, all elements as string.
|
||||
* `std::map<std::string, std::string>`: Efficient if you need the data as a `std::map`.
|
||||
* `std::map<U, V>`: Efficient if you are storing serialized data. Avoids temporaries and requires `from_bulk` for `U` and `V`.
|
||||
* `std::map<U, V>`: Efficient if you are storing serialized data. Avoids temporaries and requires `boost_redis_from_bulk` for `U` and `V`.
|
||||
|
||||
In addition to the above users can also use unordered versions of the
|
||||
containers. The same reasoning applies to sets e.g. `SMEMBERS`
|
||||
@@ -863,6 +863,12 @@ Acknowledgement to people that helped shape Boost.Redis
|
||||
|
||||
## Changelog
|
||||
|
||||
### master
|
||||
|
||||
* Renames the project to Boost.Redis and moves the code into namespace `boost::redis`.
|
||||
* As pointed out in the reviews `to_buld` and `from_buld` were too generic
|
||||
for ADL customization. They gained the prefix `boost_redis_`.
|
||||
|
||||
### v1.4.0-1
|
||||
|
||||
* Renames `retry_on_connection_lost` to `cancel_if_unresponded`. (v1.4.1)
|
||||
|
||||
@@ -76,12 +76,12 @@ auto tag_invoke(value_to_tag<user>, value const& jv)
|
||||
}
|
||||
|
||||
// Serialization
|
||||
void to_bulk(std::string& to, user const& u)
|
||||
void boost_redis_to_bulk(std::string& to, user const& u)
|
||||
{
|
||||
redis::resp3::to_bulk(to, serialize(value_from(u)));
|
||||
redis::resp3::boost_redis_to_bulk(to, serialize(value_from(u)));
|
||||
}
|
||||
|
||||
void from_bulk(user& u, std::string_view sv, boost::system::error_code&)
|
||||
void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
|
||||
{
|
||||
value jv = parse(sv);
|
||||
u = value_to<user>(jv);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace boost::redis::adapter::detail {
|
||||
// Serialization.
|
||||
|
||||
template <class T>
|
||||
auto from_bulk(T& i, std::string_view sv, system::error_code& ec) -> typename std::enable_if<std::is_integral<T>::value, void>::type
|
||||
auto boost_redis_from_bulk(T& i, std::string_view sv, system::error_code& ec) -> typename std::enable_if<std::is_integral<T>::value, void>::type
|
||||
{
|
||||
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), i);
|
||||
if (res.ec != std::errc())
|
||||
@@ -41,13 +41,13 @@ auto from_bulk(T& i, std::string_view sv, system::error_code& ec) -> typename st
|
||||
}
|
||||
|
||||
inline
|
||||
void from_bulk(bool& t, std::string_view sv, system::error_code&)
|
||||
void boost_redis_from_bulk(bool& t, std::string_view sv, system::error_code&)
|
||||
{
|
||||
t = *sv.data() == 't';
|
||||
}
|
||||
|
||||
inline
|
||||
void from_bulk(double& d, std::string_view sv, system::error_code& ec)
|
||||
void boost_redis_from_bulk(double& d, std::string_view sv, system::error_code& ec)
|
||||
{
|
||||
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), d);
|
||||
if (res.ec != std::errc())
|
||||
@@ -56,7 +56,7 @@ void from_bulk(double& d, std::string_view sv, system::error_code& ec)
|
||||
|
||||
template <class CharT, class Traits, class Allocator>
|
||||
void
|
||||
from_bulk(
|
||||
boost_redis_from_bulk(
|
||||
std::basic_string<CharT, Traits, Allocator>& s,
|
||||
std::string_view sv,
|
||||
system::error_code&)
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
from_bulk(result, n.value, ec);
|
||||
boost_redis_from_bulk(result, n.value, ec);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
}
|
||||
|
||||
typename Result::key_type obj;
|
||||
from_bulk(obj, nd.value, ec);
|
||||
boost_redis_from_bulk(obj, nd.value, ec);
|
||||
hint_ = result.insert(hint_, std::move(obj));
|
||||
}
|
||||
};
|
||||
@@ -205,11 +205,11 @@ public:
|
||||
|
||||
if (on_key_) {
|
||||
typename Result::key_type obj;
|
||||
from_bulk(obj, nd.value, ec);
|
||||
boost_redis_from_bulk(obj, nd.value, ec);
|
||||
current_ = result.insert(current_, {std::move(obj), {}});
|
||||
} else {
|
||||
typename Result::mapped_type obj;
|
||||
from_bulk(obj, nd.value, ec);
|
||||
boost_redis_from_bulk(obj, nd.value, ec);
|
||||
current_->second = std::move(obj);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public:
|
||||
result.reserve(result.size() + m * nd.aggregate_size);
|
||||
} else {
|
||||
result.push_back({});
|
||||
from_bulk(result.back(), nd.value, ec);
|
||||
boost_redis_from_bulk(result.back(), nd.value, ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -277,7 +277,7 @@ public:
|
||||
}
|
||||
|
||||
BOOST_ASSERT(nd.aggregate_size == 1);
|
||||
from_bulk(result.at(i_), nd.value, ec);
|
||||
boost_redis_from_bulk(result.at(i_), nd.value, ec);
|
||||
}
|
||||
|
||||
++i_;
|
||||
@@ -307,7 +307,7 @@ struct list_impl {
|
||||
}
|
||||
|
||||
result.push_back({});
|
||||
from_bulk(result.back(), nd.value, ec);
|
||||
boost_redis_from_bulk(result.back(), nd.value, ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
// the value type is a pair.
|
||||
|
||||
namespace boost::redis::resp3 {
|
||||
|
||||
constexpr char const* separator = "\r\n";
|
||||
|
||||
/** @brief Adds a bulk to the request.
|
||||
@@ -29,10 +28,10 @@ constexpr char const* separator = "\r\n";
|
||||
* structures in a request. For example
|
||||
*
|
||||
* @code
|
||||
* void to_bulk(std::string& to, mystruct const& obj)
|
||||
* void boost_redis_to_bulk(std::string& to, mystruct const& obj)
|
||||
* {
|
||||
* auto const str = // Convert obj to a string.
|
||||
* resp3::to_bulk(to, str);
|
||||
* boost_redis_to_bulk(to, str);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
@@ -42,7 +41,7 @@ constexpr char const* separator = "\r\n";
|
||||
* See more in @ref serialization.
|
||||
*/
|
||||
template <class Request>
|
||||
void to_bulk(Request& to, std::string_view data)
|
||||
void boost_redis_to_bulk(Request& to, std::string_view data)
|
||||
{
|
||||
auto const str = std::to_string(data.size());
|
||||
|
||||
@@ -54,10 +53,10 @@ void to_bulk(Request& to, std::string_view data)
|
||||
}
|
||||
|
||||
template <class Request, class T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||
void to_bulk(Request& to, T n)
|
||||
void boost_redis_to_bulk(Request& to, T n)
|
||||
{
|
||||
auto const s = std::to_string(n);
|
||||
to_bulk(to, std::string_view{s});
|
||||
boost_redis_to_bulk(to, std::string_view{s});
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
@@ -70,7 +69,7 @@ struct add_bulk_impl {
|
||||
static void add(Request& to, T const& from)
|
||||
{
|
||||
using namespace boost::redis::resp3;
|
||||
to_bulk(to, from);
|
||||
boost_redis_to_bulk(to, from);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -82,7 +81,7 @@ struct add_bulk_impl<std::tuple<Ts...>> {
|
||||
auto f = [&](auto const&... vs)
|
||||
{
|
||||
using namespace boost::redis::resp3;
|
||||
(to_bulk(to, vs), ...);
|
||||
(boost_redis_to_bulk(to, vs), ...);
|
||||
};
|
||||
|
||||
std::apply(f, t);
|
||||
@@ -95,8 +94,8 @@ struct add_bulk_impl<std::pair<U, V>> {
|
||||
static void add(Request& to, std::pair<U, V> const& from)
|
||||
{
|
||||
using namespace boost::redis::resp3;
|
||||
to_bulk(to, from.first);
|
||||
to_bulk(to, from.second);
|
||||
boost_redis_to_bulk(to, from.first);
|
||||
boost_redis_to_bulk(to, from.second);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,7 +161,7 @@ void add_separator(Request& to)
|
||||
* \remarks
|
||||
*
|
||||
* \li Non-string types will be converted to string by using \c
|
||||
* to_bulk, which must be made available over ADL.
|
||||
* boost_redis_to_bulk, which must be made available over ADL.
|
||||
* \li Uses a std::string for internal storage.
|
||||
*/
|
||||
class request {
|
||||
|
||||
Reference in New Issue
Block a user