etcd-node-client
A gRPC based etcd client which supports etcd V3 api, written in node.js
Prerequisites:
- etcd version supported: > 3.0.0
- node.js version supported: > 0.12 (grpc only works on node 0.12 or above)
About this client:
- Currently it supports some but not all v3.0 APIs (Adding). Please check out this for more about etcd official API.
- Proto files are directly copied from etcd repo, if there is something wrong, please check create an issue here and follow the etcd official proto files.
How to install
npm install etcd-node-client
etcd V3.0 APIs supported (Updating):
-
KV service:
- put
- range
- deleteRange
- txn
- compact
-
Lease service:
- leaseGrant
- leaseRevoke
-
Watch service: Watch service is a streaming api, please check this out
-
- status (same as official api)
- getLeaderId
How to use (Take the KV service as an example):
- Create a client:
var etcd = ; var endpoints = '127.0.0.1:2379' '127.0.0.1:22379' '127.0.0.1:32379';var lbAlgorithm = 'RoundRobin'; var client = endpoints lbAlgorithm;
- Put a kv value:
clientkv;
- get a kv value:
clientkv;
- Delete a kv value:
clientkv;
- Transaction ops:
clientkv;
Watch:
Watch is a bit different from the official v3 api, this is how we use watch:
- Create a watcher on a key:
clientwatcher;
- A watcher created:
clientwatcher;
- Cancel/delete a watcher:
clientwatcher; //'0' is the watcher id which associated to the watched key.
- A watcher canceled/deleted:
clientwatcher;
- Events happened on a watcher:
clientwatcher;
- Close the watch stream:
clientwatcher; //message is optional
Maintenance:
- status
clientmaintenancestatus { consoledirres; //res is the response object};
- getLeaderId
clientmaintenance;
License
- MIT.