public IActionResult Index(string key) { EtcdClient client = new EtcdClient("etcd", 2379); Etcdserverpb.RangeResponse response; if (key == null) { response = client.Get("/foo/foo"); } else { response = client.Get(key); } try { RepeatedField <Mvccpb.KeyValue> kvs = response.Kvs; IEnumerator <Mvccpb.KeyValue> enumerator = kvs.GetEnumerator(); enumerator.MoveNext(); string value = enumerator.Current.Value.ToStringUtf8(); ViewData["Message"] = "etcd says: " + value; }catch (Exception e) { ViewData["Message"] = e.ToString(); } IHttpConnectionFeature feature = HttpContext.Features.Get <IHttpConnectionFeature>(); ViewData["IP"] = feature.LocalIpAddress.ToString(); ViewData["Config"] = _configuration["somewhere"]; client.Put("visited", feature.LocalIpAddress.ToString()); return(View()); }
public static void GetOne() { Console.WriteLine("\n\n"); var dbConnectionString = _client.Get("/appconfig/internportalen/dbConnectionString").Node.Value; Console.ForegroundColor = ConsoleColor.DarkGreen;; Console.WriteLine(dbConnectionString); Console.ResetColor(); }
public async Task ShouldReturnOneItem() { var resp = Enumerable.Range(0, 11).Select(async x => await etcdClient.Put("test" + x, "value" + x)); await Task.WhenAll(resp); var res1 = await etcdClient.Get("test3"); var res2 = await etcdClient.Get("test10"); Assert.AreEqual("value3", res1); Assert.AreEqual("value10", res2); }
public void TestEtcdSimpleSetAndAdd() { if (!CheckEtcdRunning()) { Assert.Ignore(); return; } var respSet = etcd.Set("csharp-etcetera-test", "123"); Assert.AreEqual(respSet.Node.Value, "123"); var respGet = etcd.Get("csharp-etcetera-test"); Assert.AreEqual(respGet.Node.Value, "123"); }
public CanReadQueueKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _etcdClient.Queue(_id.ToString(), "wassup1"); _etcdClient.Queue(_id.ToString(), "wassup2"); _response = _etcdClient.Get(_id.ToString(), sorted:true); }
public async Task ShouldExtendLease() { var leaseId = await etcdClient.PutWithLease("test", "value", 1); await Task.Delay(1100); await etcdClient.KeepAliveLease(leaseId); await Task.Delay(1100); await etcdClient.KeepAliveLease(leaseId); await Task.Delay(1100); var res = await etcdClient.Get("test"); Assert.AreEqual("value", res); }
public bool TryGet(string key, out string?value) { var resp = client.Get(key); if (resp.Count == 0) { value = default; return(false); } value = resp.Kvs.First().Value.ToStringUtf8().Trim(); return(true); }
/// <summary> /// etcd get to async /// </summary> /// <param name="key"></param> /// <param name="recursive">是否递归获取子节点</param> /// <returns></returns> public Task <EtcdResponse> GetAsync(string key, bool recursive = true) { TaskCompletionSource <EtcdResponse> tcs = new TaskCompletionSource <EtcdResponse>(); Task.Factory.StartNew(() => { tcs.SetResult(_etcdClient.Get(key, recursive)); }); return(tcs.Task); }
private ModelVersion getModelVersion() { var response = client.Get(MODEL_VERSION); if (response.Kvs.Count > 0 && response.Kvs[0].Value != null) { var json = response.Kvs[0].Value.ToStringUtf8(); return(deserialize <ModelVersion>(json).Match(v => v, exception => DEFAULT_MODEL_VERSION)); } return(DEFAULT_MODEL_VERSION); }
private string retrieveValue(string key, string etcdEndpoint, int etcdPort) { EtcdClient client = new EtcdClient(etcdEndpoint, etcdPort); Etcdserverpb.RangeResponse response; response = client.Get(key); RepeatedField <Mvccpb.KeyValue> kvs = response.Kvs; IEnumerator <Mvccpb.KeyValue> enumerator = kvs.GetEnumerator(); enumerator.MoveNext(); //We only get the first string value = enumerator.Current.Value.ToStringUtf8(); return(value); }
static void Main(string[] args) { Console.WriteLine("开始分库计算"); int i = 1; //var db = (9527 % 20); //while (true) //{ // if (i == 0) continue; // if ((9527 % i) == db) // { // Console.WriteLine("数据库(" + i + "):" + (9527 % i)); // } // i++; // //if (i % 10 == 0) // //{ // // Console.WriteLine("按任意键继续"); // // Console.ReadLine(); // //} //} //var db = (9527 / 20) % 1; //while (true) //{ // var s = (9527 / 20) % i; // if (s==db) // { // Console.WriteLine("数据库(" + i + "):" + s); // } // i++; // //if (i % 10 == 0) // //{ // // Console.WriteLine("按任意键继续"); // // Console.ReadLine(); // //} //} //dic.Add("1",new List<string> { "a"}); //dic.Add("2", new List<string> { "b" }); //List<string> list = dic["1"]; //Console.WriteLine(list[0]); //dic["1"][0] = "C"; //Console.WriteLine(list[0]); //dic["1"][0] = "C"; //Console.WriteLine(list[0]); //dic["1"][0] = "K"; //Console.WriteLine(list[0]); //Console.WriteLine("除数:" + (9527 / 10)); //Console.WriteLine("数据库:" + (9527 / 10) % 8 + 1); //Console.WriteLine("表编号:" + (9527 % 10)); //Console.WriteLine("数据库:" + (((9527 / 10) % 16 + 1) -1)% 2 +1); //Console.WriteLine("表编号:" + (9527 % 80)); //int isTaked = 0; //if (Interlocked.Exchange(ref isTaked, 1) != 0) //{ // Console.Write("cc"); //}; //Interlocked.Exchange(ref isTaked, 0); EtcdClient etcdClient = new EtcdClient(new Uri("http://127.0.0.1:2379")); var s = etcdClient.Get("/111ddd").Result; Console.WriteLine(s); var sk = etcdClient.GetRange("/111").Result; var k = etcdClient.Put("/conf/order/99999", "999").Result; var b = etcdClient.Put("/conf/order/redis:add", "66666").Result; var etcdw = etcdClient.WatchRange("/111").Result; etcdw.Subscribe(x => { Console.WriteLine("触发啦"); }); //etcdClient.Put("/111", "999"); //etcdClient.Put("/111", "444"); //etcdClient.Put("/111", "333"); Console.Read(); }
public RangeResponse Get(string key) { var rsp = client.Get(key); return(rsp.FromProto()); }
public CanGetKeys() { _etcdClient = new EtcdClient(new Uri("http://192.168.101.1:4001/")); _response = _etcdClient.Set(_key.ToString(), "wassup"); _getResponse = _etcdClient.Get(_key.ToString()); }