0

我已经在 heroku 上部署了 Rails 应用程序,我正在使用 Heroku-redis premium0 插件。

我正在检查 redis 中是否存在密钥,然后从 redis 获取数据,否则调用 API,但有时即使密钥存在于 redis 中,Rails.cache.exist?(key) 也会返回 false,例如在 production.rb

 config.cache_store  = :redis_cache_store
key = "Location_testing123"
if Rails.cache.exists?(key)
   data = Rails.cache.fetch(key)
else
  Rails.logger.info "KEY_NOT_FOUND #{@key},Existing keys are #{Rails.cache.redis.keys}"
  data = call_api
end

但我检查了我的 Heroku 日志显示

2020-07-23T09:30:31.651892+00:00 app[web.1]: I, [2020-07-23T09:30:31.651740 #10]  INFO -- : [bb090357-d9a3-407b-9f76-efbfb1dd1fde] KEY_NOT_FOUND Location_testing123,Existing keys are ["Location_testing120","Location_testing123","Location_testing124", "stat:processed:2020-07-18"]

上述问题不一致,只是有时会发生

4

0 回答 0