Get Two Rails apps to share the same Redis data

亡梦爱人 提交于 2021-01-28 05:36:36

问题


I have two rails apps. The first app constantly calculates some data and stores it in Redis (This app is running on JRuby 1.7.4 and Rails 4). The second app reads this data from the same Redis server (This app is running on Ruby 2.0.0 and Rails 4). After trying to achieve this configuration in my local development environment, it's apparent that my Redis data is not being shared between the two apps. In both apps, my config/initializers/redis.rb file looks like this:

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
$redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)

When I open up a rails console in either app, the Redis client looks like this (same database, same uri, same path, etc):

#<Redis client v3.0.4 for redis://localhost:6379/0>

But when I try to set a key/value in one app, the same key is not found in the other app. I feel like I'm missing something simple here.

SOLVED: I was using the fake-redis gem in development for one of my apps. This is why Redis appeared to be working in both apps but not sharing the data. Thanks for the help.

来源:https://stackoverflow.com/questions/18939394/get-two-rails-apps-to-share-the-same-redis-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!