Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 120 lines (82 sloc) 3.905 kb
9172c43 @chriso Updated README
authored
1 **redback** - A high-level Redis library for Node.JS. Follow [redbackjs.com](http://redbackjs.com/) and [@chris6F](twitter.com/chris6F) for updates.
a52ec58 @chriso Added a README
authored
2
f00f860 @chriso Updated README
authored
3 npm install -g redback
a52ec58 @chriso Added a README
authored
4
f00f860 @chriso Updated README
authored
5 ## What is it?
a52ec58 @chriso Added a README
authored
6
1960d6c @chriso Updated README
authored
7 Redback provides an accessible and extensible interface to the Redis [data types](http://redis.io/topics/data-types) and allows you to roll your own structures with ease.
8
9 It comes with useful atomic helper methods, such as creating auto-incrementing keys
10
11 Redback comes with the following built-in structures:
a52ec58 @chriso Added a README
authored
12
f00f860 @chriso Updated README
authored
13 - **List**
14 - **Set**
15 - **SortedSet**
16 - **Hash**
17 - **Channel**
18 - **Cache**
1960d6c @chriso Updated README
authored
19
20 It also comes with the following advanced data structures:
21
b4497ab @chriso Updated README
authored
22 - **DensitySet** - A sorted set where scores are based on the density of
23 the element. Adding an element increments its score, and removing decrements it.
24 - **KeyPair** - Uses two hash structures and an auto-incrementing key to assign an ID to unique values
1960d6c @chriso Updated README
authored
25 - **SocialGraph** - Similar to Twitter's (following vs. followers)
26 - **CappedList** - A list with a fixed length
a52ec58 @chriso Added a README
authored
27
f00f860 @chriso Updated README
authored
28 ## Usage
a52ec58 @chriso Added a README
authored
29
30 var redback = require('redback').createClient();
31
f00f860 @chriso Updated README
authored
32 //redback.create<Structure>(key)
a52ec58 @chriso Added a README
authored
33
f00f860 @chriso Updated README
authored
34 var user = redback.createHash('user1');
35 user.set({username:'chris', password:'redisisawesome'}, callback);
a52ec58 @chriso Added a README
authored
36
f00f860 @chriso Updated README
authored
37 var log = redback.createCappedList('log', 1000);
38 log.push('Log message ...');
a52ec58 @chriso Added a README
authored
39
f00f860 @chriso Updated README
authored
40 ## Creating your own structures
a52ec58 @chriso Added a README
authored
41
42 To create your own structure, use `addStructure(name, methods)`.
43 Structures have access to a Redis key `this.key` and the Redis client
44 `this.client`. If an `init()` method is defined, then it is called after
45 the structure is instantiated - `init()` receives an extra parameters
46 when calling `create<structure>()`
47
48 Let's create a queue that can be either FIFO or LIFO
49
50 redback.addStructure('Queue', {
51 init: function (is_fifo) {
52 this.fifo = is_fifo;
53 },
54 add: function (value, callback) {
55 this.client.lpush(this.key, value, callback);
56 },
57 next: function (callback) {
58 var method = this.fifo ? 'lpop' : 'rpop';
59 this.client[method](this.key, callback);
60 }
61 });
62
63 To use the queue, call `createQueue(key, is_fifo)`
64
65 var queue = redback.createQueue('my_queue', true);
66
67 queue.add('awesome!', callback);
68
f00f860 @chriso Updated README
authored
69 ## Other uses
a52ec58 @chriso Added a README
authored
70
71 You can also use Redis as a cache backend or as a pub/sub provider
72
73 **Cache backend**
74
75 var cache = redback.createCache();
76 cache.set('foo', 'bar', callback);
77
78 **Pub/sub provider**
79
80 var channel = redback.createChannel('chat');
81
82 channel.subscribe();
83
84 //To received messages
85 channel.on('message', function (msg) {
86 console.log(msg);
87 });
88
89 //To send messages
90 channel.publish(msg);
91
b4497ab @chriso Updated README
authored
92 ## Want to learn more?
93
94 For now, see the [annotated source](http://redbackjs.com/api.html) for more information.
a52ec58 @chriso Added a README
authored
95
f00f860 @chriso Updated README
authored
96 ## License
a52ec58 @chriso Added a README
authored
97
98 (MIT License)
99
100 Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
101
102 Permission is hereby granted, free of charge, to any person obtaining
103 a copy of this software and associated documentation files (the
104 "Software"), to deal in the Software without restriction, including
105 without limitation the rights to use, copy, modify, merge, publish,
106 distribute, sublicense, and/or sell copies of the Software, and to
107 permit persons to whom the Software is furnished to do so, subject to
108 the following conditions:
109
110 The above copyright notice and this permission notice shall be
111 included in all copies or substantial portions of the Software.
112
113 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
114 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
115 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
116 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
117 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
118 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
119 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.