[英]Rails Redis Cache stores empty information out of method
My user.rb (model) has the following instance method:我的 user.rb (model) 有以下实例方法:
def points_last_seven_days
last_seven_days_hash_raw = self.reports.group_by_day(series: true) { |r| r.created_at }
out = {}
last_seven_days_hash_raw.each do |day, reports|
out[day.to_s] = reports.last.bullets
end
out
end
When i run User.first.points_last_seven_days
everything goes ok, as expected i get an hash with data.当我运行
User.first.points_last_seven_days
时,一切正常,正如预期的那样,我得到了一个带有数据的 hash。
Now comes the tricky part.现在是棘手的部分。 I have a cache module loading User into redis.
我有一个缓存模块将用户加载到 redis 中。
For that i use, among other things:为此,我使用,除其他外:
def make_cacheable_strings
output_array = []
get_users_for_status.each do |user|
output_array << user.to_json(methods: USER_CACHED_METHODS)
end
output_array
end
My USER_CACHED_METHODS
are as follows:我的
USER_CACHED_METHODS
如下:
USER_CACHED_METHODS = [
...,
:points_last_seven_days
]
The point is: User.last.method_name = correct data重点是: User.last.method_name = 正确的数据
CachedUser["method_name"] ( json redis ) = {} // empty hash... CachedUser["method_name"] ( json redis ) = {} // 空 hash...
What is happening?怎么了?
Thank you谢谢
def points_last_seven_days_json
self.points_last_seven_days.to_json
end
The hash i was trying to inject it was a Object and not a string.我试图注入的 hash 是 Object 而不是字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.