-
Notifications
You must be signed in to change notification settings - Fork 43
Adds support for PubSub state restoration #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
anarthal
wants to merge
15
commits into
boostorg:develop
Choose a base branch
from
anarthal:feature/pubsub-state-restoration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+407
−99
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6fa34c2
Initial impl
anarthal cef6125
pubsub_state impl
anarthal 67cb8e0
Initial request impl
anarthal f1e9772
start_command
anarthal 278a99f
parsing workaround
anarthal e502703
clear and append
anarthal e820b45
some namespace changes
anarthal 1a0d94c
namespace moving
anarthal 7e9ab02
hide constructor
anarthal 3a31d23
hide parse_last_argument
anarthal ddea2a9
Make the setting global
anarthal 0c79084
clean multiplexer up
anarthal f611ced
Update the example
anarthal 14af2c9
Use the new extension point in json
anarthal 9ed3825
Restore add_bulk
anarthal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // | ||
| // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com), | ||
| // Ruben Perez Hidalgo (rubenperez038 at gmail dot com) | ||
| // | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| // | ||
|
|
||
| #ifndef BOOST_REDIS_PUBSUB_STATE_HPP | ||
| #define BOOST_REDIS_PUBSUB_STATE_HPP | ||
|
|
||
| #include <set> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| namespace boost::redis { | ||
|
|
||
| class request; | ||
|
|
||
| namespace detail { | ||
|
|
||
| enum class pubsub_change_type; | ||
|
|
||
| class pubsub_state { | ||
anarthal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::set<std::string> channels_; | ||
| std::set<std::string> pchannels_; | ||
|
|
||
| public: | ||
| pubsub_state() = default; | ||
| void clear(); | ||
| void commit_change(pubsub_change_type type, std::string_view channel); | ||
| void commit_changes(const request& req); | ||
| void compose_subscribe_request(request& to) const; | ||
| }; | ||
|
|
||
| } // namespace detail | ||
| } // namespace boost::redis | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // | ||
| // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com), | ||
| // Ruben Perez Hidalgo (rubenperez038 at gmail dot com) | ||
| // | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| // | ||
|
|
||
| #include <boost/redis/detail/pubsub_state.hpp> | ||
| #include <boost/redis/request.hpp> | ||
|
|
||
| #include <boost/assert.hpp> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace boost::redis::detail { | ||
|
|
||
| void pubsub_state::clear() | ||
| { | ||
| channels_.clear(); | ||
| pchannels_.clear(); | ||
| } | ||
|
|
||
| void pubsub_state::commit_change(pubsub_change_type type, std::string_view channel) | ||
| { | ||
| std::string owning_channel{channel}; | ||
| switch (type) { | ||
| case pubsub_change_type::subscribe: channels_.insert(std::move(owning_channel)); break; | ||
| case pubsub_change_type::unsubscribe: channels_.erase(std::move(owning_channel)); break; | ||
| case pubsub_change_type::psubscribe: pchannels_.insert(std::move(owning_channel)); break; | ||
| case pubsub_change_type::punsubscribe: pchannels_.erase(std::move(owning_channel)); break; | ||
| default: BOOST_ASSERT(false); | ||
| } | ||
| } | ||
|
|
||
| void pubsub_state::commit_changes(const request& req) | ||
| { | ||
| for (const auto& ch : detail::request_access::pubsub_changes(req)) | ||
anarthal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| commit_change(ch.type, req.payload().substr(ch.channel_offset, ch.channel_size)); | ||
| } | ||
|
|
||
| void pubsub_state::compose_subscribe_request(request& to) const | ||
| { | ||
| to.push_range("SUBSCRIBE", channels_); | ||
| to.push_range("PBSUBSCRIBE", pchannels_); | ||
| } | ||
|
|
||
| } // namespace boost::redis::detail | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.