protected internal override IOperationResult ReadResponse(IPooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);
            var result = new TextOperationResult();

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
                return result.Fail("Failed to read response.  Item not found");

            result.Success =
                UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
            return result;
        }
예제 #2
0
		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			GetResponse r = GetHelper.ReadItem(socket);
			var result = new TextOperationResult();

			if (r == null) return result.Fail("Failed to read response");

			this.result = r.Item;
			this.Cas = r.CasValue;

			GetHelper.FinishCurrent(socket);

			return result.Pass();
		}
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);
            var    result   = new TextOperationResult();

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
            {
                return(result.Fail("Failed to read response.  Item not found"));
            }

            result.Success = UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
            return(result);
        }
        protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default(CancellationToken))
        {
            string response = await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false);

            var result = new TextOperationResult();

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
            {
                return(result.Fail("Failed to read response.  Item not found"));
            }

            result.Success = UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
            return(result);
        }
예제 #5
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            GetResponse r      = GetHelper.ReadItem(socket);
            var         result = new TextOperationResult();

            if (r == null)
            {
                return(result.Fail("Failed to read response"));
            }

            this.result = r.Item;
            this.Cas    = r.CasValue;

            GetHelper.FinishCurrent(socket);

            return(result.Pass());
        }
예제 #6
0
        protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = await GetHelper.ReadItemAsync(socket, cancellationToken).ConfigureAwait(false);

            var result = new TextOperationResult();

            if (response == null)
            {
                return(result.Fail("Failed to read response"));
            }

            this.result = response.Item;
            this.Cas    = response.CasValue;

            await GetHelper.FinishCurrentAsync(socket, cancellationToken).ConfigureAwait(false);

            return(result.Pass());
        }
예제 #7
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            this.result = new Dictionary <string, CacheItem>();
            this.Cas    = new Dictionary <string, ulong>();
            var result = new TextOperationResult();

            var response = new BinaryResponse();

            while (response.Read(socket))
            {
                this.StatusCode = response.StatusCode;

                // found the noop, quit
                if (response.CorrelationId == this.noopId)
                {
                    return(result.Pass());
                }

                string key;

                // find the key to the response
                if (!this.idToKey.TryGetValue(response.CorrelationId, out key))
                {
                    // we're not supposed to get here tho
                    log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", response.CorrelationId);
                    continue;
                }

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Reading item {0}", key);
                }

                // deserialize the response
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);

                this.result[key] = new CacheItem((ushort)flags, response.Data);
                this.Cas[key]    = response.CAS;
            }

            // finished reading but we did not find the NOOP
            return(result.Fail("Found response with CorrelationId {0}, but no key is matching it."));
        }
예제 #8
0
		protected internal override IOperationResult ReadResponse(PooledSocket socket)
		{
			this.result = new Dictionary<string, CacheItem>();
			this.Cas = new Dictionary<string, ulong>();
			var result = new TextOperationResult();

			var response = new BinaryResponse();

			while (response.Read(socket))
			{
				this.StatusCode = response.StatusCode;

				// found the noop, quit
				if (response.CorrelationId == this.noopId)
					return result.Pass();

				string key;

				// find the key to the response
				if (!this.idToKey.TryGetValue(response.CorrelationId, out key))
				{
					// we're not supposed to get here tho
					log.WarnFormat("Found response with CorrelationId {0}, but no key is matching it.", response.CorrelationId);
					continue;
				}

				if (log.IsDebugEnabled) log.DebugFormat("Reading item {0}", key);

				// deserialize the response
				int flags = BinaryConverter.DecodeInt32(response.Extra, 0);

				this.result[key] = new CacheItem((ushort)flags, response.Data);
				this.Cas[key] = response.CAS;
			}

			// finished reading but we did not find the NOOP
			return result.Fail("Found response with CorrelationId {0}, but no key is matching it.");
		}