基于LevelDB的數據庫:multi-master-merge
一個支持多主復制和合并的數據庫,基于 leveldb, fwdb 和 scuttleup實現。
使用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
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!