Exemple #1
0
        private async Task <QueryResult <KVPair[]> > Query(
            string prefix,
            CancellationToken cancellationToken,
            QueryOptions?queryOptions = null)
        {
            using var consul = ConsulBuilder.Build();
            var result =
                await consul.KV.List(prefix, queryOptions, cancellationToken).ConfigureAwait(false);

            switch (result.StatusCode)
            {
            case HttpStatusCode.OK:
            case HttpStatusCode.NotFound:
                return(result);

            default:
                throw new BadConsulQueryException <QueryResult <KVPair[]> >(result, prefix,
                                                                            queryOptions == null
                            ? null
                            : new Dictionary <string, object> {
                    { "QueryOptions", queryOptions }
                });
            }
        }
Exemple #2
0
 public async Task <WriteResult <bool> > Set(string key, string value, CancellationToken?cancellationToken)
 {
     using var consul = ConsulBuilder.Build();
     return(await consul.KV.Put(new KVPair(key) { Value = Encoding.UTF8.GetBytes(value) },
                                cancellationToken ?? CancellationToken.None));
 }