public async Task <IExistsResult> ExistsAsync(string id, ExistsOptions options)
        {
            using (var existsOp = new Observe
            {
                Key = id,
                Cid = Cid
            })
            {
                try
                {
                    await ExecuteOp(existsOp, options.Token, options.Timeout);

                    var value = existsOp.GetValue();
                    return(new ExistsResult
                    {
                        Exists = existsOp.Success && value.KeyState != KeyState.NotFound &&
                                 value.KeyState != KeyState.LogicalDeleted,
                        Cas = value.Cas,
                        Expiration = TimeSpan.FromMilliseconds(existsOp.Expires)
                    });
                }
                catch (KeyNotFoundException)
                {
                    return(new ExistsResult
                    {
                        Exists = false
                    });
                }
            }
        }
Пример #2
0
        public Task <IExistsResult> Exists(string id, Action <ExistsOptions> optionsAction)
        {
            var options = new ExistsOptions();

            optionsAction(options);

            return(Exists(id, options));
        }
Пример #3
0
        public Task <IExistsResult> Exists(string id, Action <ExistsOptions> configureOptions)
        {
            var options = new ExistsOptions();

            configureOptions?.Invoke(options);

            return(Exists(id, options));
        }
Пример #4
0
        public static Task <IExistsResult> ExistsAsync(this ICollection collection, string id,
                                                       Action <ExistsOptions> configureOptions)
        {
            var options = new ExistsOptions();

            configureOptions?.Invoke(options);

            return(collection.ExistsAsync(id, options));
        }
Пример #5
0
        public Task <IExistsResult> Exists(string id, TimeSpan?timeout = null, CancellationToken token = default(CancellationToken))
        {
            var options = new ExistsOptions
            {
                Timeout = timeout,
                Token   = token
            };

            return(Exists(id, options));
        }