public LeaseGrantResponse LeaseGrant(LeaseGrantRequest request) { var req = request.ToProto(); var rsp = client.LeaseGrant(req); return(rsp.FromProto()); }
static void Main(string[] args) { var etcdClient = new EtcdClient("http://localhost:2379"); etcdClient.DeleteRange("/foo"); //Console.WriteLine(etcdClient.GetVal("/foo")); //Console.WriteLine(etcdClient.Get("foo").Kvs.FirstOrDefault().Value.ToStringUtf8()); etcdClient.Put($"/foo/{Guid.NewGuid()}", Guid.NewGuid().ToString()); etcdClient.Put(new PutRequest { Key = ByteString.CopyFromUtf8("/time"), Value = ByteString.CopyFromUtf8(Guid.NewGuid().ToString()), Lease = etcdClient.LeaseGrant(new LeaseGrantRequest { TTL = 20 }).ID }); var response = etcdClient.GetRange("/"); foreach (var keyValue in response.Kvs) { Console.WriteLine($"{keyValue.Key.ToStringUtf8()}:{keyValue.Value.ToStringUtf8()}"); } Console.ReadKey(); }
private static async Task <(bool, LeaseGrantResponse lease)> LeaderElection(EtcdClient client, string me) { bool result; var lease = client.LeaseGrant(new LeaseGrantRequest { TTL = LeaseTtl }); try { result = await AddLeader(client, LeaderKey, me, lease); } catch (Exception e) { Console.WriteLine(e); return(false, lease); } return(result, lease); }