Skip to content
No description or website provided.
JavaScript
Latest commit b27a34e Jun 24, 2014 @dominictarr 1.2.1
Failed to load latest commit information.
example no more slaves Jun 9, 2013
test close stream in eventually consistent callback Jun 20, 2014
.gitignore [7b74460] slave key and value encoding must also be explicit plus key… Mar 12, 2014
.travis.yml ci Jun 20, 2014
LICENSE initial Mar 27, 2013
README.md
index.js implement binary Jun 16, 2013
inject.js tidy Jun 21, 2014
msgpack.js implement binary Jun 16, 2013
package.json 1.2.1 Jun 24, 2014

README.md

level-replicate build status

master-master replication with levelup.

Implements scuttlebutt style handshake and then syncs data, then replicates real time changes.

Example

Replicate from a between two processes. One process starts a server, and another connects.

//master1.js
var level   = require('level')
var SubLevel  = require('level-sublevel')
var net       = require('net')
var Replicate = require('level-replicate')

//setup the database.
var db = SubLevel(level('/tmp/example-master'))

//install Master plugin!
var master = Replicate(db, 'master', "MASTER-1")

//create a server, and stream data to who ever connects.
net.createServer(function (stream) {
  stream.pipe(master.createStream({tail: true})).pipe(stream)
}).listen(9999, function () {
  console.log('master db listening on 9999')
})

Then, the code for the client!

//master2.js
var levelup   = require('level')
var SubLevel  = require('level-sublevel')
var net       = require('net')
var Replicate = require('level-replicate')

var db = SubLevel(level('/tmp/example-slave'))
var master = Replicate(db, 'master', "MASTER-2")

var stream = net.connect(9999)

stream.pipe(master.createStream({tail: true})).pipe(stream)

Wow, that was simple.

Binary data.

by default, level-replicate supports buffers by converting them to base64 via stream-serializer and json-buffer. If you desire more efficiency, use level-replicate/msgpack

var Replicate = require('level-replicate/msgpack')

var db = SubLevel(level('/tmp/example-slave'))
var master = Replicate(db, 'master', "MASTER-2")

Replicating Sublevels Recursively

//install Master plugin with the `recursive` option set to `true`.
var master = Replicate(db, 'master', "MASTER-1", {recursive: true})

// changes made to all sublevels of `db` will replicate!
db.sublevel('documents').put('foo', {bar: 'baz'}, function() { ... })

note: this depends on having level-sublevel@>=5.2.0 with level-hooks@>=4.5.0

License

MIT

Something went wrong with that request. Please try again.