$ npm i egg-etcd --save
// {app_root}/config/plugin.js
exports.eggEtcd = {
enable: true,
package: 'egg-etcd',
};
// {app_root}/config/config.default.js
exports.eggEtcd = {
hosts: [
'your-etcd-cluster1.host.com',
'your-etcd-cluster2.host.com',
'your-etcd-cluster3.host.com',
],
auth: {
username: 'your_user_name',
password: 'your_password',
},
};
see config/config.default.js for more detail.
// app.js
// get value
app.etcd.get('foo').string().then(value => {
console.log('foo value is:', value);
});
// watch value
app.etcd
.watch()
.key('bar')
.create()
.then(watcher => {
watcher.on('put', res => {
console.log('bar value is:', res.value);
});
});
This plugin is based on Etcd3, you can read Etcd3 document for more info.
Please open an issue here.