我正在尝试将 redis 与 rails 和命名空间一起使用。 在我的 application.rb 中,我输入:
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes }
这里的 localhost 是我正在开发我的 rails 项目的 windows 中的 redis。
在我的 config/initializers/redis.rb 中:
$redis = Redis::Namespace.new("my_app_name", :redis => Redis.new)
从我的 Controller 我可以完美地访问它。
$redis.set("foo","bar")
word=$redis.get("foo")
puts word -------> output is "bar".
但我无法访问另一台 linux 服务器上的 Redis,而不是本地主机。 我试着这样做:
config.cache_store = :redis_store, 'redis://that_server_ip:6379/0', { expires_in: 90.minutes }
但我不断得到
Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (Redis::TimeoutError)).
最佳答案
您的错误消息说它仍在尝试连接到本地主机,但失败了。您可能需要重新启动您的应用程序才能接受新配置。
关于ruby-on-rails - 无法连接到远程 redis(带 rails ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30997875/