基于LevelDB的数据库:multi-master-merge

jopen 10年前

一个支持多主复制和合并的数据库,基于 leveldb, fwdbscuttleup实现。

使用
var mmm = require('multi-master-merge')  var level = require('level')    var mdb = mmm(level('data.db'), {encoding:'utf-8'})    mdb.put('hello', 'world', function(err, doc) {    console.log('Inserted:', doc)    mdb.get('hello', function(err, docs) {      console.log('"hello" contains the following:', docs)    })  })

复制

复制数据库只需打开同步流和管道到另一个数据库

// a and b are two database instances  var s1 = a.sync() // open a sync stream for db a  var s2 = b.sync() // open a sync stream for db b    s1.pipe(s2).pipe(s1) // pipe them together to start replicating

Updates will now be replicated between the two instances. If two databases inserts a document on the same key both of them will be present if you do a mdb.get(key)

a.put('hello', 'a')  b.put('hello', 'b')    setTimeout(function() {    a.get('hello', function(err, docs) {      console.log(docs) // will print [{peer:..., value:'a'}, {peer:..., value:'b'}]    })  }, 1000) // wait a bit for the inserts to replicate

项目主页:http://www.open-open.com/lib/view/home/1413507869809