Full Code of chriso/redback for AI

master 1529cbf2bfa3 cached
44 files
375.5 KB
103.0k tokens
1 requests
Download .txt
Showing preview only (392K chars total). Download the full file or copy to clipboard to get everything.
Repository: chriso/redback
Branch: master
Commit: 1529cbf2bfa3
Files: 44
Total size: 375.5 KB

Directory structure:
gitextract_q167ekye/

├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── docs/
│   ├── api.html
│   └── index.html
├── index.js
├── lib/
│   ├── Cache.js
│   ├── Channel.js
│   ├── Redback.js
│   ├── Structure.js
│   ├── Utils.js
│   ├── advanced_structures/
│   │   ├── BloomFilter.js
│   │   ├── CappedList.js
│   │   ├── DensitySet.js
│   │   ├── KeyPair.js
│   │   ├── Lock.js
│   │   ├── Queue.js
│   │   ├── RateLimit.js
│   │   └── SocialGraph.js
│   └── base_structures/
│       ├── Bitfield.js
│       ├── Hash.js
│       ├── List.js
│       ├── Set.js
│       └── SortedSet.js
├── package.json
└── test/
    ├── bitfield.test.js
    ├── bloomfilter.test.js
    ├── cache.test.js
    ├── cappedlist.test.js
    ├── channel.test.js
    ├── common.js
    ├── crc32.test.js
    ├── densityset.test.js
    ├── hash.test.js
    ├── keypair.test.js
    ├── list.test.js
    ├── lock.test.js
    ├── namespace.test.js
    ├── queue.test.js
    ├── set.test.js
    ├── socialgraph.test.js
    ├── sortedset.test.js
    └── structure.test.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules
npm-debug.log


================================================
FILE: .travis.yml
================================================
sudo: false

language: node_js

node_js:
  - stable

services:
  - redis-server

after_script:
  - npm test


================================================
FILE: LICENSE
================================================
Copyright (c) 2016 Chris O'Hara <cohara87@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: README.md
================================================
# Redback

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Downloads][downloads-image]][npm-url]

A high-level Redis library.

```sh
$ npm install redback
```

## Introduction

Redback provides an accessible and extensible interface to the Redis
[data types](http://redis.io/topics/data-types) and allows you to create
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:

- **DensitySet** - A sorted set where adding an element increments its score and removing it decrements it
- **KeyPair** - Uses two hash structures and an auto-incrementing key to assign an ID to each unique value
- **SocialGraph** - Similar to Twitter's (following vs. followers)
- **CappedList** - A list with a fixed length
- **Queue** - A simple FIFO or LIFO queue
- **RateLimit** - Count the number of times an event occurs over an interval. See [this introduction](https://gist.github.com/chriso/54dd46b03155fcf555adccea822193da).
- **BloomFilter** - A probabilistic structure used to test whether an an element exists in a set

## Usage

```javascript
var redback = require('redback').createClient();

// or

var redis = require('redis').createClient();
var redback = require('redback').use(redis);
```

```javascript
var user3 = redback.createSocialGraph(3);
user3.follow(1, callback);

var log = redback.createCappedList('log', 1000);
log.push('Log message ...');

var user = redback.createHash('user1');
user.set({username: 'chris', password: 'foobar'}, callback);
```

## Creating your own structures

Use `addStructure(name, methods)` to create your own structure.

Let's create a queue that can be either FIFO or LIFO:

```javascript
redback.addStructure('SimpleQueue', {
    init: function (options) {
        options = options || {};
        this.fifo = options.fifo;
    },
    add: function (value, callback) {
        this.client.lpush(this.key, value, callback);
    },
    next: function (callback) {
        var method = this.fifo ? 'rpop' : 'lpop';
        this.client[method](this.key, callback);
    }
});
```

Call `createSimpleQueue(key, options)` to use the queue:

```javascript
var queue = redback.createSimpleQueue('my_queue', {fifo: true});
queue.add('awesome!');
```

Structures have access to a Redis key `this.key` and the Redis client
`this.client`. If an `init()` method is defined then it is called after
the structure is instantiated. Also note that `init()` receives any extra parameters
from `create<structure>()`.

## Other uses

**Cache backend**

```javascript
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();

//To received messages
channel.on('message', function (msg) {
   console.log(msg);
});

//To send messages
channel.publish(msg);
```

## Documentation

See the [annotated source](http://chriso.github.io/redback/api.html).

## Tests

The tests require a local redis instance running on `localhost:6379`. Note that
redis database #11 will be flushed prior to each run.

```sh
$ npm test
```

## Credits

- Matt Ranney for his [node_redis](https://github.com/mranney/node_redis) library.
- GitHub user [sreeix](https://github.com/sreeix) for the bloom filter implementation.

## License

MIT


[downloads-image]: http://img.shields.io/npm/dm/redback.svg
[npm-url]: https://npmjs.org/package/redback
[npm-image]: http://img.shields.io/npm/v/redback.svg
[travis-url]: https://travis-ci.org/chriso/redback
[travis-image]: http://img.shields.io/travis/chriso/redback.svg


================================================
FILE: docs/api.html
================================================
<a href="https://github.com/chriso/redback"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
	<head>
		<title>Redback</title>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
		<style>body {
    margin: 0;
    padding: 0;
    font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
    color: #252519;
}
a {
    color: #252519;
}
a:hover {
    text-decoration: underline;
    color: #19469D;
}
p {
    margin: 12px 0;
}
h1, h2, h3 {
    margin: 0;
    padding: 0;
}
table#source {
    width: 100%;
    border-collapse: collapse;
}
table#source td:first-child {
    padding: 30px 40px 30px 40px;
    vertical-align: top;
}
table#source td:first-child,
table#source td:first-child pre {
    width: 450px;
}
table#source td:last-child {
    padding: 30px 0 30px 40px;
    border-left: 1px solid #E5E5EE;
    background: #F5F5FF;
}
table#source tr {
    border-bottom: 1px solid #E5E5EE;
}
table#source tr.filename {
    padding-top: 40px;
    border-top: 1px solid #E5E5EE;
}
table#source tr.filename td:first-child {
    text-transform: capitalize;
}
table#source tr.filename td:last-child {
    font-size: 12px;
}
table#source tr.filename h2 {
    margin: 0;
    padding: 0;
    cursor: pointer;
}
table#source tr.code h1,
table#source tr.code h2,
table#source tr.code h3 {
    margin-top: 30px;
    font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
    font-size: 18px;
}
table#source tr.code h2 {
    font-size: 16px;
}
table#source tr.code h3 {
    font-size: 14px;
}
table#source tr.code ul {
    margin: 15px 0 15px 35px;
    padding: 0;
}
table#source tr.code ul li {
    margin: 0;
    padding: 1px 0;
}
table#source tr.code ul li p {
    margin: 0;
    padding: 0;
}
table#source tr.code td:first-child pre {
    padding: 20px;
}
#ribbon {
    position: fixed;
    top: 0;
    right: 0;
}
code .string { color: #219161; }
code .regexp { color: #219161; }
code .keyword { color: #954121; }
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
		<script>
			$(function(){
				$('tr.code').hide();
				$('tr.filename').toggle(function(){
					$(this).nextUntil('.filename').fadeIn();
				}, function(){
					$(this).nextUntil('.filename').fadeOut();
				});
			});
		</script>
	</head>
	<body>
<table id="source"><tbody><tr><td><h1>Redback</h1><p>A high-level Redis library</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/advanced_structures/BloomFilter.js"><a href="#">BloomFilter</a></h2></td><td>lib/advanced_structures/BloomFilter.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>),
    <span class="variable">crc32</span> = <span class="variable">require</span>(<span class="string">'../Utils'</span>).<span class="variable">crc32</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A Simple BloomFilter. Bloomfilter is a probabilistic data structure used to
determine if an element is present in a set. There may be false positives,
but there cannot be false negatives.</p>

<h2>Usage</h2>

<p>   <code>redback.createBloomFilter(key [, size, hashes]);</code></p>

<h2>Options</h2>

<p>   <code>size</code> - Size of the bloom filter , default is 100 bits.
   <code>hashes</code> - Number of hashes to perform. default is 2.</p>

<h2>Reference</h2>

<p>   http://redis.io/commands#string
   http://en.wikipedia.org/wiki/Bloom_filter
   http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = string(bits)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">BloomFilter</span> = <span class="variable">exports</span>.<span class="class">BloomFilter</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Adds an element to the bloom filter.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  item - Item to store into bloom filter</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">BloomFilter</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span>(<span class="variable">item</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(), <span class="variable">crc</span>;

    <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">hash_index</span> = <span class="number integer">0</span>; <span class="variable">hash_index</span> &<span class="variable">lt</span>; <span class="this">this</span>.<span class="variable">num_hashes</span>; <span class="variable">hash_index</span>++) {
        <span class="variable">crc</span> = <span class="variable">crc32</span>(<span class="variable">item</span>, <span class="variable">hash_index</span>) % (<span class="this">this</span>.<span class="variable">size</span>+<span class="number integer">1</span>);
        <span class="variable">multi</span>.<span class="variable">setbit</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">crc</span>, <span class="number integer">1</span>);
    }
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span> || <span class="keyword">function</span> () {});
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Checks if the element exists in the bloom filter. 
This can return false positives( i.e An element does not exist but it returns true)
But this can never return false negatives. (i.e an element )</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  item - Item to check for existence in bloom filter</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">BloomFilter</span>.<span class="variable">prototype</span>.<span class="variable">exists</span> = <span class="keyword">function</span>(<span class="variable">item</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(), <span class="variable">crc</span>;
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};

    <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">hash_index</span> = <span class="number integer">0</span>; <span class="variable">hash_index</span> &<span class="variable">lt</span>; <span class="this">this</span>.<span class="variable">num_hashes</span>; <span class="variable">hash_index</span>++) {
        <span class="variable">crc</span> = <span class="variable">crc32</span>(<span class="variable">item</span>, <span class="variable">hash_index</span>) % (<span class="this">this</span>.<span class="variable">size</span>+<span class="number integer">1</span>);
        <span class="variable">multi</span>.<span class="variable">getbit</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">crc</span>);
    }

    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">results</span>) {
        <span class="variable">callback</span>(<span class="variable">err</span>, <span class="variable">results</span>.<span class="variable">indexOf</span>(<span class="number integer">0</span>) === -<span class="number integer">1</span>);
    });

    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Resets the Bloom filter.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">BloomFilter</span>.<span class="variable">prototype</span>.<span class="variable">reset</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">set</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="number integer">0</span>, <span class="variable">callback</span> || <span class="keyword">function</span> () {});
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/CappedList.js"><a href="#">CappedList</a></h2></td><td>lib/advanced_structures/CappedList.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">List</span> = <span class="variable">require</span>(<span class="string">'../base_structures/List'</span>).<span class="class">List</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A Redis list with a fixed length. Each command that adds a value to the
list is followed by an <code>LTRIM</code> command.</p>

