An etcd client library for .Net
Get it on NuGet:
PM> Install-Package Draft
Initialize the Client
varclient=Draft.Etcd.ClientFor(newUri("http://localhost:4001"));Initialize the Client with multiple endpoints
varendpointPool=awaitDraft.Endpoints.EndpointPool.Build().WithRoutingStrategy(Draft.Endpoints.EndpointRoutingStrategy.RoundRobin).WithVerificationStrategy(Draft.Endpoints.EndpointVerificationStrategy.All).VerifyAndBuild(newUri("http://localhost:4001"),newUri("http://localhost:4002"),newUri("http://localhost:5002"));varclient=Draft.Etcd.ClientFor(endpointPool);Set a key
varkeyResult=awaitclient.UpsertKey("/somekey").WithValue("The Value!");Set a key with an expiration
varkeyResult=awaitclient.UpsertKey("/expiringkey").WithValue("I Expire!").WithTimeToLive(300/* seconds */);Get a key
varkeyResult=awaitclient.GetKey("/somekey");Get a key with a fully linearized read
varkeyResult=awaitclient.GetKey("/somekey").WithQuorum(true);Delete a key
awaitclient.DeleteKey("/somekey");Create a directory
vardirResult=awaitclient.CreateDirectory("/foo");Create an expiring directory
vardirResult=awaitclient.CreateDirectory("/foo").WithTimeToLive(300/* seconds */);Watch a key for a single change
client.WatchOnce("/somekey").Subscribe(x =>{/* do the thing */});Monitor a key and child keys for changes
client.Watch("/somekey").WithRecursive(true).Subscribe(x =>{/* do the thing */});Stop monitoring key changes
vardisposable=client.Watch("/somekey").WithRecursive(true).Subscribe(x =>{/* do the thing */});disposable.Dispose();Update a key with an expected value
varresult=awaitclient.Atomic.CompareAndSwap("/atomickey").WithExpectedValue("foo").WithNewValue("bar");Delete a key with an expected modified index
varresult=awaitclient.Atomic.CompareAndDelete("/atomickey").WithExpectedIndex(33);Get cluster members
varmembers=awaitclient.Cluster.GetMembers();Get cluster leader
varleader=awaitclient.Cluster.GetLeader();Add a cluster member
varmemberInfo=awaitclient.Cluster.CreateMember().WithPeerUri(newUri("http://localhost:4002"),newUri("http://localhost:5002"));Remove a cluster member
awaitclient.Cluster.DeleteMember().WithMemberId(memberInfo.Id);