Skip to content

feat(pubsub): pattern subscriptions, lazy variants and callback delivery - #316

Draft
Aryex wants to merge 1 commit into
alexl/pubsub-mixin-refactorfrom
alexl/pubsub-part3-advanced-subs
Draft

Aryex wants to merge 1 commit into
alexl/pubsub-mixin-refactorfrom
alexl/pubsub-part3-advanced-subs

Conversation

@Aryex

@Aryex Aryex commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

This implement the advanced pubsub APIs per part 3 of the implementation plan.

Issue link

Related #135

Changes

The following APIs are added

Method Request type
psubscribe(*patterns, timeout_ms: 0) PSUBSCRIBE_BLOCKING (916)
punsubscribe(*patterns, timeout_ms: 0) PUNSUBSCRIBE_BLOCKING (917)
subscribe_lazy(*channels) SUBSCRIBE (911)
unsubscribe_lazy(*channels) UNSUBSCRIBE (913)
psubscribe_lazy(*patterns) PSUBSCRIBE (901)
punsubscribe_lazy(*patterns) PUNSUBSCRIBE (908)

Callback subscriptions is also added:

Valkey.new(protocol: :resp3, pubsub: {
  subscriptions: { exact: ["news"] },
  callback: ->(message, context) { context.handle(message) },
  context: my_app_state
})

Limitations

  • The six sharded verbs and publish(sharded: true) remain NotImplementedError (Part 4).
  • get_subscriptions, the five pubsub_* introspection commands, and pubsub(subcommand, *args) remain NotImplementedError (Part 5), so the lazy verbs' documented "read back get_subscriptions to confirm" workflow is not yet available.
  • No integration coverage in this PR — see Testing.
  • validate_pubsub_callback! checks respond_to?(:call) only. A callable that does not respond to arity passes construction and then fails inside deliver, where the blanket rescue drops every message silently.

Testing

bundle exec rubocop — 124 files, no offenses.

bundle exec rake test:unit — 402 tests, 873 assertions, 0 failures (up from 366; 36 new).

  • test/unit/glide/pubsub_test.rb: 15 new dispatch tests. Request type, argument order and string coercion for all six verbs; timeout coercion for the blocking pair (default 0"0", fractional truncated, sub-millisecond → "1", negative → ArgumentError); a parametrized regression guard that the four lazy verbs send no timeout argument; empty-list behavior per verb. The existing RESP2/nil-protocol sweep was extended to cover all six.
  • test/unit/glide/pubsub_receiver_test.rb (new): 21 tests driving the retained ffi_handler proc directly with real FFI::MemoryPointer buffers, so no server is needed. Queue mode unchanged; callback ordering; arity-1 vs arity-2 dispatch; a raising callback neither propagates nor kills the receiver; pop/try_pop raise in callback mode; ffi_handler object identity retained; non-message push kinds dropped; embedded NUL preserved; and the ArgumentError validation paths.

bundle exec ruby -Itest -Ilib test/integration/standalone/valkey_test.rb — 216 tests, 13 failures, all pre-existing lib_name / client_info_tag assertions unrelated to Pub/Sub, identical to the base branch's baseline. No Pub/Sub test fails.

Integration coverage is deliberately not in this PR. Nothing yet exercises psubscribe → publish → #pattern, the lazy verbs' eventual delivery, or callback mode against a live server. test/integration/valkey/pubsub_test.rb now runs in both standalone and cluster (via TestClusterPubSub), so those tests must be mode-safe; they will follow in a separate PR rather than being added unrun.

bundle exec rake test:cluster has not been run against this stack.

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.

@Aryex
Aryex added this pull request to stack #313 September 14, 2026 16:27
@Aryex
Aryex force-pushed the alexl/pubsub-part3-advanced-subs branch from acf0b4b to 54437c8 Compare September 14, 2026 16:30
Signed-off-by: Alex Le <alex.le@improving.com>
@Aryex
Aryex force-pushed the alexl/pubsub-part3-advanced-subs branch from 54437c8 to fdd9010 Compare September 14, 2026 22:00
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.

1 participant