2
votes

In addition to Sidekiq, I have a worker that also makes heavy use of Redis to store keys. Since Sidekiq maintains it's own redis connection pool, the worker takes advantage of that and always connects through Sidekiq's pool.

class MyRedisWorker
  include Sidekiq::Worker

  def perform
    # ...
  end

  def run_redis_cmd(cmd, *args)
    Sidekiq.redis { |conn| conn.send(cmd, *args) }
  end
end

I am now moving over to a multi-tenant model which allows multiple tenants to run on the same app instance and DB (In Postgres this corresponds to just using a different schema for each tenant)

Since each tenant will run its own version of the Worker against Redis and have its own Sidekiq queues, I need to namespace all Redis connections so keys don't conflict. I know Sidekiq provides such an option to use in the initializer -

Sidekiq.configure_server do |config|
  config.redis = { url: URL, network_timeout: 3, namespace: my_tenant_name }
end

Sidekiq.configure_client do |config|
  config.redis = { url: URL, network_timeout: 3, namespace: my_tenant_name }
end

My question is, Sidekiq doesn't maintain multiple sets of pools, each of which can be namespaced individually, right? Looks like it just maintains one top-level pool for which you can optionally provide (up to) 1 namespace. Even the worker just calls Sidekiq.redis { .... } at the top-level, without specifying which pool.

What's the best way around this? I don't necessarily need a dedicated redis pool for each tenant, I just need a way when retrieving a redis connection that Sidekiq will allow me to specify what namespace I want to use for that connection.

Thanks!

1

1 Answers

1
votes

Read about Sidekiq's support for Sharding. I strongly recommend not using namespaces.