Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: discourse/message_bus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.3.9
Choose a base ref
...
head repository: discourse/message_bus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.4.0
Choose a head ref
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Mar 14, 2025

  1. DEV: Add compatibility with the redis gem 5+ (#360)

    Flink authored Mar 14, 2025
    Copy the full SHA
    38e4514 View commit details
Showing with 28 additions and 48 deletions.
  1. +4 −4 .github/workflows/ci.yml
  2. +6 −0 CHANGELOG
  3. +1 −1 README.md
  4. +4 −2 lib/message_bus.rb
  5. +12 −34 lib/message_bus/backends/redis.rb
  6. +1 −1 lib/message_bus/version.rb
  7. +0 −6 spec/integration/http_client_spec.rb
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ jobs:

test:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }} (redis ${{ matrix.redis }})
name: Ruby ${{ matrix.ruby }} (${{ matrix.redis }})
timeout-minutes: 10

env:
@@ -47,8 +47,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.6", "2.7", "3.0", "3.1"]
redis: [5, 6]
ruby: ["3.2", "3.3", "3.4"]
redis: ["redis:5", "redis:6", "valkey/valkey"]

services:
postgres:
@@ -60,7 +60,7 @@ jobs:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: ${{ format('redis:{0}', matrix.redis) }}
image: ${{ matrix.redis }}
ports:
- 6379:6379
options: >-
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
14-03-2025

- Version 4.4.0

- Add compatibility with the redis gem version 5+.

18-02-2025

- Version 4.3.9
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ Read the generated docs: <https://www.rubydoc.info/gems/message_bus>

## Ruby version support

MessageBus only support officially supported versions of Ruby; as of [2021-03-31](https://www.ruby-lang.org/en/downloads/branches/) this means we only support Ruby version 2.6 and up.
MessageBus only support officially supported versions of Ruby; as of [2025-03-14](https://www.ruby-lang.org/en/downloads/branches/) this means we only support Ruby version 3.2 and up.

## Can you handle concurrent requests?

6 changes: 4 additions & 2 deletions lib/message_bus.rb
Original file line number Diff line number Diff line change
@@ -184,10 +184,12 @@ def configure(config)
# @param [Hash<Symbol => Object>] config values to merge into existing config
# @return [void]
def redis_config=(config)
configure(config.merge(backend: :redis))
configure(backend: :redis, redis_config: config)
end

alias redis_config config
def redis_config
@config[:redis_config] || {}
end

# @yield [env] a routine to determine the site ID for a subscriber
# @yieldparam [optional, Rack::Request::Env] env the subscriber request environment
46 changes: 12 additions & 34 deletions lib/message_bus/backends/redis.rb
Original file line number Diff line number Diff line change
@@ -40,16 +40,18 @@ def initialize(highest_id)
end
end

# @param [Hash] redis_config in addition to the options listed, see https://github.com/redis/redis-rb for other available options
# @option redis_config [Logger] :logger a logger to which logs will be output
# @option redis_config [Boolean] :enable_redis_logger (false) whether or not to enable logging by the underlying Redis library
# @option redis_config [Integer] :clear_every (1) the interval of publications between which the backlog will not be cleared
# @param [Hash] config
# @option config [Hash] :redis_config options for the redis connection (see https://github.com/redis/redis-rb)
# @option config [Logger] :logger a logger to which logs will be output
# @option config [Boolean] :enable_redis_logger (false) whether or not to enable logging by the underlying Redis library
# @option config [Integer] :clear_every (1) the interval of publications between which the backlog will not be cleared
# @param [Integer] max_backlog_size the largest permitted size (number of messages) for per-channel backlogs; beyond this capacity, old messages will be dropped.
def initialize(redis_config = {}, max_backlog_size = 1000)
@redis_config = redis_config.dup
@clear_every = redis_config.delete(:clear_every) || 1
@logger = @redis_config[:logger]
@redis_config[:logger] = nil unless @redis_config[:enable_redis_logger]
def initialize(config = {}, max_backlog_size = 1000)
@config = config.dup
@redis_config = config[:redis_config].dup || {}
@clear_every = config[:clear_every] || 1
@logger = @config[:logger]
@config[:logger] = nil unless @config[:enable_redis_logger]
@max_backlog_size = max_backlog_size
@max_global_backlog_size = 2000
@max_in_memory_publish_backlog = 1000
@@ -331,31 +333,7 @@ def global_subscribe(last_id = nil, &blk)
private

def new_redis_connection
config =
@redis_config.filter do |k, v|
# This is not ideal, required for Redis gem version 5
# redis-client no longer accepts arbitrary params
# anything unknown will error out.
# https://github.com/redis-rb/redis-client/blob/4c8e05acfb3477c1651138a4924616e79e6116f2/lib/redis_client/config.rb#L21-L39
#
#
# We should be doing the opposite and allowlisting params
# or splitting the object up. Starting with the smallest change that is backwards compatible
!%i[
backend
logger
long_polling_enabled
long_polling_interval
backend_options
base_route
client_message_filters
site_id_lookup
group_ids_lookup
user_id_lookup
transport_codec
].include?(k)
end
::Redis.new(config)
::Redis.new(@redis_config)
end

# redis connection used for publishing messages
2 changes: 1 addition & 1 deletion lib/message_bus/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MessageBus
VERSION = "4.3.9"
VERSION = "4.4.0"
end
6 changes: 0 additions & 6 deletions spec/integration/http_client_spec.rb
Original file line number Diff line number Diff line change
@@ -16,14 +16,8 @@ def publish_message
assert_equal("200", response.code)
end

before do
@threads = Thread.list
end

after do
new_threads = Thread.list - @threads
client.stop
new_threads.each(&:join)
end

describe '#start and #stop' do