Hi,
there are several ways to do it - the choice mainly
depends on the access pattern.
For instance you can build a JSON object like with mongodb
and store it directly in a Redis string.
So you would have three kinds of objects:
- documents (as in the mongodb example)
- countries
- persons
Up to your application to serialize/deserialize the documents
to set/get the various fields, including references to countries
and persons. This works well if the number of countries and persons
per document is limited.
If you want to support partial updates, you need to split your
document on various keys. For instance:
doc:ID -> hash for title, url and content
doc_countries:ID -> list of references of countries
doc_persons:ID -> list of references of persons
Now you can update each individual field, and maintain the list
of countries and persons associated to a document without having
to manage serialization/deserialization of the whole document.
With both solutions, you can retrieve the data for a given document
in just 2 roundtrips (if you exploit Redis pipelining):
- one to retrieve the document and its data
- one to retrieve the data associated to countries and persons
However, you cannot get the list of documents associated to a
specific country or person. If you want to support such queries,
you need to add extra sets for this. For instance:
country_doc:FR -> set of document IDs associated to France
person_doc:123 -> set of document IDs associated to person 123
Up to you to maintain these extra sets.
So Redis is quite flexible, but you need to anticipate your access
patterns, structure your data accordingly, and manage all indexing
by yourself.
Regards,
Didier.
On May 1, 2:57 pm, Aziz Nait Oumghar <
aziznaitoumg...@gmail.com>
wrote: