public static byte[] BuildCounterResponse(CounterCommand command)
        {
            byte[] value = null;
            BinaryResponseStatus status = BinaryResponseStatus.no_error;
            ulong cas = 0;

            if (command.ExceptionOccured)
                status = BinaryResponseStatus.item_not_stored;
            else
            {
                switch (command.OperationResult.ReturnResult)
                {
                    case Result.ITEM_TYPE_MISMATCHED:
                        status = BinaryResponseStatus.incr_decr_on_nonnumeric_value;
                        value = MemcachedEncoding.BinaryConverter.GetBytes("Increment or decrement on non-numeric value");
                        break;
                    case Result.ITEM_NOT_FOUND:
                        status = BinaryResponseStatus.key_not_found;
                        value = MemcachedEncoding.BinaryConverter.GetBytes("NOT_FOUND");
                        break;
                    case Result.SUCCESS:
                        if (command.NoReply == true)
                            return null;
                        cas = (ulong)command.OperationResult.Value;
                        ulong response = (command.OperationResult as MutateOpResult).MutateResult;
                        value = MemcachedEncoding.BinaryConverter.GetBytes(response);
                        break;
                    case Result.ITEM_MODIFIED:
                        status = BinaryResponseStatus.key_exists;
                        break;
                }
            }
            return BuildResposne(command.Opcode, status, command.Opaque, cas, null, value, null);
        }
 private void CreateCounterCommand(Opcode cmdType, bool noreply)
 {
     CounterCommand cmd = new CounterCommand(cmdType);
     cmd.Delta = MemcachedEncoding.BinaryConverter.ToUInt64(_rawData, 0);
     cmd.InitialValue = MemcachedEncoding.BinaryConverter.ToUInt64(_rawData, 8);
     cmd.ExpirationTimeInSeconds = (long)MemcachedEncoding.BinaryConverter.ToUInt32(_rawData, 16);
     cmd.Key = MemcachedEncoding.BinaryConverter.GetString(_rawData, 20, _requestHeader.KeyLength);
     cmd.CAS = _requestHeader.CAS;
     cmd.NoReply = noreply;
     _command = cmd;
 }
Example #3
0
        private void CreateCounterCommand(string arguments, Opcode cmdType)
        {
            string[] argumentsArray = arguments.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (argumentsArray.Length > 3 || argumentsArray.Length < 2)
            {
                CreateInvalidCommand();
                return;
            }

            CounterCommand command = new CounterCommand(cmdType);

            try
            {
                command.Key = argumentsArray[0];
                command.Delta = ulong.Parse(argumentsArray[1]);
                if (argumentsArray.Length > 2 && argumentsArray[2] == "noreply")
                    command.NoReply = true;
            }
            catch (Exception)
            {
                command.ErrorMessage = "CLIENT_ERROR bad command line format";
            }

            _command = command;
            this.State = ParserState.ReadyToDispatch;
        }