<h2>Usage</h2>

<p>   <code>redback.createCappedList(key [, max_length]);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#lists
   http://redis.io/commands/ltrim</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = list(values)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">CappedList</span> = <span class="variable">exports</span>.<span class="class">CappedList</span> = <span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">extend</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Insert an element before the specified pivot.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  pivot</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">insertBefore</span> = <span class="keyword">function</span> (<span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>()
    <span class="variable">multi</span>.<span class="variable">linsert</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="string">'BEFORE'</span>, <span class="variable">pivot</span>, <span class="variable">value</span>);
    <span class="variable">multi</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span> * <span class="this">this</span>.<span class="variable">len</span>, -<span class="number integer">1</span>);
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Insert an element after the specified pivot.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  pivot</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">insertAfter</span> = <span class="keyword">function</span> (<span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>()
    <span class="variable">multi</span>.<span class="variable">linsert</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="string">'AFTER'</span>, <span class="variable">pivot</span>, <span class="variable">value</span>);
    <span class="variable">multi</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span> * <span class="this">this</span>.<span class="variable">len</span>, -<span class="number integer">1</span>);
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the start of the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">unshift</span> = <span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">lpush</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">values</span>)) {
        <span class="keyword">var</span> <span class="variable">key</span> = <span class="this">this</span>.<span class="variable">key</span>;
        <span class="variable">values</span>.<span class="variable">reverse</span>().<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">value</span>) {
            <span class="variable">multi</span>.<span class="variable">lpush</span>(<span class="variable">key</span>, <span class="variable">value</span>);
        });
    } <span class="keyword">else</span> {
        <span class="variable">multi</span>.<span class="variable">lpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">values</span>);
    }
    <span class="variable">multi</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span> * <span class="this">this</span>.<span class="variable">len</span>, -<span class="number integer">1</span>);
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the end of the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">push</span> = <span class="class">CappedList</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">values</span>)) {
        <span class="keyword">var</span> <span class="variable">key</span> = <span class="this">this</span>.<span class="variable">key</span>;
        <span class="variable">values</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">value</span>) {
            <span class="variable">multi</span>.<span class="variable">rpush</span>(<span class="variable">key</span>, <span class="variable">value</span>);
        });
    } <span class="keyword">else</span> {
        <span class="variable">multi</span>.<span class="variable">rpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">values</span>);
    }
    <span class="variable">multi</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span> * <span class="this">this</span>.<span class="variable">len</span>, -<span class="number integer">1</span>);
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/DensitySet.js"><a href="#">DensitySet</a></h2></td><td>lib/advanced_structures/DensitySet.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">SortedSet</span> = <span class="variable">require</span>(<span class="string">'../base_structures/SortedSet'</span>).<span class="class">SortedSet</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>The DensitySet is similar to a SortedSet but the ability to explicitly
set an element's score has been removed. Instead, adding/removing
an element will increment/decrement its score, e.g.
    <code>DensitySet.add(['foo','foo','foo'], ..)</code> //'foo' has a score of 3</p>

<h2>Usage</h2>

<p>   <code>redback.createDensitySet(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#sorted-sets</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = zset(count =&gt; element)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">DensitySet</span> = <span class="variable">exports</span>.<span class="class">DensitySet</span> = <span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">extend</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">DensitySet</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">element</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">addAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="number integer">1</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove one or more elements from the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">DensitySet</span>.<span class="variable">prototype</span>.<span class="variable">remove</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">element</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">removeAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span>, <span class="variable">element</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">removed</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
        <span class="variable">self</span>.<span class="variable">client</span>.<span class="variable">zremrangebyscore</span>(<span class="variable">self</span>.<span class="variable">key</span>, <span class="string">'-inf'</span>, <span class="number integer">0</span>, <span class="variable">callback</span>);
    });
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/KeyPair.js"><a href="#">KeyPair</a></h2></td><td>lib/advanced_structures/KeyPair.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>The KeyPair is a structure where unique values are assigned an
ID (like a table with a primary auto-incrementing key and
a single unique column). Internally, the KeyPair uses two Redis
hashes to provide O(1) lookup by both ID and value.</p>

<h2>Usage</h2>

