Planning the tags data structure

You may be farmiliar with the traditional many-to-many relationship in SQL. But here what we have is just a key-value pair structure. Many-to-many relationship are done with set intersection.

Here is our data structure planning:

1'books' = [array of book objects];
2'tags' = [array of tag names];
3'tag:<tag_name>' = [array of book ISBNs];
4'tag:<tag_name2>' = [array of book ISBNs];
5'tag:<tag_name3>' = [array of book ISBNs];

By using this structure, we can get the book list and all tags list directly.

And we can list all books of a given tag with the key in tag:<tag_name> pattern.

Intersection

If we want to list book in multi tags, we can interset the ISBNs arrays for the result.

Redis’ tutorials have more examples on how to use key-value pair structure.

Redis is a server side key-value database.

What’s next? We’re going to take a look at “Introducing Lo-Dash”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content