Skip to content

HTTPS clone URL

Subversion checkout URL

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