Windows下Redis升级至v4后Rails缓存连接异常配置问询
开发场景与异常现象
基础环境说明
- 操作系统为 Windows,此前使用 Redis v2 时,Rails 自带的
cache_store功能可正常运行。 - 当前正在基于 Sidekiq 实现 ActiveJob 能力,该功能要求 Redis 版本不低于 v3。为此安装了社区维护的 Windows 适配版 Redis,先后测试 v4、v5 版本;通过 .msi 安装包完成安装并重启系统后,经
redis-cli验证 Redis 服务可正常连接。
Rails 端现有配置
开发环境配置位于 config/environments/development.rb 文件中,缓存相关配置项如下:
config.cache_store = :redis_cache_store, { url: 'redis://localhost:6379/0' }
控制台测试输出
在 Rails 控制台执行相关验证命令,得到的输出结果如下:
>> Rails.cache => #<ActiveSupport::Cache::RedisCacheStore options={:namespace=>nil, :compress=>true, :compress_threshold=>1024, :expires_in=>nil, :race_condition_ttl=>nil} redis=#<Redis client v4.2.5 for redis://localhost:6379/0>> >> Rails.cache.redis.connected? => false >> t = Rails.cache.fetch('test') { 'T' } => "T" >> r = Redis.new => #<Redis client v4.2.5 for redis://127.0.0.1:6379/0> >> r.get 'test' => "123" >> r.connected? => true
核心待排查问题
Rails 内置缓存模块持有的 Redis 实例,在查询连接状态时返回未连接,但实际执行缓存读写操作可正常返回结果;手动独立新建的 Redis 客户端实例可正常建立连接、执行读写操作。需定位现有配置存在的具体问题。
内容的提问来源于stack exchange,提问作者mdwpilot
相关产品推荐
相关产品推荐

