Databases Reference
In-Depth Information
Querying Redis
Continuing with the redis-cli session, you can fi rst list the title and author of member 1,
identifi ed by the id 1, of the set of books as follows:
$ ./redis-cli smembers books:1:title
1. “The Omnivore\xe2\x80\x99s Dilemma”
$ ./redis-cli smembers books:1:author
1. “Michael Pollan”
Available for
download on
Wrox.com
books_and_tags.txt
The special characters in the title string represent the apostrophe that was introduced in the
string value.
You can list all the tags for this topic like so:
$ ./redis-cli smembers books:1:tags
1. “4”
2. “1”
3. “2”
4. “3”
5. “5”
6. “6”
Available for
download on
Wrox.com
books_and_tags.txt
Notice that the list of tag ids is not ordered in the same way as they were entered. This is because
sets have no sense of order within their members. If you need an ordered set, use a sorted set instead
of a set.
Similarly, you can list title, author, and tags of the second book, identifi ed by the id 2, like so:
$ ./redis-cli smembers books:2:title
1. “Outliers”
$ ./redis-cli smembers books:2:author
1. “Malcolm Gladwell”
$ ./redis-cli smembers books:2:tags
1. “4”
2. “5”
3. “6”
Available for
download on
Wrox.com
books_and_tags.txt
Now, viewing the set from the tags standpoint you can list all books that have the tag, identifi ed by
id 1 as follows:
$ ./redis-cli smembers tag:1:books
“1”
Search WWH ::




Custom Search