Databases Reference
In-Depth Information
Tag 1 was identifi ed by the name organic and you can query that like so:
$ ./redis-cli smembers tag:1:name
“organic”
Some tags like tag 6, identifi ed by the name insight , have been attached to both the topics in the
set. You can confi rm that by querying the set of books that have tag 6 like so:
$ ./redis-cli smembers tag:6:books
1. “1”
2. “2”
Next, you can list the topics that have both tags 1 and 6, like so:
$ ./redis-cli sinter tag:1:books tag:6:books
“1”
The sinter command allows you to query for the intersection of two or more sets. If the word
“intersection” has befuddled you, then review the Venn diagram in Figure 3-2 to set things back
to normal.
A
Intersection
B
1
3
2
4
5
6
7
8
5 and 6 belong to both sets A and B
FIGURE 3-2
You know both books 1 and 2 have tags 5 and 6, so a sinter between the topics of tags 5 and
6 should list both books. You can run the sinter command to confi rm this. The command and
output are as follows:
$ ./redis-cli sinter tag:5:books tag:6:books
1. “1”
2. “2”
Like set intersection, you can also query for set union and difference. Figures 3-3 and 3-4
demonstrate what set union and difference imply.
Search WWH ::




Custom Search