.delete()
starts making a delete request against etcd.
.get()
starts a query to look up a single key from etcd.
.put()
starts making a put request against etcd.
transact runs the function with the current configuration. It will be retried until the transaction succeeds, or until the maximum number of retries has been exceeded.
Generated using TypeDoc
SoftwareTransaction is an implementation of software transaction memory, described in greater detail here. The idea is that you can have a block that contains multiple reads and writes, then we'll commit all those changes as a single transaction, automatically retrying as necessary.
Inside the
.transact()
block, all reads and writes must go through the transaction, not the client, or they won't be tracked.For example, this is a safe way to move 'money' between
bank/account1
andbank/account2
:const amount = 42; etcd3.stm().transact(tx => { return Promise.all([ tx.get('bank/account1').number(), tx.get('bank/account2').number(), ]).then(([balance1, balance2]) => { if (balance1 < amount) { throw new Error('You do not have enough money to transfer!'); } return Promise.all([ tx.put('bank/account1').value(balance1 - amount), tx.put('bank/account2').value(balance2 + amount), }); }); });
(Note: the author does not condone using etcd for your banking infrastructure)