<p>   <code>redback.createKeyPair(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#hashes</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key     = hash(id =&gt; value)</code>
   <code>(namespace:)key:ids = hash(value =&gt; id)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">KeyPair</span> = <span class="variable">exports</span>.<span class="class">KeyPair</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add a unique value to the KeyPair and return its id. If the value already
exists, the existing id is returned.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="comment">//Pass on an array of values to addAll()</span>
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">value</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">addAll</span>(<span class="variable">value</span>, <span class="variable">callback</span>);
    }

    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>, <span class="variable">hashed_value</span> = <span class="this">this</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>);
    <span class="comment">//Check if the value already has an id</span>
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">idkey</span>, <span class="variable">value</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">id</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
        <span class="keyword">if</span> (<span class="keyword">null</span> !== <span class="variable">id</span>) {
            <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">id</span>);
        } <span class="keyword">else</span> {
            <span class="comment">//If not, create a new id</span>
            <span class="variable">self</span>.<span class="variable">autoincrement</span>(<span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">id</span>) {
                <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);

                <span class="comment">//Set the id and value simultaneously</span>
                <span class="keyword">var</span> <span class="variable">multi</span> = <span class="variable">self</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
                <span class="variable">multi</span>.<span class="variable">hsetnx</span>(<span class="variable">self</span>.<span class="variable">idkey</span>, <span class="variable">hashed_value</span>, <span class="variable">id</span>);
                <span class="variable">multi</span>.<span class="variable">hsetnx</span>(<span class="variable">self</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="variable">value</span>);
                <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">response</span>) {
                    <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);

                    <span class="comment">//Another client may have add at exactly the same time, so do</span>
                    <span class="comment">//another get to get the actual stored id</span>
                    <span class="variable">self</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="variable">self</span>.<span class="variable">idkey</span>, <span class="variable">hashed_value</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">real_id</span>) {
                        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
                        <span class="keyword">if</span> (<span class="variable">real_id</span> == <span class="variable">id</span>) {
                            <span class="keyword">return</span> <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">real_id</span>);
                        } <span class="keyword">else</span> {
                            <span class="comment">//Another client did beat us! remove the bad key</span>
                            <span class="variable">self</span>.<span class="variable">client</span>.<span class="variable">hdel</span>(<span class="variable">self</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="keyword">function</span> (<span class="variable">err</span>) {
                                <span class="keyword">if</span> (<span class="variable">err</span>) {
                                    <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
                                } <span class="keyword">else</span> {
                                    <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">real_id</span>);
                                }
                            });
                        }
                    });
                });
            });
        }
    });
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add multiple unique values to the KeyPair and return and
object containing {value: id, ...}.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Array</em>  values</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">addAll</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,
        <span class="variable">remaining</span> = <span class="variable">values</span>.<span class="variable">length</span>,
        <span class="variable">ids</span> = {},
        <span class="variable">failed</span> = <span class="variable">false</span>;

    <span class="variable">values</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">value</span>) {
        <span class="variable">self</span>.<span class="variable">add</span>(<span class="variable">value</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">id</span>) {
            <span class="keyword">if</span> (<span class="variable">failed</span>) {
                <span class="keyword">return</span>;
            } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">err</span>) {
                <span class="variable">failed</span> = <span class="variable">true</span>;
                <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
            } <span class="keyword">else</span> {
                <span class="variable">ids</span>[<span class="variable">value</span>] = <span class="variable">id</span>;
                <span class="keyword">if</span> (!--<span class="variable">remaining</span>) <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">ids</span>);
            }
        });
    });
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lookup a unique value and get the associated id.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span> (<span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">value</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">value</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hgetall</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">value</span>)) {
        <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">l</span> = <span class="variable">value</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">l</span>; <span class="variable">i</span>++) {
            <span class="variable">value</span>[<span class="variable">i</span>] = <span class="this">this</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>[<span class="variable">i</span>]);
        }
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hmget</span>(<span class="this">this</span>.<span class="variable">idkey</span>, <span class="variable">value</span>, <span class="variable">callback</span>)
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">idkey</span>, <span class="this">this</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>), <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the value associated with the id.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int | Array</em>  id(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">getById</span> = <span class="keyword">function</span> (<span class="variable">id</span>, <span class="variable">callback</span>) {
	<span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">id</span>))
    	<span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hmget</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="variable">callback</span>);
	<span class="keyword">else</span>
    	<span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get an array of ids.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">ids</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hkeys</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get an array of values.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">values</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hvals</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check whether a unique value already exists and  has an associated id.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">exists</span> = <span class="keyword">function</span> (<span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hexists</span>(<span class="this">this</span>.<span class="variable">idkey</span>, <span class="this">this</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>), <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Checks whether an id exists.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">idExists</span> = <span class="keyword">function</span> (<span class="variable">id</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hexists</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Deletes a unique value and its associated id.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="keyword">delete</span> = <span class="keyword">function</span> (<span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>, <span class="variable">value</span> = <span class="this">this</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">idkey</span>, <span class="variable">value</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">id</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span> || <span class="variable">value</span> == <span class="keyword">null</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
        <span class="variable">self</span>.<span class="variable">_delete</span>(<span class="variable">id</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    });
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Deletes an id and its associated unique value.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  id</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">deleteById</span> = <span class="keyword">function</span> (<span class="variable">id</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">id</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">value</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span> || <span class="variable">value</span> == <span class="keyword">null</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
        <span class="variable">self</span>.<span class="variable">_delete</span>(<span class="variable">id</span>, <span class="variable">self</span>.<span class="variable">hashValue</span>(<span class="variable">value</span>), <span class="variable">callback</span>);
    });
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the number of unique values.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">length</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hlen</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Override this method if you need to hash the unique value
in the second internal hash (i.e. if values are large).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>return</strong>: <em>string</em>  hashed_value</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">KeyPair</span>.<span class="variable">prototype</span>.<span class="variable">hashValue</span> = <span class="keyword">function</span> (<span class="variable">value</span>) {
    <span class="keyword">return</span> <span class="variable">value</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/Lock.js"><a href="#">Lock</a></h2></td><td>lib/advanced_structures/Lock.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">crypto</span> = <span class="variable">require</span>(<span class="string">'crypto'</span>);
<span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A distributed lock.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Lock</span> = <span class="variable">exports</span>.<span class="class">Lock</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Acquire a temporary lock on some key.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>     key             The unique key of the lock</p></li><li><p><strong>param</strong>: <em>number</em>     ttl             The amount of time (in seconds) before the lock expires</p></li><li><p><strong>param</strong>: <em>Function</em>   callback        Invoked when the process completes</p></li><li><p><strong>param</strong>: <em>Error</em>      callback.err    An error that occurred, if any</p></li><li><p><strong>param</strong>: <em>string</em>     callback.token  The token that was acquired if successful. If the lock was</p><p>                                 not acquired then this will be <code>undefined</code></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Lock</span>.<span class="variable">prototype</span>.<span class="variable">acquire</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">ttl</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">client</span> = <span class="this">this</span>.<span class="variable">client</span>;

    <span class="variable">_createToken</span>(<span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">token</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) {
            <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
        }

        <span class="variable">client</span>.<span class="variable">setnx</span>(<span class="variable">key</span>, <span class="variable">token</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">wasSet</span>) {
            <span class="keyword">if</span> (<span class="variable">err</span>) {
                <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
            } <span class="keyword">else</span> <span class="keyword">if</span> (!<span class="variable">wasSet</span>) {
                <span class="comment">// We did not successfully acquire the lock. Since a process can crash after it sets</span>
                <span class="comment">// the lock but before it sets the expiry, we need to avoid deadlocks by ensuring</span>
                <span class="comment">// the lock has a TTL associated to it</span>
                <span class="variable">_ensureTtl</span>(<span class="variable">client</span>, <span class="variable">key</span>, <span class="variable">ttl</span>);
                <span class="keyword">return</span> <span class="variable">callback</span>();
            }

            <span class="comment">// Apply the expiry to the lock</span>
            <span class="variable">client</span>.<span class="variable">expire</span>(<span class="variable">key</span>, <span class="variable">ttl</span>, <span class="keyword">function</span>(<span class="variable">err</span>) {
                <span class="keyword">if</span> (<span class="variable">err</span>) {
                    <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
                }

                <span class="comment">// Return the token, which is used to release the lock</span>
                <span class="keyword">return</span> <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">token</span>);
            });
        });
    });
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Release a lock that was acquired with the provided key and token.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>     key                 The key for the lock to release</p></li><li><p><strong>param</strong>: <em>string</em>     token               The token that was generated for the lock acquisition</p></li><li><p><strong>param</strong>: <em>Function</em>   callback            Invoked when the function completes</p></li><li><p><strong>param</strong>: <em>Error</em>      callback.err        An error that occurred, if any</p></li><li><p><strong>param</strong>: <em>boolean</em>    callback.hadLock    Determines whether or not we owned the lock at the time</p><p>                                     that we released it</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Lock</span>.<span class="variable">prototype</span>.<span class="variable">release</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">token</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">client</span> = <span class="this">this</span>.<span class="variable">client</span>;

    <span class="variable">client</span>.<span class="variable">get</span>(<span class="variable">key</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">lockedToken</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) {
            <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
        } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">lockedToken</span> !== <span class="variable">token</span>) {
            <span class="comment">// The current token is not the one we acquired. It's possible we held the lock longer</span>
            <span class="comment">// than its expiry</span>
            <span class="keyword">return</span> <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">false</span>);
        }

        <span class="comment">// We have the token, simply delete the lock key</span>
        <span class="variable">client</span>.<span class="variable">del</span>(<span class="variable">key</span>, <span class="keyword">function</span>(<span class="variable">err</span>) {
            <span class="keyword">if</span> (<span class="variable">err</span>) {
                <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
            }

            <span class="keyword">return</span> <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">true</span>);
        });
    });
};</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/Queue.js"><a href="#">Queue</a></h2></td><td>lib/advanced_structures/Queue.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>),
    <span class="class">List</span> = <span class="variable">require</span>(<span class="string">'../base_structures/List'</span>).<span class="class">List</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A simple FIFO/LIFO queue.</p>

<h2>Usage</h2>

<p>   <code>redback.createQueue(key [, is_fifo]);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#lists
   http://en.wikipedia.org/wiki/Queue<em>(data</em>structure)</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = list(values)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Queue</span> = <span class="variable">exports</span>.<span class="class">Queue</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the queue.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Queue</span>.<span class="variable">prototype</span>.<span class="variable">enqueue</span> = <span class="class">Queue</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">list</span>.<span class="variable">unshift</span>(<span class="variable">values</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove the next element from the queue.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  wait (optional) - block for this many seconds</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Queue</span>.<span class="variable">prototype</span>.<span class="variable">dequeue</span> = <span class="class">Queue</span>.<span class="variable">prototype</span>.<span class="variable">next</span> = <span class="keyword">function</span> (<span class="variable">wait</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">list</span>[<span class="this">this</span>.<span class="variable">fifo</span> ? <span class="string">'pop'</span> : <span class="string">'shift'</span>](<span class="variable">wait</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/RateLimit.js"><a href="#">RateLimit</a></h2></td><td>lib/advanced_structures/RateLimit.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>See https://gist.github.com/chriso/54dd46b03155fcf555adccea822193da</p>

<p>Count the number of times a subject performs an action over an interval
in the immediate past - this can be used to rate limit the subject if
the count goes over a certain threshold. For example, you could track
how many times an IP (the subject) has viewed a page (the action) over
a certain time frame and limit them accordingly.</p>

<h2>Usage</h2>

<p>   <code>redback.createRateLimit(action [, options]);</code></p>

<h2>Options</h2>

<p>   <code>bucket_interval</code> - default is 5 seconds
   <code>bucket_span</code>     - default is 10 minutes
   <code>subject_expiry</code>  - default is 20 minutes</p>

<h2>Reference</h2>

