Skip to content

refactor(pubsub): mixin refactor - #311

Open
Aryex wants to merge 7 commits into
mainfrom
alexl/pubsub-mixin-refactor
Open

Aryex wants to merge 7 commits into
mainfrom
alexl/pubsub-mixin-refactor

Conversation

@Aryex

@Aryex Aryex commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR refactor the PubSub handler class into a mixin module, per the comment here.

Issue link

Related #135

Changes

  • PubSub handler class removed
  • Pubsub handlings moved into the mixin module pubsub_commands.rb
  • Plumbing code for unit tests

Limitations

  • No functional changes.

Testing

All integration tests passed locally. Unit tests assertions were not touched, only plumbing code.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to an issue.
  • Commit message describe your changes
  • Commits are signed off (git commit -s) per the DCO.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Linters have been run (bundle exec rubocop) and pass.
  • Destination branch is correct.

@Aryex
Aryex changed the base branch from main to alexl/inline-pubsub September 9, 2026 22:43
@Aryex Aryex changed the title refactor(pubsub): move Pub/Sub onto the command-mixin architecture refactor(pubsub): mixin refactor Sep 9, 2026
@Aryex
Aryex added this pull request to stack #313 September 10, 2026 22:35
@Aryex
Aryex force-pushed the alexl/pubsub-mixin-refactor branch from 7472873 to cb06201 Compare September 10, 2026 23:00
Base automatically changed from alexl/inline-pubsub to main September 14, 2026 16:27
Signed-off-by: Alex Le <alex.le@improving.com>
Signed-off-by: Alex Le <alex.le@improving.com>
Signed-off-by: Alex Le <alex.le@improving.com>
@Aryex
Aryex force-pushed the alexl/pubsub-mixin-refactor branch from cb06201 to 7ba0a01 Compare September 14, 2026 16:27
@Aryex
Aryex marked this pull request as ready for review September 14, 2026 16:28
Signed-off-by: Alex Le <alex.le@improving.com>
Comment thread lib/valkey/pipeline.rb Outdated
# rubocop:enable Lint/UselessMethodDefinition

def subscribe(*_channels, timeout_ms: 0)
raise CommandError, "subscribe is not supported in a pipeline or transaction"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valkey::CommandError is the base for server-side command errors (WrongTypeError, NoScriptError, etc.). Calling subscribe on a pipeline is a caller mistake, and the existing precedent in this repo is ArgumentError: Pipeline#call with route: and ft_search/ft_aggregate inside a batch both raise ArgumentError with a "not supported inside pipelined/multi" message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in b7f9bc9

Comment thread .rubocop.yml Outdated
Metrics/ClassLength:
Exclude:
- 'lib/valkey.rb'
- 'lib/valkey/pipeline.rb'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest removing this, and the Lint/UnusuedMethodArgument lint, and replacing the implementation in pipeline.rb with

%i[subscribe unsubscribe psubscribe ... pubsub_shardnumsub].each do |name|
  define_method(name) do |*, **|
    raise ArgumentError, "#{name} is not supported inside pipelined/multi"
  end
end

Future unused-arg bugs in pipeline.rb ought to be caught.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in b7f9bc9

Comment thread lib/valkey/commands/pubsub_commands.rb Outdated
# valkey.try_get_pubsub_message
# # => nil
#
# @return [Valkey::Commands::PubSubCommands::Message, nil] the message, or `nil` when the queue is empty or the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming seems redundant, and pretty verbose.

Valkey::Commands::PubSubCommands::Message for what a user gets back form every get_pubsub_message is pretty long.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e3948eb.

Moved PushKind to internal class since users won't need to use it.

The other two types are now Valkey::Glide::PubSubState and Valkey::Glide::PubSubMessage.

@nderraugh

Copy link
Copy Markdown
Collaborator

Are you planning to beef up the testing around pubsub alongside pipelined, multi, and Pipeline.new?

Signed-off-by: Alex Le <alex.le@improving.com>
@Aryex

Aryex commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

Are you planning to beef up the testing around pubsub alongside pipelined, multi, and Pipeline.new?

Yes, pipeline pubsub support would be handled in a separate PR.

Signed-off-by: Alex Le <alex.le@improving.com>
Signed-off-by: Alex Le <alex.le@improving.com>
@Aryex
Aryex force-pushed the alexl/pubsub-mixin-refactor branch from b0c2b69 to e3948eb Compare September 14, 2026 21:24
@Aryex
Aryex requested review from jamesx-improving and nderraugh and removed request for prateek-kumar-improving September 14, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants