Quantcast
Channel: Redis-Objects in rails saves as String, not array - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Redis-Objects in rails saves as String, not array

$
0
0

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)

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>