Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples about how to use all etcd operations #22

Open
viing937 opened this issue Jun 18, 2019 · 7 comments
Open

Add examples about how to use all etcd operations #22

viing937 opened this issue Jun 18, 2019 · 7 comments
Labels
Documentation good first issue Good for newcomers help wanted Extra attention is needed up-for-grabs
Projects

Comments

@viing937
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I want to use ETCD's ttl, and I noticed that there are some lease methods (LeaseGrant and so on) exposed from client, but I can't figure out how to use them.

Describe the solution you'd like
Add some usage examples in README.md.

Thank you for your creating the great client again.

@viing937
Copy link
Contributor Author

I found how to set a key with ttl.

EtcdClient client = new EtcdClient("127.0.0.1", 2379);

long leaseId = client.LeaseGrant(new LeaseGrantRequest
{
    TTL = ttl
}).ID;

client.Put(new PutRequest
{
    Key = ByteString.CopyFromUtf8(key),
    Value = ByteString.CopyFromUtf8(val),
    Lease = leaseId
});

And this can keep lease alive, but I am not sure what are LeaseKeepAliveHandler and CancellationToken used for.

client.LeaseKeepAlive(new LeaseKeepAliveRequest
{
    ID = leaseId
}, LeaseKeepAliveHandler, new CancellationToken());

private static void LeaseKeepAliveHandler(LeaseKeepAliveResponse rep)
{
    Console.WriteLine($"Lease {rep.ID} keep alive");
}

@shubhamranjan
Copy link
Owner

shubhamranjan commented Jun 21, 2019

LeaseKeepAliveHandler : The method which contains instructions to be executed on each LeaseKeepAlive response.

CancellationToken: Propagates notification that operations should be canceled.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken?view=netframework-4.8

@shubhamranjan
Copy link
Owner

I am working on restructuring the lib's code a bit without hurting method signatures. I will try to update documentation as soon as I can.

@viing937
Copy link
Contributor Author

viing937 commented Jun 21, 2019

Actually I do not need to execute anything on LeaseKeepAlive response, an overload of LeaseKeepAlive without LeaseKeepAliveHandler should be better.
Also, CancellationToken should be optional as the same reason.

@shubhamranjan
Copy link
Owner

shubhamranjan commented Jun 21, 2019

Noted. For now, you can use the overload which takes an array of Handlers and you can pass an empty array.

@shubhamranjan shubhamranjan added this to To Do in dotnet-etcd via automation Jun 30, 2019
@spiderpoison
Copy link

I need Doc about Lease too, thanks very much

@shubhamranjan shubhamranjan moved this from To Do to In Progress in dotnet-etcd Sep 7, 2019
@shubhamranjan shubhamranjan added good first issue Good for newcomers help wanted Extra attention is needed up-for-grabs labels Nov 8, 2019
@shubhamranjan shubhamranjan changed the title Add examples about how to use lease operations Add examples about how to use all etcd operations Apr 7, 2020
@shubhamranjan shubhamranjan changed the title Add examples about how to use all etcd operations [Documentation] Add examples about how to use all etcd operations Apr 7, 2020
@shubhamranjan shubhamranjan changed the title [Documentation] Add examples about how to use all etcd operations Add examples about how to use all etcd operations Apr 7, 2020
@anythink-wx
Copy link

LeaseGrant and LeaseKeepAlive doc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation good first issue Good for newcomers help wanted Extra attention is needed up-for-grabs
Projects
dotnet-etcd
  
In Progress
Development

No branches or pull requests

4 participants