You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Redis报错ERR unknown command 'HELLO',本地Ruby脚本运行问题求助

问题描述

本地已启用Redis服务,但运行Ruby脚本时触发以下错误:

/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'
解决方法

这个错误的核心是本地Redis版本过低,不支持HELLO命令——该命令是Redis 6.0才引入的,而当前使用的Redis版本低于6.0,导致redis-client库发送命令时触发报错。以下是三种可行的解决方式:

方案1:升级Redis到6.0及以上版本

直接更新本地Redis到支持HELLO命令的版本,具体步骤根据系统而定:

  • 若用包管理器安装:macOS执行brew upgrade redis,Ubuntu执行sudo apt update && sudo apt upgrade redis-server。
  • 升级完成后重启Redis服务,再运行Ruby脚本即可。

方案2:降级redis-client到兼容旧版Redis的版本

如果暂时不想升级Redis,可降低redis-client版本到不默认发送HELLO命令的版本(0.10.x及更早版本):

gem uninstall redis-client -v 0.11.1
gem install redis-client -v 0.10.1

若使用Gemfile管理依赖,可指定版本后更新:

gem 'redis-client', '~> 0.10.1'

执行bundle install完成依赖更新。

方案3:临时禁用redis-client的HELLO命令

不想升级Redis也不想降级gem的话,可在初始化Redis客户端时显式禁用HELLO命令:

redis = RedisClient.new(host: "localhost", port: 6379, hello: false)

如果和Sidekiq配合使用,修改Sidekiq配置:

Sidekiq.configure_client do |config|
  config.redis = { url: "redis://localhost:6379/0", hello: false }
end

Sidekiq.configure_server do |config|
  config.redis = { url: "redis://localhost:6379/0", hello: false }
end

内容的提问来源于stack exchange,提问作者zero20210602

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 02:57:13