使用 redis-store(redis-rails) 在 Redis 上建立 SSL 连接的方法

当使用rediss://hogehoge格式尝试进行SSL连接时,redis-rails却忽略SSL,并试图使用redis://hogehoge进行连接的问题。

实际的问题出在redis-rails中使用的redis-store库,这个问题正在处理中,似乎很快就会被合并

处理方法

如果需要迅速应对的解决方案,可以通过散列方式传递连接信息,就可以了。

Rails.application.config.session_store :redis_store,
  servers: URI.parse(ENV['REDIS_SESSION_STORE']).tap { |uri|
    break {
      host: uri.host,
      port: uri.port,
      password: uri.password ? CGI.unescape(uri.password) : nil,
      db: uri.path.split('/')[1] || 0,
      namespace: uri.path.split('/')[2] || nil,
      scheme: uri.scheme,
    }.compact
  }