<p>   https://gist.github.com/chriso/54dd46b03155fcf555adccea822193da
   http://redis.io/topics/data-types#hash</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)action:&lt;subject1&gt; = hash(bucket =&gt; count)</code>
   <code>(namespace:)action:&lt;subject2&gt; = hash(bucket =&gt; count)</code>
   <code>(namespace:)action:&lt;subjectN&gt; = hash(bucket =&gt; count)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">RateLimit</span> = <span class="variable">exports</span>.<span class="class">RateLimit</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Increment the count for the specified subject.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  subject</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">RateLimit</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">subject</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">subject</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">addAll</span>(<span class="variable">subject</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">var</span> <span class="variable">bucket</span> = <span class="this">this</span>.<span class="variable">getBucket</span>(), <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
    <span class="variable">subject</span> = <span class="this">this</span>.<span class="variable">key</span> + <span class="string">':'</span> + <span class="variable">subject</span>;

    <span class="comment">//Increment the current bucket</span>
    <span class="variable">multi</span>.<span class="variable">hincrby</span>(<span class="variable">subject</span>, <span class="variable">bucket</span>, <span class="number integer">1</span>)

    <span class="comment">//Clear the buckets ahead</span>
    <span class="variable">multi</span>.<span class="variable">hdel</span>(<span class="variable">subject</span>, (<span class="variable">bucket</span> + <span class="number integer">1</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>)
         .<span class="variable">hdel</span>(<span class="variable">subject</span>, (<span class="variable">bucket</span> + <span class="number integer">2</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>)

    <span class="comment">//Renew the key TTL</span>
    <span class="variable">multi</span>.<span class="variable">expire</span>(<span class="variable">subject</span>, <span class="this">this</span>.<span class="variable">subject_expiry</span>);

    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="keyword">function</span> (<span class="variable">err</span>) {
        <span class="keyword">if</span> (!<span class="variable">callback</span>) <span class="keyword">return</span>;
        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>);
        <span class="variable">callback</span>(<span class="keyword">null</span>);
    });

    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Count the number of times the subject has performed an action
in the last <code>interval</code> seconds.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  subject</p></li><li><p><strong>param</strong>: <em>int</em>  interval</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">RateLimit</span>.<span class="variable">prototype</span>.<span class="variable">count</span> = <span class="keyword">function</span> (<span class="variable">subject</span>, <span class="variable">interval</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">bucket</span> = <span class="this">this</span>.<span class="variable">getBucket</span>(),
        <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(),
        <span class="variable">count</span> = <span class="class">Math</span>.<span class="variable">floor</span>(<span class="variable">interval</span> / <span class="this">this</span>.<span class="variable">bucket_interval</span>);

    <span class="variable">subject</span> = <span class="this">this</span>.<span class="variable">key</span> + <span class="string">':'</span> + <span class="variable">subject</span>;

    <span class="comment">//Get the counts from the previous `count` buckets</span>
    <span class="variable">multi</span>.<span class="variable">hget</span>(<span class="variable">subject</span>, <span class="variable">bucket</span>);
    <span class="keyword">while</span> (<span class="variable">count</span>--) {
        <span class="variable">multi</span>.<span class="variable">hget</span>(<span class="variable">subject</span>, (--<span class="variable">bucket</span> + <span class="this">this</span>.<span class="variable">bucket_count</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>);
    }

    <span class="comment">//Add up the counts from each bucket</span>
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">counts</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
        <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">count</span> = <span class="number integer">0</span>, <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">l</span> = <span class="variable">counts</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">l</span>; <span class="variable">i</span>++) {
            <span class="keyword">if</span> (<span class="variable">counts</span>[<span class="variable">i</span>]) {
                <span class="variable">count</span> += <span class="variable">parseInt</span>(<span class="variable">counts</span>[<span class="variable">i</span>], <span class="number integer">10</span>);
            }
        }
        <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">count</span>);
    });

    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>An alias for <code>ratelimit.add(subject).count(subject, interval);</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  subject</p></li><li><p><strong>param</strong>: <em>int</em>  interval</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">RateLimit</span>.<span class="variable">prototype</span>.<span class="variable">addCount</span> = <span class="keyword">function</span> (<span class="variable">subject</span>, <span class="variable">interval</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">bucket</span> = <span class="this">this</span>.<span class="variable">getBucket</span>(),
        <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(),
        <span class="variable">count</span> = <span class="class">Math</span>.<span class="variable">floor</span>(<span class="variable">interval</span> / <span class="this">this</span>.<span class="variable">bucket_interval</span>);

    <span class="variable">subject</span> = <span class="this">this</span>.<span class="variable">key</span> + <span class="string">':'</span> + <span class="variable">subject</span>;

    <span class="comment">//Increment the current bucket</span>
    <span class="variable">multi</span>.<span class="variable">hincrby</span>(<span class="variable">subject</span>, <span class="variable">bucket</span>, <span class="number integer">1</span>)

    <span class="comment">//Clear the buckets ahead</span>
    <span class="variable">multi</span>.<span class="variable">hdel</span>(<span class="variable">subject</span>, (<span class="variable">bucket</span> + <span class="number integer">1</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>)
         .<span class="variable">hdel</span>(<span class="variable">subject</span>, (<span class="variable">bucket</span> + <span class="number integer">2</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>)

    <span class="comment">//Renew the key TTL</span>
    <span class="variable">multi</span>.<span class="variable">expire</span>(<span class="variable">subject</span>, <span class="this">this</span>.<span class="variable">subject_expiry</span>);

    <span class="comment">//Get the counts from the previous `count` buckets</span>
    <span class="variable">multi</span>.<span class="variable">hget</span>(<span class="variable">subject</span>, <span class="variable">bucket</span>);
    <span class="keyword">while</span> (<span class="variable">count</span>--) {
        <span class="variable">multi</span>.<span class="variable">hget</span>(<span class="variable">subject</span>, (--<span class="variable">bucket</span> + <span class="this">this</span>.<span class="variable">bucket_count</span>) % <span class="this">this</span>.<span class="variable">bucket_count</span>);
    }

    <span class="comment">//Add up the counts from each bucket</span>
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">counts</span>) {
        <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">callback</span>(<span class="variable">err</span>, <span class="keyword">null</span>);
        <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">count</span> = <span class="number integer">0</span>, <span class="variable">i</span> = <span class="number integer">4</span>, <span class="variable">l</span> = <span class="variable">counts</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">l</span>; <span class="variable">i</span>++) {
            <span class="keyword">if</span> (<span class="variable">counts</span>[<span class="variable">i</span>]) {
                <span class="variable">count</span> += <span class="variable">parseInt</span>(<span class="variable">counts</span>[<span class="variable">i</span>], <span class="number integer">10</span>);
            }
        }
        <span class="variable">callback</span>(<span class="keyword">null</span>, <span class="variable">count</span>);
    });

    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/advanced_structures/SocialGraph.js"><a href="#">SocialGraph</a></h2></td><td>lib/advanced_structures/SocialGraph.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Build a social graph similar to Twitter's. User ID can be a string or
integer, as long as they're unique.</p>

<h2>Usage</h2>

