MemDB 分布式事务内存数据库 项目简介
MemDB 是全球首个支持分布式事务的 MongoDB。高性能和可伸缩快速的内存数据访问,高达 25,000 ops (single doc read/write) /碎片 (each shard take one CPU core).系统可水平伸缩没有单点瓶颈真正的分布式 ACID 事务在分布式环境真正支持 ACID (Stands for Atomicity, Consistency, Isolation, Durability) 事务MemDB 让 MongoDB 支持 ACID 事务兼容 MongoDB 和 Mongoose直接使用 MongoDB 的查询 API内置 Mongoose 支持高可用性每个碎片都有一个或者多个 slaves,不会发生单点故障 MemDB shell:架构:Mdbgoose:var memdb = require('memdb-client');
var P = memdb.Promise;
var mdbgoose = memdb.goose;
// Define player schema
var playerSchema = new mdbgoose.Schema({
_id : String,
name : String,
areaId : Number,
deviceType : Number,
deviceId : String,
items : [mdbgoose.SchemaTypes.Mixed],
}, {collection : 'player'});
// Define player model
var Player = mdbgoose.model('player', playerSchema);
var main = P.coroutine(function*(){
// Connect to memdb
yield mdbgoose.connectAsync({
shards : { // specify all shards here
s1 : {host : '127.0.0.1', port: 31017},
s2 : {host : '127.0.0.1', port: 31018},
}
});
// Make a transaction in s1
yield mdbgoose.transactionAsync(P.coroutine(function*(){
var player = new Player({
_id : 'p1',
name: 'rain',
areaId : 1,
deviceType : 1,
deviceId : 'id1',
items : [],
});
// insert a player
yield player.saveAsync();
// find player by id
var doc = yield Player.findByIdAsync('p1');
console.log('%j', doc);
// find player by areaId, return array of players
var docs = yield Player.findAsync({areaId : 1});
console.log('%j', docs);
// find player by deviceType and deviceId
player = yield Player.findOneAsync({deviceType : 1, deviceId : 'id1'});
// update player
player.areaId = 2;
yield player.saveAsync();
// remove the player
yield player.removeAsync();
}), 's1');
});
if (require.main === module) {
main().finally(process.exit);
}
var P = memdb.Promise;
var mdbgoose = memdb.goose;
// Define player schema
var playerSchema = new mdbgoose.Schema({
_id : String,
name : String,
areaId : Number,
deviceType : Number,
deviceId : String,
items : [mdbgoose.SchemaTypes.Mixed],
}, {collection : 'player'});
// Define player model
var Player = mdbgoose.model('player', playerSchema);
var main = P.coroutine(function*(){
// Connect to memdb
yield mdbgoose.connectAsync({
shards : { // specify all shards here
s1 : {host : '127.0.0.1', port: 31017},
s2 : {host : '127.0.0.1', port: 31018},
}
});
// Make a transaction in s1
yield mdbgoose.transactionAsync(P.coroutine(function*(){
var player = new Player({
_id : 'p1',
name: 'rain',
areaId : 1,
deviceType : 1,
deviceId : 'id1',
items : [],
});
// insert a player
yield player.saveAsync();
// find player by id
var doc = yield Player.findByIdAsync('p1');
console.log('%j', doc);
// find player by areaId, return array of players
var docs = yield Player.findAsync({areaId : 1});
console.log('%j', docs);
// find player by deviceType and deviceId
player = yield Player.findOneAsync({deviceType : 1, deviceId : 'id1'});
// update player
player.areaId = 2;
yield player.saveAsync();
// remove the player
yield player.removeAsync();
}), 's1');
});
if (require.main === module) {
main().finally(process.exit);
}