GithubHelp home page GithubHelp logo

draft's Introduction

Draft

Build status

An etcd client library for .Net

Get it on NuGet:

PM> Install-Package Draft

Basic usage

Initialize the Client

var client = Draft.Etcd.ClientFor(new Uri("http://localhost:4001"));

Initialize the Client with multiple endpoints

var endpointPool = await Draft.Endpoints.EndpointPool.Build()
	.WithRoutingStrategy(Draft.Endpoints.EndpointRoutingStrategy.RoundRobin)
	.WithVerificationStrategy(Draft.Endpoints.EndpointVerificationStrategy.All)
	.VerifyAndBuild(
		new Uri("http://localhost:4001"), 
		new Uri("http://localhost:4002"), 
		new Uri("http://localhost:5002")
	);
var client = Draft.Etcd.ClientFor(endpointPool);

Key based operations

Set a key

var keyResult = await client
                .UpsertKey("/somekey")
                .WithValue("The Value!");

Set a key with an expiration

var keyResult = await client
                .UpsertKey("/expiringkey")
                .WithValue("I Expire!")
                .WithTimeToLive(300 /* seconds */);

Get a key

var keyResult = await client
                .GetKey("/somekey");

Get a key with a fully linearized read

var keyResult = await client
                .GetKey("/somekey")
                .WithQuorum(true);

Delete a key

await client.DeleteKey("/somekey");

Create a directory

var dirResult = await client
                .CreateDirectory("/foo");

Create an expiring directory

var dirResult = await client
                .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

var disposable = client.Watch("/somekey")
                    .WithRecursive(true)
                    .Subscribe(x => { /* do the thing */ });

disposable.Dispose();

Atomic Key based operations

Update a key with an expected value

var result = await client
            .Atomic
            .CompareAndSwap("/atomickey")
            .WithExpectedValue("foo")
            .WithNewValue("bar");

Delete a key with an expected modified index

var result = await client
            .Atomic
            .CompareAndDelete("/atomickey")
            .WithExpectedIndex(33);

Cluster based operations

Get cluster members

var members = await client
                .Cluster
                .GetMembers();

Get cluster leader

var leader = await client
                .Cluster
                .GetLeader();

Add a cluster member

var memberInfo = await client
                .Cluster
                .CreateMember()
                .WithPeerUri(
					new Uri("http://localhost:4002"), 
					new Uri("http://localhost:5002")
				);

Remove a cluster member

await client
    .Cluster
    .DeleteMember()
    .WithMemberId(memberInfo.Id);

draft's People

Contributors

codybatt avatar jordansjones avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.