<p>   <code>redback.createSocialGraph(id [, prefix]);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#sets</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)(prefix:)id:following = set(ids)</code>
   <code>(namespace:)(prefix:)id:followers = set(ids)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">SocialGraph</span> = <span class="variable">exports</span>.<span class="class">SocialGraph</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Follow one or more users.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">follow</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,
        <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>, <span class="string">'id'</span>),
        <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">users</span>[<span class="variable">users</span>.<span class="variable">length</span>-<span class="number integer">1</span>] === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">users</span>.<span class="variable">pop</span>();
    } <span class="keyword">else</span> {
        <span class="variable">callback</span> = <span class="keyword">function</span> () {};
    }
    <span class="variable">users</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">user</span>) {
        <span class="variable">multi</span>.<span class="variable">sadd</span>(<span class="variable">self</span>.<span class="variable">key_prefix</span> + <span class="variable">user</span> + <span class="string">':followers'</span>, <span class="variable">self</span>.<span class="variable">id</span>);
        <span class="variable">multi</span>.<span class="variable">sadd</span>(<span class="variable">self</span>.<span class="variable">following</span>, <span class="variable">user</span>);
    });
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Unfollow one or more users.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">unfollow</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>,
        <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>, <span class="string">'id'</span>),
        <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>();
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">users</span>[<span class="variable">users</span>.<span class="variable">length</span>-<span class="number integer">1</span>] === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">users</span>.<span class="variable">pop</span>();
    } <span class="keyword">else</span> {
        <span class="variable">callback</span> = <span class="keyword">function</span> () {};
    }
    <span class="variable">users</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">user</span>) {
        <span class="variable">multi</span>.<span class="variable">srem</span>(<span class="variable">self</span>.<span class="variable">key_prefix</span> + <span class="variable">user</span> + <span class="string">':followers'</span>, <span class="variable">self</span>.<span class="variable">id</span>);
        <span class="variable">multi</span>.<span class="variable">srem</span>(<span class="variable">self</span>.<span class="variable">following</span>, <span class="variable">user</span>);
    });
    <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets the users whom the current users follows as an array.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getFollowing</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">smembers</span>(<span class="this">this</span>.<span class="variable">following</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets an array of users who follow the current user.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getFollowers</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">smembers</span>(<span class="this">this</span>.<span class="variable">followers</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Count how many users the current user follows.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">countFollowing</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">scard</span>(<span class="this">this</span>.<span class="variable">following</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Count how many users follow the current user.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">countFollowers</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">scard</span>(<span class="this">this</span>.<span class="variable">followers</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Checks whether the current user follows the specified user.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph</em>  user</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">isFollowing</span> = <span class="keyword">function</span> (<span class="variable">user</span>, <span class="variable">callback</span>) {
    <span class="variable">user</span> = <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">user</span>, <span class="string">'id'</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sismember</span>(<span class="this">this</span>.<span class="variable">following</span>, <span class="variable">user</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Checks whether the specified user follows the current user.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph</em>  user</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">hasFollower</span> = <span class="keyword">function</span> (<span class="variable">user</span>, <span class="variable">callback</span>) {
    <span class="variable">user</span> = <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">user</span>, <span class="string">'id'</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sismember</span>(<span class="this">this</span>.<span class="variable">followers</span>, <span class="variable">user</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets an array of common followers for one or more users.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getCommonFollowers</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getSocialKeys</span>(<span class="variable">arguments</span>, <span class="string">'followers'</span>);
    <span class="variable">users</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">followers</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sinter</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">users</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets an array of users who are followed by all of the specified user(s).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getCommonFollowing</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getSocialKeys</span>(<span class="variable">arguments</span>, <span class="string">'following'</span>);
    <span class="variable">users</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">following</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sinter</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">users</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets an array of users who follow the current user but do not follow any
of the other specified users.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getDifferentFollowers</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getSocialKeys</span>(<span class="variable">arguments</span>, <span class="string">'followers'</span>);
    <span class="variable">users</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">followers</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sdiff</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">users</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets an array of users who are followed by the current user but not any of
the other specified users.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | SocialGraph | Array</em>  user(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SocialGraph</span>.<span class="variable">prototype</span>.<span class="variable">getDifferentFollowing</span> = <span class="keyword">function</span> (<span class="variable">users</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">users</span> = <span class="this">this</span>.<span class="variable">getSocialKeys</span>(<span class="variable">arguments</span>, <span class="string">'following'</span>);
    <span class="variable">users</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">following</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sdiff</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">users</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/base_structures/Bitfield.js"><a href="#">Bitfield</a></h2></td><td>lib/base_structures/Bitfield.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Wrap the Redis bit commands.</p>

<h2>Usage</h2>

<p>   <code>redback.createBitfield(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/commands#string</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = string</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Bitfield</span> = <span class="variable">exports</span>.<span class="class">Bitfield</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get a single bit</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  bit</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Bitfield</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span> (<span class="variable">bit</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">getbit</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">bit</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Set a single bit. The callback receives the previous value.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  bit</p></li><li><p><strong>param</strong>: <em>bool</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Bitfield</span>.<span class="variable">prototype</span>.<span class="variable">set</span> = <span class="keyword">function</span> (<span class="variable">bit</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">setbit</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">bit</span>, <span class="variable">value</span> ? <span class="number integer">1</span> : <span class="number integer">0</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/base_structures/Hash.js"><a href="#">Hash</a></h2></td><td>lib/base_structures/Hash.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A wrapper for the Redis hash type.</p>

<h2>Usage</h2>

<p>   <code>redback.createHash(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#hashes</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = hash(key =&gt; value)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Hash</span> = <span class="variable">exports</span>.<span class="class">Hash</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get an array of hash keys.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">keys</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hkeys</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get an array of hash values.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">values</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hvals</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the number of hash keys.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">length</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hlen</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Delete a hash key.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="keyword">delete</span> = <span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">del</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hdel</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Checks whether a hash key exists.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">exists</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hexists</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Sets one or more key/value pairs.</p>

<p>To set one key/value pair:
   <code>hash.set('foo', 'bar', callback);</code></p>

<p>To set multiple:
   <code>hash.set({key1:'value1', key2:'value2}, callback);</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Object</em>  hash_key</p></li><li><p><strong>param</strong>: <em>string</em>  value (optional)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">set</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">hash_key</span> === <span class="string">'object'</span>) {
        <span class="variable">callback</span> = <span class="variable">value</span> || <span class="keyword">function</span> () {};
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hmset</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hset</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Sets a key/value pair if the key doesn't already exist.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hsetnx</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Gets one or more key/value pairs.</p>

<p>To get all key/value pairs in the hash:
   <code>hash.get('foo', callback);</code></p>

<p>To get certain key/value pairs:
   <code>hash.get(['foo','bar'], callback);</code>
   <code>hash.get('foo', callback);</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key (optional)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">hash_key</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">hash_key</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hgetall</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">hash_key</span>)) {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hmget</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">callback</span>)
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hget</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Increment the specified hash value.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key</p></li><li><p><strong>param</strong>: <em>int</em>  amount (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">increment</span> =
<span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">incrBy</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">amount</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">amount</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">amount</span>;
        <span class="variable">amount</span> = <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, <span class="variable">amount</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Decrement the specified hash value.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  hash_key</p></li><li><p><strong>param</strong>: <em>int</em>  amount (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">decrement</span> =
<span class="class">Hash</span>.<span class="variable">prototype</span>.<span class="variable">decrBy</span> = <span class="keyword">function</span> (<span class="variable">hash_key</span>, <span class="variable">amount</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">amount</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">amount</span>;
        <span class="variable">amount</span> = <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">hincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">hash_key</span>, -<span class="number integer">1</span> * <span class="variable">amount</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/base_structures/List.js"><a href="#">List</a></h2></td><td>lib/base_structures/List.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A wrapper for the Redis list type.</p>

<h2>Usage</h2>

<p>   <code>redback.createList(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#lists</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = list(values)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">List</span> = <span class="variable">exports</span>.<span class="class">List</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the list as an array.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">values</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="number integer">0</span>, -<span class="number integer">1</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get a range of list elements.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>count</em>  end (optional - defaults to the last element)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">range</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">end</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">end</span>;
        <span class="variable">end</span> = -<span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get one or more elements starting at the specified index.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  index</p></li><li><p><strong>param</strong>: <em>count</em>  count (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span> (<span class="variable">index</span>, <span class="variable">count</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">count</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">count</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lindex</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">index</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">index</span>, <span class="variable">index</span> + <span class="variable">count</span> - <span class="number integer">1</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Cap the length of the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  length</p></li><li><p><strong>param</strong>: <em>bool</em>  keep_earliest (optional - default is false)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">cap</span> = <span class="keyword">function</span> (<span class="variable">length</span>, <span class="variable">keep_earliest</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">var</span> <span class="variable">start</span> = <span class="number integer">0</span>, <span class="variable">end</span> = -<span class="number integer">1</span>;
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">keep_earliest</span> === <span class="string">'function'</span>) {
        <span class="comment">//Keep the last `length` elements</span>
        <span class="variable">start</span> = -<span class="number integer">1</span> * <span class="variable">length</span>;
        <span class="variable">callback</span> = <span class="variable">keep_earliest</span>;
    } <span class="keyword">else</span> {
        <span class="comment">//Keep the first `length` elements</span>
        <span class="variable">end</span> = <span class="variable">length</span> - <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove one or more list elements matching the value.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>bool</em>  count (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">remove</span> = <span class="keyword">function</span> (<span class="variable">value</span>, <span class="variable">count</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">count</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">count</span>;
        <span class="variable">count</span> = <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lrem</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">count</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Trim a list to the specified bounds.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">trim</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">ltrim</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Insert an element before the specified pivot.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  pivot</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">insertBefore</span> = <span class="keyword">function</span> (<span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">linsert</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="string">'BEFORE'</span>, <span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Insert an element after the specified pivot.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  pivot</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">insertAfter</span> = <span class="keyword">function</span> (<span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">linsert</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="string">'AFTER'</span>, <span class="variable">pivot</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Set the element at the specified index.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  index</p></li><li><p><strong>param</strong>: <em>string</em>  value</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">set</span> = <span class="keyword">function</span> (<span class="variable">index</span>, <span class="variable">value</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lset</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">index</span>, <span class="variable">value</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the number of elements in the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">length</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">llen</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get and remove the last element in the list. The first param can be used
to block the process and wait until list elements are available. If the list
is empty in both examples below, the first example will return <code>null</code>, while
the second will wait for up to 3 seconds. If a list element becomes available
during the 3 seconds it will be returned, otherwise <code>null</code> will be returned.</p>

<h2>Example</h2>

<p>   <code>list.shift(callback);</code></p>

<h2>Blocking Example</h2>

<p>   <code>list.shift(3, callback)</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  wait (optional) - seconds to block</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">shift</span> = <span class="keyword">function</span> (<span class="variable">wait</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">wait</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">wait</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lpop</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">blpop</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">wait</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get and remove the last element in the list. The first param can be used
to block the process and wait until list elements are available. If the list
is empty in both examples below, the first example will return <code>null</code>, while
the second will wait for up to 3 seconds. If a list element becomes available
during the 3 seconds it will be returned, otherwise <code>null</code> will be returned.</p>

<h2>Example</h2>

<p>   <code>list.pop(callback);</code></p>

<h2>Blocking Example</h2>

<p>   <code>list.pop(3, callback)</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  wait (optional) - seconds to block</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">pop</span> = <span class="keyword">function</span> (<span class="variable">wait</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">wait</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">wait</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">rpop</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">brpop</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">wait</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the start of the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">unshift</span> = <span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">lpush</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">values</span>)) {
        <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(), <span class="variable">key</span> = <span class="this">this</span>.<span class="variable">key</span>;
        <span class="variable">values</span>.<span class="variable">reverse</span>().<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">value</span>) {
            <span class="variable">multi</span>.<span class="variable">lpush</span>(<span class="variable">key</span>, <span class="variable">value</span>);
        });
        <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">lpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">values</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the end of the list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | array</em>  value(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">push</span> = <span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">values</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">values</span>)) {
        <span class="keyword">var</span> <span class="variable">multi</span> = <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">multi</span>(), <span class="variable">key</span> = <span class="this">this</span>.<span class="variable">key</span>;
        <span class="variable">values</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">value</span>) {
            <span class="variable">multi</span>.<span class="variable">rpush</span>(<span class="variable">key</span>, <span class="variable">value</span>);
        });
        <span class="variable">multi</span>.<span class="variable">exec</span>(<span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">rpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">values</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove the last element of the list and add it to the start
of another list.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>String | List</em>  list</p></li><li><p><strong>param</strong>: <em>bool</em>  wait (optional) - seconds to block while waiting</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">List</span>.<span class="variable">prototype</span>.<span class="variable">popShift</span> = <span class="keyword">function</span> (<span class="variable">list</span>, <span class="variable">wait</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="variable">list</span> = <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">list</span>);
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">wait</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">wait</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">rpoplpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">list</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">brpoplpush</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">list</span>, <span class="variable">wait</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/base_structures/Set.js"><a href="#">Set</a></h2></td><td>lib/base_structures/Set.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A wrapper for the Redis set type.</p>

<h2>Usage</h2>

<p>   <code>redback.createSet(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#sets</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = set(elements)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Set</span> = <span class="variable">exports</span>.<span class="class">Set</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">element</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">addAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sadd</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove one or more elements from the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">remove</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">element</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">removeAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">srem</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get an array of elements in the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">elements</span> = <span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">members</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">smembers</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Move an element to another set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set</em>  dest</p></li><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">move</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">smove</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">dest</span>), <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check whether an element exists in the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">exists</span> = <span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">contains</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sismember</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the length (cardinality) of the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">length</span> = <span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">cardinality</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">scard</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get a random element from the set and optionally remove it.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>bool</em>  remove (optional - default is false)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">random</span> = <span class="keyword">function</span> (<span class="variable">remove</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">remove</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">remove</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">srandmember</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">spop</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the intersection of one or more sets.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">inter</span> = <span class="keyword">function</span> (<span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sinter</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the intersection of one or more sets and store it another
set (dest).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set</em>  dest</p></li><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">interStore</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">dest</span> = <span class="variable">sets</span>.<span class="variable">shift</span>();
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="variable">dest</span>, <span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sinterstore</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the union of one or more sets.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">union</span> = <span class="keyword">function</span> (<span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sunion</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the union of one or more sets and store it another
set (dest).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set</em>  dest</p></li><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">unionStore</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">dest</span> = <span class="variable">sets</span>.<span class="variable">shift</span>();
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="variable">dest</span>, <span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sunionstore</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the difference of one or more sets.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">diff</span> = <span class="keyword">function</span> (<span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sdiff</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the difference of one or more sets and store it another
set (dest).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Set</em>  dest</p></li><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Set</span>.<span class="variable">prototype</span>.<span class="variable">diffStore</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">sets</span>, <span class="variable">callback</span>) {
    <span class="variable">sets</span> = <span class="this">this</span>.<span class="variable">getKeys</span>(<span class="variable">arguments</span>);
    <span class="variable">dest</span> = <span class="variable">sets</span>.<span class="variable">shift</span>();
    <span class="variable">sets</span>.<span class="variable">unshift</span>(<span class="variable">dest</span>, <span class="this">this</span>.<span class="variable">key</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">sdiffstore</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">sets</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/base_structures/SortedSet.js"><a href="#">SortedSet</a></h2></td><td>lib/base_structures/SortedSet.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Structure</span> = <span class="variable">require</span>(<span class="string">'../Structure'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>A wrapper for the Redis sorted set (zset) type. Each element has a
score which is used to rank and order all elements in the set. Elements
are ranked from lowest score to highest (the lowest score has
a rank of 0)</p>

<h2>Usage</h2>

<p>   <code>redback.createSortedSet(key);</code></p>

<h2>Reference</h2>

<p>   http://redis.io/topics/data-types#sorted-sets</p>

<h2>Redis Structure</h2>

<p>   <code>(namespace:)key = zset(score =&gt; element)</code>
 </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">SortedSet</span> = <span class="variable">exports</span>.<span class="class">SortedSet</span> = <span class="class">Structure</span>.<span class="keyword">new</span>();</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Add one or more elements to the set.</p>

<p>To add a single element and score:
   <code>set.add(12, 'foo', callback);</code></p>

<p>To add multiple elements/scores:
   <code>set.add({foo:12, bar:3}, callback);</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  score (optional)</p></li><li><p><strong>param</strong>: <em>string | Object</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> (<span class="variable">score</span>, <span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">score</span> === <span class="string">'object'</span>) {
        <span class="variable">callback</span> = <span class="variable">element</span>;
        <span class="variable">element</span> = <span class="variable">score</span>;
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">addAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zadd</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">score</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove one or more elements from the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string | Array</em>  element(s)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">remove</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">element</span>)) {
        <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">removeAll</span>(<span class="variable">element</span>, <span class="variable">callback</span>);
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrem</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the number of elements in the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">length</span> = <span class="keyword">function</span> (<span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zcard</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check whether an element exists in the set.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">exists</span> =
<span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">contains</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="keyword">function</span> (<span class="variable">err</span>, <span class="variable">score</span>) {
        <span class="variable">callback</span>(<span class="variable">err</span>, <span class="variable">score</span> != <span class="keyword">null</span>);
    });
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the rank of the specified element.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">rank</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrank</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>)
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the score of the specified element.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">score</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">element</span>, <span class="variable">callback</span>)
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Increment the specified element's score.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>int</em>  amount (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em>
;</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">increment</span> =
<span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">incrBy</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">amount</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">amount</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">amount</span>;
        <span class="variable">amount</span> = <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">amount</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Decrement the specified element's score.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>string</em>  element</p></li><li><p><strong>param</strong>: <em>int</em>  amount (optional - default is 1)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em>
;</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">decrement</span> =
<span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">decrBy</span> = <span class="keyword">function</span> (<span class="variable">element</span>, <span class="variable">amount</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">amount</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">amount</span>;
        <span class="variable">amount</span> = <span class="number integer">1</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zincrby</span>(<span class="this">this</span>.<span class="variable">key</span>, -<span class="number integer">1</span> * <span class="variable">amount</span>, <span class="variable">element</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get all elements in the set as an object <code>{element: score, ...}</code>.
If <code>without_scores</code> is true then just an array of elements is returned.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>bool</em>  without_scores (optional - scores are included by default)</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span> (<span class="variable">without_scores</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">without_scores</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">without_scores</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="number integer">0</span>, -<span class="number integer">1</span>, <span class="string">'WITHSCORES'</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
    } <span class="keyword">else</span> {
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="number integer">0</span>, -<span class="number integer">1</span>, <span class="variable">callback</span>);
    }
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get elements with scores between the specified range. Elements are returned
as an object <code>{element: score, ..}</code> and ordered from highest score to lowest.</p>

<p>Note that the <code>start</code> and <code>end</code> range is inclusive and can be an integer or
the constants <code>redback.INF</code> to represent infinity, or <code>redback.NINF</code> to
represent negative infinity. <code>start</code> must be &lt;= <code>end</code>.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>int</em>  count (optional) - the maximum number of elements to return</p></li><li><p><strong>param</strong>: <em>int</em>  offset (optional) - if using count, start at this offset</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">getScores</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">count</span>, <span class="variable">offset</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = <span class="string">'-inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="string">'+inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">count</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">count</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrangebyscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>,
            <span class="string">'WITHSCORES'</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
        <span class="keyword">return</span> <span class="this">this</span>;
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">offset</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">offset</span>;
        <span class="variable">offset</span> = <span class="number integer">0</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrangebyscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="string">'WITHSCORES'</span>,
        <span class="string">'LIMIT'</span>, <span class="variable">offset</span>, <span class="variable">count</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>The same as <code>getScores()</code> but elements are ordered from lowest score to
highest.</p>

<p>Note that <code>end</code> must be &lt;= <code>start</code>.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>int</em>  count (optional) - the maximum number of elements to return</p></li><li><p><strong>param</strong>: <em>int</em>  offset (optional) - if using count, start at this offset</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">getScoresReverse</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">count</span>, <span class="variable">offset</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = <span class="string">'+inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="string">'-inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">count</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">count</span>;
        <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrevrangebyscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>,
            <span class="string">'WITHSCORES'</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
        <span class="keyword">return</span> <span class="this">this</span>;
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">offset</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">offset</span>;
        <span class="variable">offset</span> = <span class="number integer">0</span>;
    }
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrevrangebyscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="string">'WITHSCORES'</span>,
        <span class="string">'LIMIT'</span>, <span class="variable">offset</span>, <span class="variable">count</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove elements with scores between the specified range (inclusive).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">removeScores</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = <span class="string">'-inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="string">'+inf'</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zremrangebyscore</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Count the number of elements with scores between the specified
range (inclusive).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">countScores</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = <span class="string">'-inf'</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="string">'+inf'</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zcount</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get elements with ranks between the specified range (inclusive).</p>

<p>To get the first 3 elements in the set (with the highest scores):
   <code>set.getRanks(0, 2, callback);</code></p>

<p>To get the last 3 elements in the set (lowest scores):
   <code>set.getRanks(-3, -1, callback);</code></p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">getRanks</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = <span class="number integer">0</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = -<span class="number integer">1</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>,
        <span class="string">'WITHSCORES'</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>The same as <code>getRanks()</code> but elements are ordered from lowest score
to the highest.</p>

<p>Note that start and end have been deliberately switched for consistency.</p>

<p>getScoresReverse(arg1, arg2, ..) expects arg1 &gt;= arg2 and so does this
method.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">getRanksReverse</span> = <span class="keyword">function</span> (<span class="variable">end</span>, <span class="variable">start</span>, <span class="variable">callback</span>) {
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = -<span class="number integer">1</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="number integer">0</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zrevrange</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>,
        <span class="string">'WITHSCORES'</span>, <span class="this">this</span>.<span class="variable">parseScores</span>(<span class="variable">callback</span>));
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Remove elements with ranks between the specified range (inclusive).</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  start</p></li><li><p><strong>param</strong>: <em>int</em>  end</p></li><li><p><strong>param</strong>: <em>Function</em>  callback (optional)</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">removeRanks</span> = <span class="keyword">function</span> (<span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>) {
    <span class="variable">callback</span> = <span class="variable">callback</span> || <span class="keyword">function</span> () {};
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">start</span>) <span class="variable">start</span> = -<span class="number integer">1</span>;
    <span class="keyword">if</span> (<span class="keyword">null</span> === <span class="variable">end</span>) <span class="variable">end</span> = <span class="number integer">0</span>;
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zremrangebyrank</span>(<span class="this">this</span>.<span class="variable">key</span>, <span class="variable">start</span>, <span class="variable">end</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get <code>count</code> elements with the highest scores.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  count</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">highestScores</span> = <span class="keyword">function</span> (<span class="variable">count</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">getRanks</span>(-<span class="number integer">1</span> * <span class="variable">count</span>, -<span class="number integer">1</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get <code>count</code> elements with the lowest scores.</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  count</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">lowestScores</span> = <span class="keyword">function</span> (<span class="variable">count</span>, <span class="variable">callback</span>) {
    <span class="this">this</span>.<span class="variable">getRanks</span>(<span class="number integer">0</span>, <span class="variable">count</span> - <span class="number integer">1</span>, <span class="variable">callback</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the intersection of one or more sets. For more information on weights,
aggregate functions, etc. see: http://redis.io/commands/zinterstore</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  dest</p></li><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>int | Array</em>  weights (optional)</p></li><li><p><strong>param</strong>: <em>string</em>  aggregate (optional) - either SUM, MIN or MAX</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">inter</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">sets</span>, <span class="variable">weights</span>, <span class="variable">aggregate</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">args</span> = [], <span class="variable">self</span> = <span class="this">this</span>;
    <span class="variable">args</span>.<span class="variable">push</span>(<span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">dest</span>));

    <span class="comment">//weights/aggregate are optional</span>
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">weights</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">weights</span>;
        <span class="variable">weights</span> = <span class="variable">aggregate</span> = <span class="variable">false</span>;
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">aggregate</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">aggregate</span>;
        <span class="variable">aggregate</span> = <span class="variable">false</span>;
    }

    <span class="comment">//ZINTERSTORE destination numkeys key [key ...]</span>
    <span class="comment">//    [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]</span>
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">sets</span>)) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">sets</span>.<span class="variable">length</span>);
        <span class="variable">sets</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">set</span>) {
            <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">self</span>.<span class="variable">getKey</span>(<span class="variable">set</span>));
        });
    } <span class="keyword">else</span> {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="number integer">1</span>, <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">sets</span>));
    }
    <span class="keyword">if</span> (<span class="variable">weights</span>) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="string">'WEIGHTS'</span>);
        <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">weights</span>)) {
            <span class="variable">weights</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">weight</span>) {
                <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">weight</span>);
            });
        } <span class="keyword">else</span> {
            <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">weights</span>);
        }
    }
    <span class="keyword">if</span> (<span class="variable">aggregate</span>) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="string">'AGGREGATE'</span>, <span class="variable">aggregate</span>);
    }
    <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">callback</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zinterstore</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">args</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Get the union of one or more sets. For more information on weights,
aggregate functions, etc. see: http://redis.io/commands/zunionstore</p>

<h2></h2>

<ul><li><p><strong>param</strong>: <em>int</em>  dest</p></li><li><p><strong>param</strong>: <em>string | Set | Array</em>  set(s)</p></li><li><p><strong>param</strong>: <em>int | Array</em>  weights (optional)</p></li><li><p><strong>param</strong>: <em>string</em>  aggregate (optional) - either SUM, MIN or MAX</p></li><li><p><strong>param</strong>: <em>Function</em>  callback</p></li><li><p><strong>return</strong>: <em>this</em></p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SortedSet</span>.<span class="variable">prototype</span>.<span class="variable">union</span> = <span class="keyword">function</span> (<span class="variable">dest</span>, <span class="variable">sets</span>, <span class="variable">weights</span>, <span class="variable">aggregate</span>, <span class="variable">callback</span>) {
    <span class="keyword">var</span> <span class="variable">args</span> = [], <span class="variable">self</span> = <span class="this">this</span>;
    <span class="variable">args</span>.<span class="variable">push</span>(<span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">dest</span>));

    <span class="comment">//weights/aggregate are optional</span>
    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">weights</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">weights</span>;
        <span class="variable">weights</span> = <span class="variable">aggregate</span> = <span class="variable">false</span>;
    } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">aggregate</span> === <span class="string">'function'</span>) {
        <span class="variable">callback</span> = <span class="variable">aggregate</span>;
        <span class="variable">aggregate</span> = <span class="variable">false</span>;
    }

    <span class="comment">//ZUNIONSTORE destination numkeys key [key ...]</span>
    <span class="comment">//    [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]</span>
    <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">sets</span>)) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">sets</span>.<span class="variable">length</span>);
        <span class="variable">sets</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">set</span>) {
            <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">self</span>.<span class="variable">getKey</span>(<span class="variable">set</span>));
        });
    } <span class="keyword">else</span> {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="number integer">1</span>, <span class="this">this</span>.<span class="variable">getKey</span>(<span class="variable">sets</span>));
    }
    <span class="keyword">if</span> (<span class="variable">weights</span>) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="string">'WEIGHTS'</span>);
        <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">weights</span>)) {
            <span class="variable">weights</span>.<span class="variable">forEach</span>(<span class="keyword">function</span> (<span class="variable">weight</span>) {
                <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">weight</span>);
            });
        } <span class="keyword">else</span> {
            <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">weights</span>);
        }
    }
    <span class="keyword">if</span> (<span class="variable">aggregate</span>) {
        <span class="variable">args</span>.<span class="variable">push</span>(<span class="string">'AGGREGATE'</span>, <span class="variable">aggregate</span>);
    }
    <span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">callback</span>);
    <span class="this">this</span>.<span class="variable">client</span>.<span class="variable">zunionstore</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">client</span>, <span class="variable">args</span>);
    <span class="keyword">return</span> <span class="this">this</span>;
}
</code></pre>
</td>
</tr>	</body>
</html></tbody></table>

