Databases Reference
In-Depth Information
Next, add a bunch of tags to the member you added to the set named books . Here is how you do it:
$ ./redis-cli sadd books:1:tags 1
(integer) 1
$ ./redis-cli sadd books:1:tags 2
(integer) 1
$ ./redis-cli sadd books:1:tags 3
(integer) 1
$ ./redis-cli sadd books:1:tags 4
(integer) 1
$ ./redis-cli sadd books:1:tags 5
(integer) 1
$ ./redis-cli sadd books:1:tags 6
(integer) 1
Available for
download on
Wrox.com
books_and_tags.txt
A bunch of numeric tag identifi ers have been added to the member identifi ed by the id value of
1. The tags themselves have not been defi ned any more than having been assigned an id so far. It
may be worthwhile to break down the constituents of books:1:tags a bit further and explain
how the key naming systems work in Redis. Any string, except those containing whitespace and
special characters, are good choices for a key in Redis. Avoid very long or short keys. Keys can be
structured in a manner where a hierarchical relationship can be established and nesting of objects
and their properties can be established. It is a suggested practice and convention to use a scheme
like object-type:id:field for key names. Therefore, a key such as books:1:tags implies a tag
collection for a member identifi ed by the id 1 within a set named “books.” Similarly, books:1:
title means title fi eld of a member, identifi ed by an id value of 1, within the set of books.
After adding a bunch of tags to the fi rst member of the set of books, you can defi ne the tags
themselves like so:
$ ./redis-cli sadd tag:1:name “organic”
(integer) 1
$ ./redis-cli sadd tag:2:name “industrialization”
(integer) 1
$ ./redis-cli sadd tag:3:name “local”
(integer) 1
$ ./redis-cli sadd tag:4:name “written by a journalist”
(integer) 1
$ ./redis-cli sadd tag:5:name “best seller”
(integer) 1
$ ./redis-cli sadd tag:6:name “insight”
(integer) 1
Available for
download on
Wrox.com
books_and_tags.txt
With tags defi ned, you establish the reciprocal relationship to associate books that have the particular
tags. The fi rst member has all six tags so you add it to each of the tags as follows:
Search WWH ::




Custom Search