I am using the redis-objects gem to store simple info
class Purchase < ActiveRecord::Base include Redis::Objects hash_key :user_purchases, :marshal => true, :global => true # "hash" is taken by Ruby def self.add_user_end(fb_id,item_id) if self.user_purchases[fb_id] a = Array.new a << candidate_id self.user_purchases[fb_id] = a else new_a = self.user_purchases[fb_id] new_a << item_id self.user_purchases[fb_id] = new_a end endend
I'm creating a method to collect user_purchases as a hasy_key, keyed by a users fb id. I would imply like to see a collection of ids when I use Purchase.user_purchases["2"] => [1,23,563,2]
I am running into a problem with Redis::Object where I can only save this as a string: Why?
1.9.3-p125 :050 > Purchase.user_purchases["6"].class => String 1.9.3-p125 :051 > Purchase.user_purchases["6"] => "\u0004\b[\u0006I\"\v543555\u0006:\u0006ET"
Answer:
My Initialization file was missing require 'redis/list'
require 'redis'require 'redis/objects'require 'redis/hash_key'require 'redis/list'Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)