简体   繁体   中英

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.

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" ?

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.

In my case I need to avoid it, then is needed set row as true in configs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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