Ejemplo n.º 1
0
        public override void Execute(IMemcachedProvider cacheProvider)
        {
            if (this._errorMessage != null)
            {
                return;
            }

            if (_casUnique > 0)
            {
                _result = cacheProvider.CheckAndSet(_key, _flags, _expirationTimeInSeconds, _casUnique, _dataBlock);
            }
            else
            {
                switch (this.Opcode)
                {
                case Opcode.Set:
                case Opcode.SetQ:
                    _result = cacheProvider.Set(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                    break;

                case Opcode.Add:
                case Opcode.AddQ:
                    _result = cacheProvider.Add(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                    break;

                case Opcode.Replace:
                case Opcode.ReplaceQ:
                    _result = cacheProvider.Replace(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                    break;

                case Opcode.Append:
                case Opcode.AppendQ:
                    _result = cacheProvider.Append(_key, (byte[])_dataBlock, _casUnique);
                    break;

                case Opcode.Prepend:
                case Opcode.PrependQ:
                    _result = cacheProvider.Prepend(_key, (byte[])_dataBlock, _casUnique);
                    break;

                case Opcode.CAS:
                    _result = cacheProvider.CheckAndSet(_key, _flags, _expirationTimeInSeconds, _casUnique, _dataBlock);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        //Private common store method.
        private string store(string command, string key, bool keyIsChecked, object value, uint hash, int expiry, ulong unique)
        {
            if (!keyIsChecked)
            {
                checkKey(key);
            }
            SerializedType type;

            byte[] bytes;
            try
            {
                bytes = Serializer.Serialize(value, out type, CompressionThreshold);
            }
            catch (Exception e)
            {
                //If serialization fails, return false;

                logger.Error("Error serializing object for key '" + key + "'.", e);
                return("");
            }
            string commandResult = "";

            if (memcachedProvider == null)
            {
                ConnectionError();
                return("");
            }
            OperationResult opResult = new OperationResult();

            try
            {
                switch (command)
                {
                case "set":
                    opResult = memcachedProvider.Set(key, (ushort)type, expiry, bytes);
                    break;

                case "add":
                    opResult = memcachedProvider.Add(key, (ushort)type, expiry, bytes);
                    break;

                case "replace":
                    opResult = memcachedProvider.Replace(key, (ushort)type, expiry, bytes);
                    break;

                case "append":
                    opResult = memcachedProvider.Append(key, bytes, unique);
                    break;

                case "prepend":
                    opResult = memcachedProvider.Prepend(key, bytes, unique);
                    break;

                case "cas":
                    opResult = memcachedProvider.CheckAndSet(key, (ushort)type, expiry, unique, bytes);
                    break;
                }
                if (command.Equals("replace") && opResult.ReturnResult == Result.ITEM_NOT_FOUND)
                {
                    commandResult = "NOT_STORED";
                }
                else
                {
                    switch (opResult.ReturnResult)
                    {
                    case Result.SUCCESS:
                        commandResult = "STORED";
                        break;

                    case Result.ITEM_EXISTS:
                        commandResult = "NOT_STORED";
                        break;

                    case Result.ITEM_NOT_FOUND:
                        commandResult = "NOT_FOUND";
                        break;

                    case Result.ITEM_MODIFIED:
                        commandResult = "EXISTS";
                        break;
                    }
                }
            }
            catch (InvalidArgumentsException e)
            {
                commandResult = "CLIENT_ERROR bad command line format";
            }
            catch (CacheRuntimeException e)
            {
                commandResult = "SERVER_ERROR";
            }
            return(commandResult);
        }
Ejemplo n.º 3
0
        public override void Execute(IMemcachedProvider cacheProvider)
        {
            if (this._errorMessage != null)
                return;

            if (_casUnique > 0)
                _result = cacheProvider.CheckAndSet(_key, _flags, _expirationTimeInSeconds, _casUnique, _dataBlock);
            else
                switch (this.Opcode)
                {
                    case Opcode.Set:
                    case Opcode.SetQ:
                        _result = cacheProvider.Set(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                        break;
                    case Opcode.Add:
                    case Opcode.AddQ:
                        _result = cacheProvider.Add(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                        break;
                    case Opcode.Replace:
                    case Opcode.ReplaceQ:
                        _result = cacheProvider.Replace(_key, _flags, _expirationTimeInSeconds, _dataBlock);
                        break;
                    case Opcode.Append:
                    case Opcode.AppendQ:
                        _result = cacheProvider.Append(_key, (byte[])_dataBlock, _casUnique);
                        break;
                    case Opcode.Prepend:
                    case Opcode.PrependQ:
                        _result = cacheProvider.Prepend(_key, (byte[])_dataBlock, _casUnique);
                        break;
                    case Opcode.CAS:
                        _result = cacheProvider.CheckAndSet(_key, _flags, _expirationTimeInSeconds, _casUnique, _dataBlock);
                        break;
                }
        }