Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 137 lines (99 sloc) 4.632 kb
d0ccae7 @chriso Updated README
authored
1 **redback** - A high-level Redis library for Node.JS.
2
3 Follow [redbackjs.com](http://redbackjs.com/) and [@chris6F](twitter.com/chris6F) for updates.
a52ec58 @chriso Added a README
authored
4
f00f860 @chriso Updated README
authored
5 npm install -g redback
a52ec58 @chriso Added a README
authored
6
f00f860 @chriso Updated README
authored
7 ## What is it?
a52ec58 @chriso Added a README
authored
8
667bca1 @chriso Fixed README examples
authored
9 Redback provides an accessible and extensible interface to the Redis
10 [data types](http://redis.io/topics/data-types) and allows you to roll
11 your own structures with ease. Redback comes with the following built-in
12 structures: **List**, **Set**, **SortedSet**, **Hash**, **Channel**, **Cache**
1960d6c @chriso Updated README
authored
13
5da91b7 @chriso Updated README
authored
14 It also comes with the following advanced data structures:
1960d6c @chriso Updated README
authored
15
f0fcc68 @chriso Updated README
authored
16 - **DensitySet** - A sorted set where adding an element increments its score and removing it decrements it.
5de121c @chriso Updated README
authored
17 - **KeyPair** - Uses two hash structures and an auto-incrementing key to assign an ID to each unique value
1960d6c @chriso Updated README
authored
18 - **SocialGraph** - Similar to Twitter's (following vs. followers)
19 - **CappedList** - A list with a fixed length
f8d51b8 @chriso Full-text search, oh my
authored
20 - **FullText** - A full text index with support for stop words, stemming and basic boolean search
4dd4341 @chriso Added Queue as a builtin
authored
21 - **Queue** - A simple FIFO or LIFO queue
df4dac5 @chriso Added a link to the Rate limiting blog post
authored
22 - **RateLimit** - Count the number of times an event occurs over an interval. Can be used for IP rate limiting. See [this blog post](http://chris6f.com/rate-limiting-with-redis)
2fc2114 @chriso Added sreeix as a contributor
authored
23 - **BloomFilter** - A probabilistic structure used to test whether an an element exists in a set. Contributed by user [sreeix](https://github.com/sreeix)
1253c59 @chriso Updated README
authored
24
25 *Have an idea for an advanced structure? Send a pull request and I'll add you as a contributor.*
667bca1 @chriso Fixed README examples
authored
26
f00f860 @chriso Updated README
authored
27 ## Usage
a52ec58 @chriso Added a README
authored
28
447efd5 @chriso Added syntax highlighting + credits to the README
authored
29 ```javascript
667bca1 @chriso Fixed README examples
authored
30 var redback = require('redback').createClient();
a52ec58 @chriso Added a README
authored
31
f8d51b8 @chriso Full-text search, oh my
authored
32 var user3 = redback.createSocialGraph(3);
33 user3.follow(1, callback);
34
35 var text = redback.createFullText('my_index');
aace1a5 @chriso Fixed README
authored
36 text.indexFile({1: 'file1.txt', 2: 'file2.txt'}, callback);
f8d51b8 @chriso Full-text search, oh my
authored
37 text.search('foo bar -exclude -these -words', callback);
a52ec58 @chriso Added a README
authored
38
667bca1 @chriso Fixed README examples
authored
39 var user1 = redback.createHash('user1');
40 user.set({username:'chris', password:'redisisawesome'}, callback);
a52ec58 @chriso Added a README
authored
41
667bca1 @chriso Fixed README examples
authored
42 var log = redback.createCappedList('log', 1000);
43 log.push('Log message ...');
447efd5 @chriso Added syntax highlighting + credits to the README
authored
44 ```
5de121c @chriso Updated README
authored
45
f00f860 @chriso Updated README
authored
46 ## Creating your own structures
a52ec58 @chriso Added a README
authored
47
48 To create your own structure, use `addStructure(name, methods)`.
f0fcc68 @chriso Updated README
authored
49
a52ec58 @chriso Added a README
authored
50 Let's create a queue that can be either FIFO or LIFO
51
447efd5 @chriso Added syntax highlighting + credits to the README
authored
52 ```javascript
4dd4341 @chriso Added Queue as a builtin
authored
53 redback.addStructure('SimpleQueue', {
667bca1 @chriso Fixed README examples
authored
54 init: function (is_fifo) {
55 this.fifo = is_fifo;
56 },
57 add: function (value, callback) {
58 this.client.lpush(this.key, value, callback);
59 },
60 next: function (callback) {
1607c69 @chriso Argh minor error
authored
61 var method = this.fifo ? 'rpop' : 'lpop';
667bca1 @chriso Fixed README examples
authored
62 this.client[method](this.key, callback);
63 }
64 });
447efd5 @chriso Added syntax highlighting + credits to the README
authored
65 ```
a52ec58 @chriso Added a README
authored
66
4dd4341 @chriso Added Queue as a builtin
authored
67 To use the queue, call `createSimpleQueue(key, is_fifo)`
a52ec58 @chriso Added a README
authored
68
447efd5 @chriso Added syntax highlighting + credits to the README
authored
69 ```javascript
4dd4341 @chriso Added Queue as a builtin
authored
70 var queue = redback.createSimpleQueue('my_queue', true);
71 queue.add('awesome!');
447efd5 @chriso Added syntax highlighting + credits to the README
authored
72 ```
a52ec58 @chriso Added a README
authored
73
f0fcc68 @chriso Updated README
authored
74 Structures have access to a Redis key `this.key` and the Redis client
5da91b7 @chriso Updated README
authored
75 `this.client`. If an `init()` method is defined then it is called after
f0fcc68 @chriso Updated README
authored
76 the structure is instantiated. Also note that `init()` receives any extra parameters
5da91b7 @chriso Updated README
authored
77 from `create<structure>()`.
f0fcc68 @chriso Updated README
authored
78
f00f860 @chriso Updated README
authored
79 ## Other uses
a52ec58 @chriso Added a README
authored
80
81 **Cache backend**
82
447efd5 @chriso Added syntax highlighting + credits to the README
authored
83 ```javascript
667bca1 @chriso Fixed README examples
authored
84 var cache = redback.createCache(namespace);
85 cache.set('foo', 'bar', callback);
86 cache.get('foo', function (err, foo) {
87 console.log(foo); //bar
88 });
447efd5 @chriso Added syntax highlighting + credits to the README
authored
89 ```
a52ec58 @chriso Added a README
authored
90
91 **Pub/sub provider**
92
447efd5 @chriso Added syntax highlighting + credits to the README
authored
93 ```javascript
667bca1 @chriso Fixed README examples
authored
94 var channel = redback.createChannel('chat').subscribe();
a52ec58 @chriso Added a README
authored
95
667bca1 @chriso Fixed README examples
authored
96 //To received messages
97 channel.on('message', function (msg) {
98 console.log(msg);
99 });
a52ec58 @chriso Added a README
authored
100
667bca1 @chriso Fixed README examples
authored
101 //To send messages
102 channel.publish(msg);
447efd5 @chriso Added syntax highlighting + credits to the README
authored
103 ```
a52ec58 @chriso Added a README
authored
104
b4497ab @chriso Updated README
authored
105 ## Want to learn more?
106
107 For now, see the [annotated source](http://redbackjs.com/api.html) for more information.
a52ec58 @chriso Added a README
authored
108
447efd5 @chriso Added syntax highlighting + credits to the README
authored
109 ## Credits
110
111 - Matt Ranney for his awesome [node_redis](https://github.com/mranney/node_redis) library.
112
f00f860 @chriso Updated README
authored
113 ## License
a52ec58 @chriso Added a README
authored
114
115 (MIT License)
116
117 Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
118
119 Permission is hereby granted, free of charge, to any person obtaining
120 a copy of this software and associated documentation files (the
121 "Software"), to deal in the Software without restriction, including
122 without limitation the rights to use, copy, modify, merge, publish,
123 distribute, sublicense, and/or sell copies of the Software, and to
124 permit persons to whom the Software is furnished to do so, subject to
125 the following conditions:
126
127 The above copyright notice and this permission notice shall be
128 included in all copies or substantial portions of the Software.
129
130 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
131 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
132 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
133 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
134 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
135 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
136 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.