如何在Redis Objects gem中使用hash_key?

时间:2015-11-01 07:37:06

标签: ruby-on-rails ruby hash redis

我需要使用redis-objects gem将哈希存储到Redis中。从自述文件中,他们有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

对于这样的模型:

 > inning_player_instance.fantasy_points_details
 => #<Redis::HashKey:0x007f820adf4470>

但吸气剂有效:

>  inning_player_instance.fantasy_points_details.update({"a"=>"3", "c"=>"4"})
=> "OK"

1 个答案:

答案 0 :(得分:0)

使用HashKey class上的更新方法:

> ip.fantasy_points_details.all
=> {"a"=>"3", "c"=>"4"}

阅读:

class DTN {
  public:
    DTN () :
      is_word(false), word_to_here(""), children()
    {}
    DTN (bool iw, std::string wth) :
      is_word(iw), word_to_here(wth), children()
    {}
    bool                     is_word;
    std::string              word_to_here;
    Map<char,DTN>  children;
};