/// <summary> /// Deletes all keys with the specified prefix /// </summary> /// <param name="prefixKey">Commin prefix of all keys that need to be deleted</param> public DeleteRangeResponse DeleteRange(string prefixKey, Metadata headers = null) { string rangeEnd = EtcdUtil.GetRangeEnd(prefixKey); return(Delete(new DeleteRangeRequest { Key = ByteString.CopyFromUtf8(prefixKey), RangeEnd = ByteString.CopyFromUtf8(rangeEnd) }, headers)); }
/// <summary> /// Deletes all keys with the specified prefix in async /// </summary> /// <param name="prefixKey">Commin prefix of all keys that need to be deleted</param> public async Task <DeleteRangeResponse> DeleteRangeAsync(string prefixKey, Metadata headers = null) { string rangeEnd = EtcdUtil.GetRangeEnd(prefixKey); return(await DeleteAsync(new DeleteRangeRequest { Key = ByteString.CopyFromUtf8(prefixKey), RangeEnd = ByteString.CopyFromUtf8(rangeEnd) }, headers)); }
/// <summary> /// Gets the range of keys with the specified prefix in async /// </summary> /// <returns>Dictionary containing range of key-values</returns> /// <param name="prefixKey">Prefix key</param> public async Task <IDictionary <string, string> > GetRangeValAsync(string prefixKey, Metadata headers = null) { string rangeEnd = EtcdUtil.GetRangeEnd(prefixKey); var request = new RangeRequest { Key = ByteString.CopyFromUtf8(prefixKey), RangeEnd = ByteString.CopyFromUtf8(rangeEnd) }; var rangeResponse = await GetAsync(request, headers); return(EtcdUtil.RangeRespondToDictionary(rangeResponse)); }
/// <summary> /// Gets the range of keys with the specified prefix in async /// </summary> /// <returns>RangeResponse containing range of key-values</returns> /// <param name="prefixKey">Prefix key</param> public async Task <RangeResponse> GetRangeAsync(string prefixKey, Metadata headers = null) { string rangeEnd = EtcdUtil.GetRangeEnd(prefixKey); var request = new RangeRequest { Key = ByteString.CopyFromUtf8(prefixKey), RangeEnd = ByteString.CopyFromUtf8(rangeEnd) }; var rangeResponse = await GetAsync(request, headers); return(rangeResponse); }
/// <summary> /// Gets the range of keys with the specified prefix /// </summary> /// <returns>RangeResponse containing range of key-values</returns> /// <param name="prefixKey">Prefix key</param> public RangeResponse GetRange(string prefixKey, Metadata headers = null) { string rangeEnd = EtcdUtil.GetRangeEnd(prefixKey); var request = new RangeRequest { Key = ByteString.CopyFromUtf8(prefixKey), RangeEnd = ByteString.CopyFromUtf8(rangeEnd) }; var rangeResponse = Get(request, headers); return(rangeResponse); }
/// <summary> /// Watch指定的范围,并将响应传递给提供的方法。 /// </summary> /// <param name="path">watch的范围</param> /// <param name="method">处理watch响应的方法</param> public void WatchRange(string path, Action <WatchResponse> method, CancellationToken cancellationToken, Metadata headers = null, Action <Exception> exceptionHandler = null) { WatchRequest request = new WatchRequest() { CreateRequest = new WatchCreateRequest() { Key = ByteString.CopyFromUtf8(path), RangeEnd = ByteString.CopyFromUtf8(EtcdUtil.GetRangeEnd(path)) } }; Task.Factory.StartNew(() => WatchAsync(request, method, headers, exceptionHandler), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
/// <summary> /// Watch指定的范围,并将响应传递给提供的方法。 /// </summary> /// <param name="paths">watch的范围集合</param> /// <param name="methods">处理watch响应的方法集合</param> /// <param name="cancellationToken">中止线程token</param> /// <param name="exceptionHandler">异常处理委托方法</param> public void WatchRange(string[] paths, Action <WatchEvent[]>[] methods, CancellationToken cancellationToken, Metadata headers = null, Action <Exception> exceptionHandler = null) { List <WatchRequest> requests = new List <WatchRequest>(); foreach (string path in paths) { WatchRequest request = new WatchRequest() { CreateRequest = new WatchCreateRequest() { Key = ByteString.CopyFromUtf8(path), RangeEnd = ByteString.CopyFromUtf8(EtcdUtil.GetRangeEnd(path)) } }; requests.Add(request); } Watch(requests.ToArray(), methods, headers, exceptionHandler); }