Skip to content
Browse files

Fixed README examples

  • Loading branch information...
1 parent 447efd5 commit 667bca1475327ca46becd5c3cc86169463e09436 @chriso committed
Showing with 40 additions and 42 deletions.
  1. +40 −42 README.md
View
82 README.md
@@ -6,14 +6,10 @@ Follow [redbackjs.com](http://redbackjs.com/) and [@chris6F](twitter.com/chris6F
## What is it?
-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. Redback comes with the following built-in structures:
-
-- **List**
-- **Set**
-- **SortedSet**
-- **Hash**
-- **Channel**
-- **Cache**
+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. Redback comes with the following built-in
+structures: **List**, **Set**, **SortedSet**, **Hash**, **Channel**, **Cache**
It also comes with the following advanced data structures:
@@ -22,21 +18,23 @@ It also comes with the following advanced data structures:
- **SocialGraph** - Similar to Twitter's (following vs. followers)
- **CappedList** - A list with a fixed length
+*More coming soon!*
+
## Usage
```javascript
- var redback = require('redback').createClient();
+var redback = require('redback').createClient();
- //redback.create<Structure>(key)
+//redback.create<Structure>(key)
- var user1 = redback.createHash('user1');
- user.set({username:'chris', password:'redisisawesome'}, callback);
+var user1 = redback.createHash('user1');
+user.set({username:'chris', password:'redisisawesome'}, callback);
- var log = redback.createCappedList('log', 1000);
- log.push('Log message ...');
+var log = redback.createCappedList('log', 1000);
+log.push('Log message ...');
- var user3 = redback.createSocialGraph(3);
- user3.follow(1, callback);
+var user3 = redback.createSocialGraph(3);
+user3.follow(1, callback);
```
## Creating your own structures
@@ -46,25 +44,25 @@ To create your own structure, use `addStructure(name, methods)`.
Let's create a queue that can be either FIFO or LIFO
```javascript
- redback.addStructure('Queue', {
- init: function (is_fifo) {
- this.fifo = is_fifo;
- },
- add: function (value, callback) {
- this.client.lpush(this.key, value, callback);
- },
- next: function (callback) {
- var method = this.fifo ? 'lpop' : 'rpop';
- this.client[method](this.key, callback);
- }
- });
+redback.addStructure('Queue', {
+ init: function (is_fifo) {
+ this.fifo = is_fifo;
+ },
+ add: function (value, callback) {
+ this.client.lpush(this.key, value, callback);
+ },
+ next: function (callback) {
+ var method = this.fifo ? 'lpop' : 'rpop';
+ this.client[method](this.key, callback);
+ }
+});
```
To use the queue, call `createQueue(key, is_fifo)`
```javascript
- var queue = redback.createQueue('my_queue', true);
- queue.add('awesome!', callback);
+var queue = redback.createQueue('my_queue', true);
+queue.add('awesome!', callback);
```
Structures have access to a Redis key `this.key` and the Redis client
@@ -77,25 +75,25 @@ from `create<structure>()`.
**Cache backend**
```javascript
- var cache = redback.createCache(namespace);
- cache.set('foo', 'bar', callback);
- cache.get('foo', function (err, foo) {
- console.log(foo); //bar
- });
+var cache = redback.createCache(namespace);
+cache.set('foo', 'bar', callback);
+cache.get('foo', function (err, foo) {
+ console.log(foo); //bar
+});
```
**Pub/sub provider**
```javascript
- var channel = redback.createChannel('chat').subscribe();
+var channel = redback.createChannel('chat').subscribe();
- //To received messages
- channel.on('message', function (msg) {
- console.log(msg);
- });
+//To received messages
+channel.on('message', function (msg) {
+ console.log(msg);
+});
- //To send messages
- channel.publish(msg);
+//To send messages
+channel.publish(msg);
```
## Want to learn more?

0 comments on commit 667bca1

Please sign in to comment.
Something went wrong with that request. Please try again.