================================================
FILE: docs/index.html
================================================
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>Redback - Redis-backed persistence for Node.JS</title>

    <link rel="icon" type="image/png" href="favicon.png" />
    <link href='http://fonts.googleapis.com/css?family=Gruppo' rel='stylesheet' type='text/css' />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
    <script type="text/javascript">

    /*
    Credits
      jQuery noise: https://github.com/DanielRapp/Noisy
      Sexy buttons: https://github.com/ubuwaits/css3-buttons
      Title font:   http://www.google.com/webfonts/family?family=Gruppo
      Favicon:      http://prothemedesign.com/circular-icons
    */

    (function(a){a.fn.noisy=function(b){return this.each(function(){var c=document.createElement("canvas"),h=c.getContext("2d");if(!h&&b.fallback!==undefined&&b.fallback!=="")a(this).css("background-image","url("+b.fallback+"),"+a(this).css("background-image"));else{b=a.extend({},a.fn.noisy.defaults,b);c.width=c.height=b.size;for(var d=h.createImageData(c.width,c.height),e=function(i,k){return Math.floor(Math.random()*(k-i)+i)},j=0;j<b.intensity*Math.pow(b.size,2);j++){var f=e(0,c.width),g=e(0,c.height);f=(f+g*d.width)*4;g=e(0,255);d.data[f]=g;d.data[f+1]=b.monochrome?g:e(0,255);d.data[f+2]=b.monochrome?g:e(0,255);d.data[f+3]=e(0,255*b.opacity)}h.putImageData(d,0,0);a(this).data("original-css")==undefined&&a(this).data("original-css",a(this).css("background-image"));a(this).css("background-image","url("+c.toDataURL("image/png")+"),"+a(this).data("original-css"))}})};a.fn.noisy.defaults={intensity:0.9,size:200,opacity:0.08,fallback:"",monochrome:false}})(jQuery);

    $(function () {
        $('body').noisy({
            'intensity' : 1,
            'size' : 200,
            'opacity' : 0.070,
            'fallback' : '',
            'monochrome' : false
        }).css('background-color', '#FCFCFC');
    });

    </script>

    <style type="text/css">

        body {
            background-color: #FCFCFC;
            font-family: Droid Sans,Arial,Sans Serif;
            font-size: 16px;
            margin: 0;
            border-top: 3px solid #E60B0B;
            color: #444;
        }
        #fork {
            top: 0;
            right: 0;
            position: fixed;
            z-index: 999;
            opacity: 0.8;
        }
        #tag {
            float: right;
            margin-top: 54px;
        }
        #fork:hover {
            opacity: 0.7;
        }
        #container {
            width: 700px;
            margin: 0 auto;
        }
        #header {
            height: 70px;
            border-bottom: 2px dotted #bbb;
            margin-bottom: 10px;
        }
        #header h1 {
            font-family: 'Gruppo',Arial, Sans Serif;
            font-size: 60px;
            font-weight: bold;
            letter-spacing: -1px;
            text-shadow: 1px 2px 2px rgba(30,30,30,0.6);
        }
        #header h1 .red {
            color: #E60B0B;
            text-shadow: 1px 2px 2px rgba(80,0,0,0.6);
        }
        #content h2 {
   
