New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

backbone-redis

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-redis

Persistant backbone storage through redis pub/sub and socket.io

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

Backbone Redis

Technologies

  • Node
  • Express
  • Backbone
  • Socket.io
  • Redis

Installation

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

npm install backbone-redis

or

git clone git://github.com/sorensen/backbone-redis.git

Server Configuration

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

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

bbRedis.config({
    io        : io,
    database  : db,
    publish   : pub,
    subscribe : sub,
    listener  : 'backbone',
});

server.listen(8080);

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

fooSchema
    .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='/socket.io/socket.io.js'></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();

bbRedis.config({
    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.fetch();
FooList.subscribe({}, function(){
    FooList.create({
        data : 'lorem ipsum'
    })
    FooList.unsubscribe();
});

Keywords

FAQs

Package last updated on 25 Aug 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc