rebridge 介绍
Rebridge是一个透明的JavaScript-Redis桥。您可以使用它来创建自动同步到Redis数据库的JavaScript对象。
安装
npm install rebridge
同步,非阻塞使用
const Rebridge = require("rebridge");
const redis = require("redis");
const client = redis.createClient();
const db = new Rebridge(client,{
mode: "deasync"
});
db.users = [];
db.users.push({
username: "johndoe",
email: "johndoe@domain.com"
});
db.users.push({
username: "foobar",
email: "foobar@domain.com"
});
db.users.push({
username: "CapacitorSet",
email: "CapacitorSet@users.noreply.github.com"
});
console.log("Users:",db.users._value); // Prints the list of users
const [me] = db.users.filter(user => user.username === "CapacitorSet");
console.log("Me:",me); // Prints [{username: "CapacitorSet",email: "..."}]
client.quit();
异步使用
const Rebridge = require("rebridge");
const redis = require("redis");
const client = redis.createClient();
const db = new Rebridge(client);
db.users.set([])
.then(() => Promise.all([
db.users.push({
username: "johndoe",
email: "johndoe@domain.com"
}),
db.users.push({
username: "foobar",
email: "foobar@domain.com"
}),
db.users.push({
username: "CapacitorSet",
email: "CapacitorSet@users.noreply.github.com"
})
]))
.then(() => db.users._promise)
.then(arr => console.log("Users:",arr)) // Prints the list of users
.then(() => db.users.filter(user => user.username === "CapacitorSet"))
.then(([me]) => console.log("Me:",me)) // Prints [{username: "CapacitorSet",email: "..."}]
.then(() => client.quit())
.catch(err => console.log("An error occurred:",err));
Rebridge使用ES6代理对象,因此至少需要Node 6。
GitHub:https://github.com/CapacitorSet/rebridge
网站描述:Redis的透明Javascript接口
rebridge
小编说
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。