Redis in Rails 4

0

I have an Item template. Can you save Item.all (Item :: ActiveRecord_Relation) in Redis? I tried to do so:

$redis = Redis::Namespace.new("suggestme", :redis => Redis.new)

$redis.set("itens", Item.all)

But when I give:

$redis.get("itens")

It returns me "#<Item::ActiveRecord_Relation:0x007fe399d6e550>" which is a String ...

The idea was to save an Array of items.

    
asked by anonymous 25.08.2014 / 22:27

1 answer

1

One alternative is to save .first of this relation:

$redis = Redis::Namespace.new("suggestme", :redis => Redis.new)

$redis.set("itens", Item.where(true).first)
    
27.08.2014 / 20:21