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

问题描述 投票:1回答:1

我在我的项目中使用redis-rails来存储用户的缓存,我不知道为什么在缓存开始时添加额外的行。

这是我的配置:

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

这是我的代码:

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

这是结果Result

在第1行,o: ActiveSupport::Cache::Entry:@valueI"�

这是什么?

ruby-on-rails ruby caching redis
1个回答
0
投票

在项目仓库中打开一个问题后,我发现这是使用该数据包装缓存的rails的默认行为。

在我的情况下,我需要避免它,然后需要在配置中将row设置为true

config.cache_store = :redis_store, {
  host: ENV['REDIS_SERVER'] || 'localhost',
  port: 6379,
  db: 0,
  namespace: ENV['CUSTOMER'],
  raw: true
}
© www.soinside.com 2019 - 2024. All rights reserved.