Download .txt
gitextract_q167ekye/

├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── docs/
│   ├── api.html
│   └── index.html
├── index.js
├── lib/
│   ├── Cache.js
│   ├── Channel.js
│   ├── Redback.js
│   ├── Structure.js
│   ├── Utils.js
│   ├── advanced_structures/
│   │   ├── BloomFilter.js
│   │   ├── CappedList.js
│   │   ├── DensitySet.js
│   │   ├── KeyPair.js
│   │   ├── Lock.js
│   │   ├── Queue.js
│   │   ├── RateLimit.js
│   │   └── SocialGraph.js
│   └── base_structures/
│       ├── Bitfield.js
│       ├── Hash.js
│       ├── List.js
│       ├── Set.js
│       └── SortedSet.js
├── package.json
└── test/
    ├── bitfield.test.js
    ├── bloomfilter.test.js
    ├── cache.test.js
    ├── cappedlist.test.js
    ├── channel.test.js
    ├── common.js
    ├── crc32.test.js
    ├── densityset.test.js
    ├── hash.test.js
    ├── keypair.test.js
    ├── list.test.js
    ├── lock.test.js
    ├── namespace.test.js
    ├── queue.test.js
    ├── set.test.js
    ├── socialgraph.test.js
    ├── sortedset.test.js
    └── structure.test.js
