ruby - redis - 错误未知命令 'HELLO' (RedisClient::CommandError)

标签 ruby redis

“我已在本地启用了 Redis,但运行脚本时出现错误。我应该如何解决此问题?”

/home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client/connection_mixin.rb:48:in `call_pipelined': ERR unknown command 'HELLO' (RedisClient::CommandError)
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client.rb:678:in `block in connect'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client/middlewares.rb:16:in `call'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client.rb:677:in `connect'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client.rb:647:in `raw_connection'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client.rb:614:in `ensure_connected'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client.rb:349:in `pipelined'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/redis-client-0.11.1/lib/redis_client/decorator.rb:51:in `pipelined'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/client.rb:214:in `block in raw_push'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:65:in `block (2 levels) in with'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:64:in `handle_interrupt'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:64:in `block in with'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:61:in `handle_interrupt'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:61:in `with'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/client.rb:211:in `raw_push'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/client.rb:92:in `push'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/job.rb:365:in `client_push'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/job.rb:198:in `perform_async'
    from /home/linlin/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/sidekiq-7.0.1/lib/sidekiq/job.rb:290:in `perform_async'

最佳答案

将协议(protocol)版本设置为2可以解决大多数情况下的错误,或者您可以选择将redis-client版本升级到6以上。

redis 协议(protocol)版本可以设置为1 或 2

协议(protocol)版本2是Redis 6.0中引入的增强协议(protocol)版本。

您可以将如下所示的协议(protocol)添加到 redis 配置中,

Sidekiq.configure_client do |config|
  config.redis = {
    url: Rails.application.credentials.config[:REDIS_URL],
    protocol: 2,
  }
end

关于ruby - redis - 错误未知命令 'HELLO' (RedisClient::CommandError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75798268/

相关文章:

ruby-on-rails - 更优雅地处理项目中的 Redis 需求?

ruby - Jekyll - 当我的项目中有分页时出现错误

java - cucumber 测试 java 示例?

ruby : "undefined method"错误;如何更有效地使用 gsub?

caching - 在redis缓存中批量设置

node.js - Redis 到永久存储的迁移

ruby - 运营商 `!=` 是否使用 `==` ?

ruby - 如何从最后一个元素开始遍历数组? ( ruby )

ruby-on-rails - 在这种情况下使用 Redis 合适吗?

Redis在获取键值时响应各种$值