Killerpixler
Killerpixler

Reputation: 4050

ruby get part of a hash redis

I have this type of hash stored in variable foo

{:name=>"bobby", :data=>[[1, 2], [3, 4], [5, 6], [7, 8]]}

when I try foo[:data] I get no implicit conversion of Symbol into Integer

How do I get the 2d array?

EDIT

This is the entire code:

redis = Redis.new
  redis.set "foo", {name: "bobby", :data => [
    [1,2],[3,4],[5,6],[7,8]
  ]}
  foo = redis.get "foo"
  puts foo[:data][0]

Upvotes: 0

Views: 587

Answers (1)

BroiSatse
BroiSatse

Reputation: 44685

redis.get returns a string, not a hash. This string is JSON representation of the hash. Try:

require 'json'
foo = JSON.parse(redis.get "foo")
puts foo['data']

Upvotes: 1

Related Questions