Storing a hash of hashes in Redis

2.9k views Asked by At

What's the best way to store an hash in Redis which looks like this:

id1->{key1->value1, key2->value2, key3->value3….} , id3->{key1->value1, key2->value2, key3->value3….} ….

where key1, key2, key3... is two-letters code of language (en, es, etc), but some of they keys can have different set of languages, and a key can have about 30 different languages.

1

There are 1 answers

0
Ofir Luzon On BEST ANSWER

This fits just right in Redis HASH, you can use HMSET to add all fields to each hash:

HMSET id1 key1 value1 key2 value2 ...
HMSET id2 key1 value1 key2 value2 ...
HMSET id3 key1 value1 key2 value2 ...
...

You might want to SADD all HASHs key names into a SET to be able to get all of their names:

SADD ids id1 id2 id3 ...