Frees resources associated with the client.
.delete()
starts making a delete request against etcd.
Creates a new Election instead. See more information on the Election class documentation.
Name of the election in the etcd instance.
Lease TTL used in the election. This is the maximum time that a node which goes down can remain the leader before being automatically evicted.
.get()
starts a query to look up a single key from etcd.
.getAll()
starts a query to look up multiple keys from etcd.
Resolves to an array of roles available in etcd.
Resolves to an array of users available in etcd.
if()
starts a new etcd transaction, which allows you to execute complex
statements atomically. See documentation on the ComparatorBuilder for
more information.
lease()
grants and returns a new Lease instance. The Lease is
automatically kept alive for you until it is revoked. See the
documentation on the Lease class for some examples.
lock()
is a helper to provide distributed locking capability. See
the documentation on the Lock class for more information and examples.
.mock()
allows you to insert an interface that will be called into
instead of calling out to the "real" service. unmock
should be called
after mocking is finished.
For example:
const sinon = require('sinon');
const { expect } = require('chai');
const { Etcd3 } = require('etcd3');
const client = new Etcd3();
const mock = client.mock({ exec: sinon.stub() });
mock.exec.resolves({ kvs: [{ key: 'foo', value: 'bar' }]});
const output = client.get('foo').string();
expect(output).to.equal('bar');
client.unmock();
namespace adds a prefix and returns a new Namespace, which is used for
operating on keys in a prefixed domain. For example, if the current
namespace is the default "" and you call namespace('user1/'), all
operations on that new namespace will be automatically prefixed
with user1/
. See the Namespace class for more details.
.put()
starts making a put request against etcd.
Returns an object to manipulate the role with the provided name.
stm()
creates a new software transaction, see more details about how
this works and why you might find this useful
on the SoftwareTransaction class.
Removes any previously-inserted mock.
Returns an object to manipulate the user with the provided name.
.watch()
creates a new watch builder. See the documentation on the
WatchBuilder for usage examples.
Generated using TypeDoc
Etcd3 is a high-level interface for interacting and calling etcd endpoints. It also provides several lower-level clients for directly calling methods.
const { Etcd3 } = require('etcd3'); const client = new Etcd3(); await client.put('foo').value('bar'); console.log('foo is:', await client.get('foo').string()); const keys = await client.getAll().prefix('f').strings(); console.log('all keys starting with "f"': keys); await client.delete().all();