Beispiel #1
0
        public async Task <Either <RiakException, RiakCounterResult> > GetCounter(string bucket, string counter, RiakCounterGetOptions 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 RpbCounterGetReq {
                bucket = bucket.ToRiakString(), key = counter.ToRiakString()
            };

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

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

                var  riakObject = new RiakObject(bucket, counter, result.returnvalue);
                long cVal;
                var  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));
            }
        }
Beispiel #2
0
        /// <summary>
        /// get counter
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="key"></param>
        /// <param name="setOptions"></param>
        /// <param name="millisecondsReceiveTimeout"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        public Task <long?> GetCounter(string bucket,
                                       byte[] key,
                                       Action <CounterGetOptions> setOptions = null,
                                       int millisecondsReceiveTimeout        = 3000,
                                       object asyncState = null)
        {
            var source = new TaskCompletionSource <long?>(asyncState);
            var req    = new RpbCounterGetReq {
                bucket = bucket.GetBytes(), key = key
            };

            if (setOptions != null)
            {
                setOptions(new CounterGetOptions(req));
            }

            this._socket.Execute <RpbCounterGetReq, RpbCounterGetResp>(Codes.CounterGetReq, Codes.CounterGetResp, req,
                                                                       ex => source.TrySetException(ex),
                                                                       response =>
            {
                if (response == null)
                {
                    source.TrySetResult(null);
                }
                else
                {
                    source.TrySetResult(response.returnvalue);
                }
            }, millisecondsReceiveTimeout);
            return(source.Task);
        }
Beispiel #3
0
        internal void Populate(RpbCounterGetReq request)
        {
            if (R != null)
            {
                request.r = R;
            }

            if (Pr != null)
            {
                request.pr = Pr;
            }

            if (BasicQuorum.HasValue)
            {
                request.basic_quorum = BasicQuorum.Value;
            }

            if (NotFoundOk.HasValue)
            {
                request.notfound_ok = NotFoundOk.Value;
            }
        }