简体   繁体   English

Rails在我的Redis缓存中添加额外的行

[英]Rails adding extra line in my redis cache

Im using redis-rails in my project to store a cache of users, and I don't know why a extra line is added at begining of cache. 我在项目中使用redis-rails来存储用户缓存,但我不知道为什么在缓存开始时要添加额外的一行。

This is my config: 这是我的配置:

config.cache_store = :redis_store, {
  host: ENV['REDIS_SERVER'] || 'localhost',
  port: 6379,
  db: 0,
  namespace: ENV['CUSTOMER']
}

This is my code: 这是我的代码:

namespace :update_employees_cache do
  desc "Update employees cache"
  task update: :environment do
    employees = []

    Employee.where(active: true).each do |item|
      employees.push({ id: item.id, name: item.name })
    end

    Rails.cache.write "employees", employees.to_json
  end
end

This is the result 这是结果 结果

At line 1, o: ActiveSupport::Cache::Entry:?@valueI" ? 在第1行, o: ActiveSupport::Cache::Entry:?@valueI" ?

What is this? 这是什么?

After open a issue in the project repo I discovered that is the default behavior of rails wrapping the cache with that data. 在项目仓库中打开一个问题后,我发现这是Rails用该数据包装高速缓存的默认行为。

In my case I need to avoid it, then is needed set row as true in configs. 就我而言,我需要避免它,然后需要在配置中将row设置为true

config.cache_store = :redis_store, {
  host: ENV['REDIS_SERVER'] || 'localhost',
  port: 6379,
  db: 0,
  namespace: ENV['CUSTOMER'],
  raw: true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM