Redis in Rails 4

Asked

Viewed 66 times

0

I have an Item template. Can you store 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")

He returns to me "#<Item::ActiveRecord_Relation:0x007fe399d6e550>" that is a String...

The idea was to save an Array of items.

1 answer

1

An alternative is to keep the .first of this relation:

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

$redis.set("itens", Item.where(true).first)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.