Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Backbone data persistence through Redis pub/sub and
branch: master
Failed to load latest commit information.
browser Improving error handling.
examples Removing old files, how did those get in there...
vendor Updating serverside functionality.
.gitignore Project creation Updating readme.
index.js Updating serverside functionality.
license Updating serverside functionality.
package.json Updating project information.

Backbone Redis


  • Node
  • Express
  • Backbone
  • Redis


The project can be installed via NPM, or by cloning this repo into your project.

npm install backbone-redis


git clone git://

Server Configuration

var express    = require('express'),
    Redis      = require('redis'),
    bbRedis    = require('../../'),
    browserify = require('browserify'),
    io         = require(''),
    server     = module.exports = express.createServer(),
    io         = io.listen(server);

var db  = Redis.createClient(6379, ''),
    pub = Redis.createClient(6379, ''),
    sub = Redis.createClient(6379, '')

    io        : io,
    database  : db,
    publish   : pub,
    subscribe : sub,
    listener  : 'backbone',


You can also create schemas for your models, which will have hookable methods for you to intercept the data. The hookable methods are create, read, update, delete, subscribe, and unsubscribe, each with both pre and post methods attached.

var fooSchema = bbRedis.schema();

    .pre('create', function(next, model, options, cb) {
        next(model, options, cb);
    .post('create', function(next, model, options, cb) {
        next(model, options, cb);
    .pre('subscribe', function(next, socket, options, cb) {
        next(socket, options, cb);
    .post('subscribe', function(next, socket, options, cb) {
        next(socket, options, cb);

bbRedis.model('foo', fooSchema);

Just be sure the name you give for the schema matches the type attribute that you set on the Backbone model.

Client Configuration

<script src='/'></script>
<script src="/underscore.js"></script>
<script src="/backbone.js"></script>

If you have cloned the repo, just serve the file. Otherwise you can expose it to the client using browserify.

<script src="/backbone.redis.js"></script>

var socket = io.connect();

    io : socket,
    listener : 'message'

var Foo = Backbone.Model.extend({
    url  : 'foos',
    type : 'foo',
    sync : _.sync

var FooList = Backbone.Collection.extend({
    model: Todo,
    url  : 'todos',
    type : 'todo',
    sync : _.sync

Now that there is something to work with, we can use all of the default Backbone methods

FooList.subscribe({}, function(){
        data : 'lorem ipsum'
Something went wrong with that request. Please try again.