redis / redis-rb

A Ruby client library for Redis
MIT License
3.96k stars 1.03k forks source link

Unable to load application: TypeError: superclass mismatch for class Cluster #1240

Closed dil-atiwari closed 9 months ago

dil-atiwari commented 9 months ago

I have added redis-clustering gem and when I start the rails server I am getting below error. I couldn't find any open or closed issue. Any help is appreciated thanks

Unable to load application: TypeError: superclass mismatch for class Cluster
 bundler: failed to load command: puma (/usr/local/bundle/gems/ruby/3.0.0/bin/puma)
 /usr/local/bundle/gems/ruby/3.0.0/gems/redis-clustering-5.0.0.beta3/lib/redis/cluster.rb:8:in `<class:Redis>': superclass mismatch for class Cluster (TypeError)
     from /usr/local/bundle/gems/ruby/3.0.0/gems/redis-clustering-5.0.0.beta3/lib/redis/cluster.rb:5:in `<top (required)>'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/redis-4.8.1/lib/redis.rb:299:in `require'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/redis-4.8.1/lib/redis.rb:299:in `<top (required)>'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-6.5.9/lib/sidekiq/redis_connection.rb:4:in `require'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-6.5.9/lib/sidekiq/redis_connection.rb:4:in `<top (required)>'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-6.5.9/lib/sidekiq.rb:11:in `require'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-6.5.9/lib/sidekiq.rb:11:in `<top (required)>'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-pro-5.5.8/lib/sidekiq-pro.rb:3:in `require'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/sidekiq-pro-5.5.8/lib/sidekiq-pro.rb:3:in `<top (required)>'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:60:in `require'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:55:in `each'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:55:in `block in require'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:44:in `each'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/runtime.rb:44:in `require'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler.rb:187:in `require'
     from /usr/src/app/config/application.rb:8:in `<top (required)>'
     from /usr/src/app/config/environment.rb:2:in `require_relative'
     from /usr/src/app/config/environment.rb:2:in `<top (required)>'
     from config.ru:3:in `require_relative'
     from config.ru:3:in `block in <main>'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/rack-2.2.7/lib/rack/builder.rb:116:in `eval'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/rack-2.2.7/lib/rack/builder.rb:116:in `new_from_string'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/rack-2.2.7/lib/rack/builder.rb:105:in `load_file'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/rack-2.2.7/lib/rack/builder.rb:66:in `parse_file'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/configuration.rb:366:in `load_rackup'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/configuration.rb:288:in `app'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/runner.rb:158:in `load_and_bind'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/cluster.rb:359:in `run'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/launcher.rb:194:in `run'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/lib/puma/cli.rb:75:in `run'
     from /usr/local/bundle/gems/ruby/3.0.0/gems/puma-6.3.0/bin/puma:10:in `<top (required)>'
     from /usr/local/bundle/gems/ruby/3.0.0/bin/puma:25:in `load'
     from /usr/local/bundle/gems/ruby/3.0.0/bin/puma:25:in `<top (required)>'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli/exec.rb:58:in `load'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli/exec.rb:58:in `kernel_load'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli/exec.rb:23:in `run'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli.rb:492:in `exec'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli.rb:34:in `dispatch'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/cli.rb:28:in `start'
     from /usr/local/bundle/gems/bundler-2.4.21/exe/bundle:37:in `block in <top (required)>'
     from /usr/local/bundle/gems/bundler-2.4.21/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
     from /usr/local/bundle/gems/bundler-2.4.21/exe/bundle:29:in `<top (required)>'
     from /usr/local/bundle/bin/bundle:23:in `load'
     from /usr/local/bundle/bin/bundle:23:in `<main>'

Ruby - 3.0.6 Rails - 7.0.6

Gemfile

gem 'redis'
gem 'redis-namespace'
gem 'redis-clustering'
gem 'sidekiq-pro', '~> 5.5.5'

Gemfile.lock

  sidekiq-pro (5.5.8)
      sidekiq (~> 6.0, >= 6.5.6)
   sidekiq (6.5.9)
    redis (4.8.1)
    redis-client (0.18.0)
      connection_pool
    redis-cluster-client (0.7.5)
      redis-client (~> 0.12)
    redis-clustering (5.0.0.beta3)
      redis-cluster-client (~> 0.2)
supercaracal commented 9 months ago

Could you bump the redis-clustering gem version to the latest?

https://rubygems.org/gems/redis-clustering

dil-atiwari commented 9 months ago

@supercaracal If I try to add the latest then I get the below error

Could not find compatible versions

Because redis-clustering >= 5.0.8 depends on redis = 5.0.8
  and sidekiq >= 6.5.6, < 7.0.0.beta1 depends on redis >= 4.5.0, < 5,
  redis-clustering >= 5.0.8 is incompatible with sidekiq >= 6.5.6, < 7.0.0.beta1.
And because sidekiq-pro >= 5.5.5, < 6.0.0.beta1 depends on sidekiq >= 6.5.6, < 7.A,
  redis-clustering >= 5.0.8 is incompatible with sidekiq-pro >= 5.5.5, < 6.0.0.beta1.
So, because Gemfile depends on sidekiq-pro ~> 5.5.5
  and Gemfile depends on redis-clustering = 5.0.8,
  version solving has failed.
supercaracal commented 9 months ago

Since the above dependencies, you can't use redis-clustering gem because you use sidekiq-pro versioned with 5.5.8. The redis gem had supported features of cluster mode until 4.x and it was decoupled to redis and redis-clustering since 5.x. Although I'm not familiar with sidekiq, it seems that sidekiq 7.x might be compatible with redis-clustering.

dil-atiwari commented 9 months ago

@supercaracal I cannot use sidekiq 7.x as it doesn;t support redis-namespace. Is there any workaround with the existing gems which i can downgrade to make it compatible for my usecase?

supercaracal commented 9 months ago

I think there is no workarounds. Since sidekiq owner says, you can't use Redis cluster.

dil-atiwari commented 9 months ago

@supercaracal I was able to make it work with the below configuration for one of my microservice. For one of my project we have Rails 7 and ruby 3 and there it doesn't work

Rails 6.1.7.6 Ruby 2.7.8 Sidekiq 6.0.7 sidekiq-pro 5.0.1 redis-namespace 1.7.0 redis-client 0.18.0 redis-clustering 5.0.0.beta3

supercaracal commented 9 months ago

You can specify the older version of the redis-cluster-client gem in your Gemfile. The redis-clustering gem doesn't specify the strict version range for the redis-cluster-client gem. It's recommended to use the latest version of the both. But your case, you're obliged to use older versions of the redis-cluster-client gem. Anyway, since older sidekiq doesn't support Redis cluster, I don't know the combination works or not.