Fork me on GitHub

Everything here is experimental, and the API is no exception, so expect things to change in future releases.

Master

You can setup master by simply passing in the Alfred.open option replication_master as true.

Replication is still very crudely implemented. The slave gets all the existing data on the first connection, which is less than optimal. As everything here, use it at your own risk.

Example:

var Alfred = require('alfred');
var options = {
 replication_master: true,
 replication_port: 5294 // port 5293 is default
};
Alfred.open('path/do/master/db/dir', options, function(err, db) {
 if (err) { throw err; }
 // Now I have db and a replication server on TCP port 5294
});

Slave

You can easily setup a slave by using the database.replicateFrom method like this:


var Alfred = require('alfred');
var options = {
  source_port: 5294
};
Alfred.open('path/do/slave/db/dir', options, function(err, db) {
  if (err) { throw err; }
  db.replicateFrom('master.host.name.com', options, function(err) {
    // this callback is called when there is an error
    throw err;
  });
});

database.replicateFrom (host_name, options, error_callback)

  • host_name: master host name.
  • error_callback (err): called when there is a replication error.
  • options: supported options are:
    • source_port: TCP port where the master server is listening. Defaults to 5293.
    • reconnect_count: Number of reconnect tries after loosing connection to master. Defaults to 20.
    • reconnect_timeout: Average time after which we try to reconnect after loosing connection to master. In miliseconds. Defaults to 1000 (1 second).