我需要使用 redis-objects 将哈希存储到 Redis 中 gem 。从 README 中,他们有 hash_key
。但是没有这方面的例子。
我得到一个错误:
NoMethodError: undefined method `fantasy_points_details=' for #<InningPlayer:0x007f820adb68a0>
当我这样做时:
inning_player_instance.fantasy_points_details = {a: 1}
对于这样的模型:
class InningPlayer < ActiveRecord::Base
include Redis::Objects
hash_key :fantasy_points_details
end
但是 setter/getter 起作用了:
> inning_player_instance.fantasy_points_details
=> #<Redis::HashKey:0x007f820adf4470>
最佳答案
在 HashKey class 上使用更新方法:
> inning_player_instance.fantasy_points_details.update({"a"=>"3", "c"=>"4"})
=> "OK"
阅读:
> ip.fantasy_points_details.all
=> {"a"=>"3", "c"=>"4"}
关于ruby-on-rails - 如何在 Redis 对象 gem 中使用 hash_key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33460154/