【问题标题】:Rails adding extra line in my redis cacheRails 在我的 redis 缓存中添加了额外的行
【发布时间】:2018-08-07 04:38:18
【问题描述】:

我在我的项目中使用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

这是结果

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

这是什么?

【问题讨论】:

    标签: ruby-on-rails ruby caching redis


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-06-24
      • 1970-01-01
      • 2020-03-12
      • 1970-01-01
      • 2011-07-15
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多