mirror of
https://github.com/boostorg/redis.git
synced 2026-02-21 03:12:14 +00:00
Some simplifications and a bugfix.
This commit is contained in:
@@ -206,10 +206,11 @@ struct consumer_op {
|
||||
yield self.complete(ec, m_type);
|
||||
|
||||
if (m_type != type::push)
|
||||
requests.front().elements.pop();
|
||||
requests.front().elements.pop();
|
||||
|
||||
} while (!std::empty(requests.front().elements));
|
||||
requests.pop();
|
||||
} while (!std::empty(requests) && !std::empty(requests.front().elements));
|
||||
if (!std::empty(requests))
|
||||
requests.pop();
|
||||
} while (std::empty(requests));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,8 @@ struct write_some_op {
|
||||
if (ec)
|
||||
break;
|
||||
|
||||
requests.front().sent = true;
|
||||
|
||||
if (std::empty(requests.front().elements)) {
|
||||
// We only pop when all commands in the pipeline has push
|
||||
// We only pop when all commands in the pipeline have push
|
||||
// responses like subscribe, otherwise, pop is done when the
|
||||
// response arrives.
|
||||
requests.pop();
|
||||
@@ -93,12 +91,15 @@ struct write_some_op {
|
||||
|
||||
template<
|
||||
class AsyncWriteStream,
|
||||
class CompletionToken>
|
||||
class CompletionToken =
|
||||
net::default_completion_token_t<typename AsyncWriteStream::executor_type>
|
||||
>
|
||||
auto
|
||||
async_write_some(
|
||||
AsyncWriteStream& stream,
|
||||
std::queue<request>& requests,
|
||||
CompletionToken&& token)
|
||||
CompletionToken&& token =
|
||||
net::default_completion_token_t<typename AsyncWriteStream::executor_type>{})
|
||||
{
|
||||
return net::async_compose<
|
||||
CompletionToken,
|
||||
|
||||
@@ -12,17 +12,11 @@ namespace resp3 {
|
||||
|
||||
bool prepare_next(std::queue<request>& reqs)
|
||||
{
|
||||
if (std::empty(reqs)) {
|
||||
auto const cond = std::empty(reqs) || std::size(reqs) == 1;
|
||||
if (cond)
|
||||
reqs.push({});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (reqs.back().sent) {
|
||||
reqs.push({});
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return cond;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, request::element const& e)
|
||||
|
||||
@@ -37,7 +37,6 @@ public:
|
||||
};
|
||||
std::string payload;
|
||||
std::queue<element> elements;
|
||||
bool sent = false;
|
||||
|
||||
public:
|
||||
/// Return the size of the pipeline. i.e. how many commands it
|
||||
@@ -138,13 +137,20 @@ public:
|
||||
elements.emplace(command::lpop, std::string{key});
|
||||
}
|
||||
|
||||
/// Adds ping to the request, see https://redis.io/commands/subscribe
|
||||
void subscribe(std::string_view key)
|
||||
/// Adds subscribe to the request, see https://redis.io/commands/subscribe
|
||||
void subscribe(std::initializer_list<std::string_view> l)
|
||||
{
|
||||
// The response to this command is a push type.
|
||||
detail::assemble(payload, "SUBSCRIBE", key);
|
||||
std::initializer_list<std::string_view> dummy = {};
|
||||
detail::assemble(payload, "SUBSCRIBE", l, std::cbegin(dummy), std::cend(dummy));
|
||||
}
|
||||
|
||||
void psubscribe(std::initializer_list<std::string_view> l)
|
||||
{
|
||||
std::initializer_list<std::string_view> dummy = {};
|
||||
detail::assemble(payload, "PSUBSCRIBE", l, std::cbegin(dummy), std::cend(dummy));
|
||||
}
|
||||
|
||||
/// Adds ping to the request, see https://redis.io/commands/unsubscribe
|
||||
void unsubscribe(std::string_view key)
|
||||
{
|
||||
@@ -236,12 +242,6 @@ public:
|
||||
elements.emplace(command::lpush, std::string{key});
|
||||
}
|
||||
|
||||
void psubscribe( std::initializer_list<std::string_view> l)
|
||||
{
|
||||
std::initializer_list<std::string_view> dummy = {};
|
||||
detail::assemble(payload, "PSUBSCRIBE", l, std::cbegin(dummy), std::cend(dummy));
|
||||
}
|
||||
|
||||
/// Adds ping to the request, see https://redis.io/commands/publish
|
||||
void publish(std::string_view key, std::string_view msg)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user