Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 144 lines (104 sloc) 4.748 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();
d28bebb Edited README.md via GitHub
Chase Colman authored
31
3ad000e @chriso Fixed up README
authored
32 // or
d28bebb Edited README.md via GitHub
Chase Colman authored
33
6f62b2f @chase Allow Redback to take an existing Redis client or create a new client.
chase authored
34 var redis = require('redis').createClient();
3ad000e @chriso Fixed up README
authored
35 var redback = require('redback').use(redis);
36 ```
37
38 ```javascript
f8d51b8 @chriso Full-text search, oh my
authored
39 var user3 = redback.createSocialGraph(3);
40 user3.follow(1, callback);
41
42 var text = redback.createFullText('my_index');
aace1a5 @chriso Fixed README
authored
43 text.indexFile({1: 'file1.txt', 2: 'file2.txt'}, callback);
f8d51b8 @chriso Full-text search, oh my
authored
44 text.search('foo bar -exclude -these -words', callback);
a52ec58 @chriso Added a README
authored
45
667bca1 @chriso Fixed README examples
authored
46 var user1 = redback.createHash('user1');
47 user.set({username:'chris', password:'redisisawesome'}, callback);
a52ec58 @chriso Added a README
authored
48
667bca1 @chriso Fixed README examples
authored
49 var log = redback.createCappedList('log', 1000);
50 log.push('Log message ...');
447efd5 @chriso Added syntax highlighting + credits to the README
authored
51 ```
5de121c @chriso Updated README
authored
52
f00f860 @chriso Updated README
authored
53 ## Creating your own structures
a52ec58 @chriso Added a README
authored
54
55 To create your own structure, use `addStructure(name, methods)`.
f0fcc68 @chriso Updated README
authored
56
a52ec58 @chriso Added a README
authored
57 Let's create a queue that can be either FIFO or LIFO
58
447efd5 @chriso Added syntax highlighting + credits to the README
authored
59 ```javascript
4dd4341 @chriso Added Queue as a builtin
authored
60 redback.addStructure('SimpleQueue', {
667bca1 @chriso Fixed README examples
authored
61 init: function (is_fifo) {
62 this.fifo = is_fifo;
63 },
64 add: function (value, callback) {
65 this.client.lpush(this.key, value, callback);
66 },
67 next: function (callback) {
1607c69 @chriso Argh minor error
authored
68 var method = this.fifo ? 'rpop' : 'lpop';
667bca1 @chriso Fixed README examples
authored
69 this.client[method](this.key, callback);
70 }
71 });
447efd5 @chriso Added syntax highlighting + credits to the README
authored
72 ```
a52ec58 @chriso Added a README
authored
73
4dd4341 @chriso Added Queue as a builtin
authored
74 To use the queue, call `createSimpleQueue(key, is_fifo)`
a52ec58 @chriso Added a README
authored
75
447efd5 @chriso Added syntax highlighting + credits to the README
authored
76 ```javascript
4dd4341 @chriso Added Queue as a builtin
authored
77 var queue = redback.createSimpleQueue('my_queue', true);
78 queue.add('awesome!');
447efd5 @chriso Added syntax highlighting + credits to the README
authored
79 ```
a52ec58 @chriso Added a README
authored
80
f0fcc68 @chriso Updated README
authored
81 Structures have access to a Redis key `this.key` and the Redis client
5da91b7 @chriso Updated README
authored
82 `this.client`. If an `init()` method is defined then it is called after
f0fcc68 @chriso Updated README
authored
83 the structure is instantiated. Also note that `init()` receives any extra parameters
5da91b7 @chriso Updated README
authored
84 from `create<structure>()`.
f0fcc68 @chriso Updated README
authored
85
f00f860 @chriso Updated README
authored
86 ## Other uses
a52ec58 @chriso Added a README
authored
87
88 **Cache backend**
89
447efd5 @chriso Added syntax highlighting + credits to the README
authored
90 ```javascript
667bca1 @chriso Fixed README examples
authored
91 var cache = redback.createCache(namespace);
92 cache.set('foo', 'bar', callback);
93 cache.get('foo', function (err, foo) {
94 console.log(foo); //bar
95 });
447efd5 @chriso Added syntax highlighting + credits to the README
authored
96 ```
a52ec58 @chriso Added a README
authored
97
98 **Pub/sub provider**
99
447efd5 @chriso Added syntax highlighting + credits to the README
authored
100 ```javascript
667bca1 @chriso Fixed README examples
authored
101 var channel = redback.createChannel('chat').subscribe();
a52ec58 @chriso Added a README
authored
102
667bca1 @chriso Fixed README examples
authored
103 //To received messages
104 channel.on('message', function (msg) {
105 console.log(msg);
106 });
a52ec58 @chriso Added a README
authored
107
667bca1 @chriso Fixed README examples
authored
108 //To send messages
109 channel.publish(msg);
447efd5 @chriso Added syntax highlighting + credits to the README
authored
110 ```
a52ec58 @chriso Added a README
authored
111
b4497ab @chriso Updated README
authored
112 ## Want to learn more?
113
114 For now, see the [annotated source](http://redbackjs.com/api.html) for more information.
a52ec58 @chriso Added a README
authored
115
447efd5 @chriso Added syntax highlighting + credits to the README
authored
116 ## Credits
117
118 - Matt Ranney for his awesome [node_redis](https://github.com/mranney/node_redis) library.
119
f00f860 @chriso Updated README
authored
120 ## License
a52ec58 @chriso Added a README
authored
121
122 (MIT License)
123
124 Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
125
126 Permission is hereby granted, free of charge, to any person obtaining
127 a copy of this software and associated documentation files (the
128 "Software"), to deal in the Software without restriction, including
129 without limitation the rights to use, copy, modify, merge, publish,
130 distribute, sublicense, and/or sell copies of the Software, and to
131 permit persons to whom the Software is furnished to do so, subject to
132 the following conditions:
133
134 The above copyright notice and this permission notice shall be
135 included in all copies or substantial portions of the Software.
136
137 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
138 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
139 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
140 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
141 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
142 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
143 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.