Exemple #1
0
 public Task <RiakCounterResult> IncrementCounter(string bucket, string counter, long amount, RiakCounterUpdateOptions options = null)
 {
     return(Task.Factory.StartNew(() => _client.IncrementCounter(bucket, counter, amount, options)));
 }
Exemple #2
0
        public async Task <Either <RiakException, RiakCounterResult> > IncrementCounter(string bucket, string counter, long amount, RiakCounterUpdateOptions options = null)
        {
            if (!IsValidBucketOrKey(bucket))
            {
                return(new Either <RiakException, RiakCounterResult>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)));
            }

            if (!IsValidBucketOrKey(counter))
            {
                return(new Either <RiakException, RiakCounterResult>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)));
            }

            var request = new RpbCounterUpdateReq {
                bucket = bucket.ToRiakString(), key = counter.ToRiakString(), amount = amount
            };

            options = options ?? new RiakCounterUpdateOptions();
            options.Populate(request);

            try
            {
                var result = await _connection.PbcWriteRead <RpbCounterUpdateReq, RpbCounterUpdateResp>(_endPoint, request)
                             .ConfigureAwait(false);

                var riakObject  = new RiakObject(bucket, counter, result.returnvalue);
                var cVal        = 0L;
                var parseResult = false;

                if (options.ReturnValue != null && options.ReturnValue.Value)
                {
                    parseResult = long.TryParse(riakObject.Value.FromRiakString(), out cVal);
                }

                return(new Either <RiakException, RiakCounterResult>(new RiakCounterResult(riakObject, parseResult ? (long?)cVal : null)));
            }
            catch (RiakException riakException)
            {
                return(new Either <RiakException, RiakCounterResult>(riakException));
            }
        }
Exemple #3
0
        /// <summary>
        /// Increments a Riak counter.
        /// </summary>
        /// <param name="bucket">The bucket</param>
        /// <param name="counter">The name of the counter</param>
        /// <param name="amount">The amount to increment/decrement the counter</param>
        /// <param name="options">The <see cref="RiakCounterUpdateOptions"/></param>
        /// <returns><see cref="RiakCounterResult"/></returns>
        /// <remarks>Only available in Riak 1.4+. If the counter is not initialized, then the counter will be initialized to 0 and then incremented.</remarks>
        public RiakCounterResult IncrementCounter(string bucket, string counter, long amount, RiakCounterUpdateOptions options = null)
        {
            var result = Async.IncrementCounter(bucket, counter, amount, options).ConfigureAwait(false).GetAwaiter().GetResult();

            if (result.IsLeft)
            {
                throw result.Left;
            }

            return(result.Right);
        }