Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 150 lines (109 sloc) 5.171 kb
46fb719 @sintaxi adds README.md
authored
1 # redis-tag
2
3 Tagging is the perfect job for redis wouldn't you agree? This library makes it
4 easy to implement a tagging system into any node appication. It has only 4
5 public methods and sets up all the associations for you.
6
7 ## Instalation
8
9 I always recomend you bundle your dependencies with your application. To do
10 this, create a `package.json` file in the root of your project with the minimum
11 information...
12
13 {
14 "name": "yourapplication",
15 "verson": "0.0.1",
16 "dependencies": {
f3eef6e @sintaxi version bump v0.2.0
authored
17 "redis-tag": "0.2.0"
46fb719 @sintaxi adds README.md
authored
18 }
19 }
20
21 Then run the following command using npm...
22
23 npm install
24
25 OR, if you just want to start playing with the library run...
26
27 npm install redis-tag
28
1618189 @sintaxi adds license to README.md
authored
29 ## Docs
46fb719 @sintaxi adds README.md
authored
30
31 To create a taggable object we must first require the library and then
32 instantiate a new Taggable object. A taggable object can be any model in your
33 system. For example: book, post, person, etc.
34
35 var redisTag = require("redis-tag")
36 var bookTagger = new redisTag.Taggable("book")
37
38 Now we have 4 methods on the `bookTagger` object that give us tagging abilities.
39
900f8f5 @sintaxi updates README.md
authored
40 ### set([scope,] id, tags, callback)
46fb719 @sintaxi adds README.md
authored
41
42 The `set` method applies tags to an `id` (which is your first argument). The id
43 should correspond with the resource you are tagging. The id does not have to be
44 an integer but this will usually be the case. `tags` must come in the form of
45 an array (it is up to your application how this array is formed. redis-tag does
900f8f5 @sintaxi updates README.md
authored
46 not do this for you). The last argument is a callback with an argument that is
47 the response of the `set` call. It will return `true` or `false`. `scope` is an
48 optional argument for if you want to do something like delicious where eash
49 user has their own set of tags. If a `scope` is used when tagging. you still
50 have avaiable to you all the other methods in a non-scoped or scoped manner.
46fb719 @sintaxi adds README.md
authored
51
52 // sets tags on book 12
53 bookTagger.set(12, ["fiction", "fantasy"], function(response){
54 console.log(response) //=> true
55 })
56
900f8f5 @sintaxi updates README.md
authored
57 #### OR (with scope)
58
59 // sets tags on book 12 for user 42
60 bookTagger.set("user:42", 12, ["fiction", "fantasy"], function(response){
61 console.log(response) //=> true
62 })
63
64 ### get([scope,] id, callback)
46fb719 @sintaxi adds README.md
authored
65
66 The `get` method simply takes an `id` and a callback with a list of tags as the
67 response. This will always be in the form of an array.
68
69 // gets tags for book 12
70 bookTagger.get(12, function(tags){
71 console.log(tags) //=> ["fiction", "fantasy"]
72 })
73
900f8f5 @sintaxi updates README.md
authored
74 #### OR (with scope)
75
76 Please note that this is only effective if you have used a scope on the `set`
77 method.
78
79 // gets tags for book 12
80 bookTagger.get("user:42", 12, function(tags){
81 console.log(tags) //=> ["fiction", "fantasy"]
82 })
83
46fb719 @sintaxi adds README.md
authored
84 ### find(tags, callback)
85
86 The `find` method will take an array of tags and find all the resources that
87 have those tags in common. The callback function taken as the second argument
88 will return with an array of ids.
89
90 // finds resources that have been tagged "fiction"
91 bookTagger.find(["fiction"], function(ids){
92 console.log(ids) //=> ["12", "27", "42", "18"]
93 })
94
900f8f5 @sintaxi updates README.md
authored
95 #### OR (with scope)
96
97 Please note that this is only effective if you have used a scope on the `set`
98 method.
99
100 // finds resources that have been tagged "fiction"
101 bookTagger.find("user:42", ["fiction"], function(ids){
102 console.log(ids) //=> ["12", "27", "42", "18"]
103 })
104
46fb719 @sintaxi adds README.md
authored
105 ### popular(count, callback)
106
107 The `popular` will retrieve all the tags on that resource and order them from
108 most to least most popular. It accepts an `integer` as its first argument
109 describing the number of tags you want returned. The `callback` is called with
110 a `nested array` listing the tags in decending order.
111
112 bookTagger.popular(25, function(tags){
900f8f5 @sintaxi updates README.md
authored
113 console.log(tags) //=> [ ["fiction", 892], ["non-fiction", 423], ["fantasy", 315], ... ]
114 })
115
116 #### OR (with scope)
117
118 Please note that this is only effective if you have used a scope on the `set`
119 method.
120
121 bookTagger.popular("user:42", 25, function(tags){
46fb719 @sintaxi adds README.md
authored
122 console.log(tags) //=> [ ["fiction", 27], ["non-fiction", 23], ["fantasy", 15], ... ]
123 })
124
1618189 @sintaxi adds license to README.md
authored
125 ## License
126
127 Copyright 2011 Brock Whitten
128 All rights reserved.
129
130 Permission is hereby granted, free of charge, to any person
131 obtaining a copy of this software and associated documentation
132 files (the "Software"), to deal in the Software without
133 restriction, including without limitation the rights to use,
134 copy, modify, merge, publish, distribute, sublicense, and/or sell
135 copies of the Software, and to permit persons to whom the
136 Software is furnished to do so, subject to the following
137 conditions:
138
139 The above copyright notice and this permission notice shall be
140 included in all copies or substantial portions of the Software.
141
142 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
143 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
144 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
145 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
146 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
147 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
148 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
149 OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.