How to store a simple hash

90 views
Skip to first unread message

hyn

unread,
Jul 13, 2011, 7:09:16 AM7/13/11
to Ohm Ruby
Feels like a stupid question but.. how should I store a simple hash of
string key-values? Should I store it as a JSON string, or is there a
more 'native' way to do this?

Thanks

cyx

unread,
Jul 13, 2011, 7:19:22 AM7/13/11
to Ohm Ruby
Hi hyn,

My first choice for this would be to use Ohm::Contrib (http://
github.com/cyx/ohm-contrib) and
it's typecasting module.

class User < Ohm::Model
include Ohm::Typecast

attribute :some_data, Hash
end

If I need more control over the data in-redis, I'll probably store it
as a HASH though.

Regards,
cyx

hyn

unread,
Jul 13, 2011, 7:45:19 AM7/13/11
to Ohm Ruby
Okay, so it performs serialization under the hood.

Since my hash could be around 150+ bytes and I only need to retrieve
something like 10 bytes at a time, the redis HASH might make more
sense, so I don't have to read the entire hash.

Thanks
Reply all
Reply to author
Forward
0 new messages