Condensed preview — 44 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (404K chars).
[
  {
    "path": ".gitignore",
    "chars": 27,
    "preview": "node_modules\nnpm-debug.log\n"
  },
  {
    "path": ".travis.yml",
    "chars": 108,
    "preview": "sudo: false\n\nlanguage: node_js\n\nnode_js:\n  - stable\n\nservices:\n  - redis-server\n\nafter_script:\n  - npm test\n"
  },
  {
    "path": "LICENSE",
    "chars": 1077,
    "preview": "Copyright (c) 2016 Chris O'Hara <cohara87@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtain"
  },
  {
    "path": "README.md",
    "chars": 3786,
    "preview": "# Redback\n\n[![NPM version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Downloads][downloads-imag"
  },
  {
    "path": "docs/api.html",
    "chars": 191206,
    "preview": "<a href=\"https://github.com/chriso/redback\"><img alt=\"Fork me on GitHub\" id=\"ribbon\" src=\"http://s3.amazonaws.com/github"
  },
  {
    "path": "docs/index.html",
    "chars": 8350,
    "preview": "<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n\n    <title>Redback - Redis-backed persistence for No"
  },
  {
    "path": "index.js",
    "chars": 43,
    "preview": "module.exports = require('./lib/Redback');\n"
  },
  {
    "path": "lib/Cache.js",
    "chars": 9614,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Use Redis as a cache b"
  },
  {
    "path": "lib/Channel.js",
    "chars": 1898,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/Redback.js",
    "chars": 4355,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/Structure.js",
    "chars": 7491,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * All Redback structures"
  },
  {
    "path": "lib/Utils.js",
    "chars": 3238,
    "preview": "/*\n===============================================================================\nCrc32 is a JavaScript function for co"
  },
  {
    "path": "lib/advanced_structures/BloomFilter.js",
    "chars": 2692,
    "preview": "/**\n * Module dependencies.\n */\n\nvar Structure = require('../Structure'),\n    crc32 = require('../Utils').crc32;\n\n/**\n *"
  },
  {
    "path": "lib/advanced_structures/CappedList.js",
    "chars": 3056,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/DensitySet.js",
    "chars": 3411,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/KeyPair.js",
    "chars": 7582,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/Lock.js",
    "chars": 4274,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/Queue.js",
    "chars": 1380,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/RateLimit.js",
    "chars": 5167,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/advanced_structures/SocialGraph.js",
    "chars": 6906,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/base_structures/Bitfield.js",
    "chars": 1083,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/base_structures/Hash.js",
    "chars": 4471,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/base_structures/List.js",
    "chars": 7913,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/base_structures/Set.js",
    "chars": 6688,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "lib/base_structures/SortedSet.js",
    "chars": 15259,
    "preview": "/*!\n * Redback\n * Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n "
  },
  {
    "path": "package.json",
    "chars": 886,
    "preview": "{ \"name\"          : \"redback\",\n  \"description\"   : \"A high-level Redis library\",\n  \"version\"       : \"0.5.1\",\n  \"homepag"
  },
  {
    "path": "test/bitfield.test.js",
    "chars": 795,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/bloomfilter.test.js",
    "chars": 1826,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/cache.test.js",
    "chars": 6659,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/cappedlist.test.js",
    "chars": 4578,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/channel.test.js",
    "chars": 1062,
    "preview": "var redback = require('./common').createClient(),\n    client2 = require('./common').createClient(),\n    assert = require"
  },
  {
    "path": "test/common.js",
    "chars": 144,
    "preview": "var redback = require('../');\n\nexports.createClient = function (options) {\n    return redback.createClient('redis://loca"
  },
  {
    "path": "test/crc32.test.js",
    "chars": 274,
    "preview": "var crc32 = require('../lib/Utils').crc32,\n    assert = require('assert');\n\nmodule.exports = {\n  'test crc32': function "
  },
  {
    "path": "test/densityset.test.js",
    "chars": 4225,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/hash.test.js",
    "chars": 5325,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/keypair.test.js",
    "chars": 4567,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/list.test.js",
    "chars": 11583,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/lock.test.js",
    "chars": 5049,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n// Flush the DB and close the Redis c"
  },
  {
    "path": "test/namespace.test.js",
    "chars": 620,
    "preview": "var redback = require('./common').createClient({namespace: 'foo'}),\n    assert = require('assert');\n\nmodule.exports = {\n"
  },
  {
    "path": "test/queue.test.js",
    "chars": 1519,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/set.test.js",
    "chars": 9426,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/socialgraph.test.js",
    "chars": 7419,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/sortedset.test.js",
    "chars": 11172,
    "preview": "var redback = require('./common').createClient(),\n    assert = require('assert');\n\n//Flush the DB and close the Redis co"
  },
  {
    "path": "test/structure.test.js",
    "chars": 6272,
    "preview": "var redback = require('../'),\n    assert = require('assert'),\n    Structure = redback.Structure,\n    Hash = redback.Hash"
  }
]

About this extraction

This page contains the full source code of the chriso/redback GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 44 files (375.5 KB), approximately 103.0k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!