Redis HQ adapter for JugglingDB
JavaScript Lua Shell Other
Latest commit d6eba84 Dec 29, 2016 @1602 1602 committed on GitHub Merge pull request #38 from lukechilds/patch-1
Fix package name typo in readme
Permalink
Failed to load latest commit information.
benchmark
lib
test
.DS_Store
.gitignore
.travis.yml
Makefile
README.md
circle.yml
index.js
package.json

README.md

NPM Version NPM Downloads Build status Test Coverage Dependency Status

JugglingDB-Redis

Redis adapter for jugglingdb.

Usage

To use it you need jugglingdb@0.2.x.

  1. Setup dependencies in package.json:
{
  ...
  "dependencies": {
    "jugglingdb": "0.2.x",
    "jugglingdb-redis": "latest"
  },
  ...
}
  1. Use:
    var Schema = require('jugglingdb').Schema;
    var schema = new Schema('redis');

Running tests

Make sure you have redis server running on default port, then run

npm test

Be careful, it could delete your data in database number 0

Additional Features

Backyard

Enabling this feature allows to keep only "hot" data in redis and unload rarely used data to backyard.

Backyard is an additional storage that used by redis adapter to mirror all data. Data in redis has some expiration period when mirrored in backyard database. When expired data requested from redis (actual record is not present), then record loaded from backyard and restored in redis. Each time record requested expiration timeout renewed.

Configuration

Include backyard section using the same format as normal schema settings definition in config/database.js:

exports.development = {
    main: {
        driver: 'redis-hq',
        database: 1,
        log: true,
        backyard: {
            driver: 'mysql',
            username: 'root',
            database: 'myapp'
            log: true,
        }
    }
};

Use expire setting for model in db/schema.js:

db.define('Comment', function(m) {
    m.property('text', String);
    m.set('expire', 30); // expire record in 30 seconds
});

This setting may be also set to -1 to disable expiration.

Usage

Use your models as usual. All data where expire is not set to -1 will be mirrored automatically and restored in redis db when requested after expiration.

Please note that you will get an additional error messages from backyard database. Expiration only being set when both redis and backyard db responded with success to prevent data loss.

Hint 1. If you are using compoundjs and some sql adapter as backyard for redis, then app.enable('autoupdate'); setting is useful to not care about schema (at least in development env).

Hint 2. Use log: true to debug sql queries.

Hint 3. Make sure your schema is sql-friendly. The most often bottleneck is indexes length, specify length attribute for each indexed String property.