random-forest-cat
random-forest-cat

Reputation: 35884

Hashes and Arrays with redis

Suppose I wanted to store a hash containing an array:

{:foo=>[:bar, :baz], :quack => 'duck'}

At first glance I have 2 options.

  1. Serialize the value of :foo and store it it as a string.
  2. Convert the value to a set, store a hash with the key of the set, and rebuild my data structure with 2 queries, for the set and the hash respectively.

The second approach feels messy to me, especially considering the possibility of a hash or multiple hash'es being nested within the array and the work involved rebuilding that structure upon retrieval.

What is the best approach for storing complex data structures with redis?

Is there a better option then the options I've listed that would allow me to take advantage of redis data types?

Upvotes: 2

Views: 84

Answers (1)

John La Rooy
John La Rooy

Reputation: 304127

If you are not sharing the data with other objects, you should just go ahead and serialise them.

...As long as they are under 512MB

Upvotes: 1

Related Questions