Esempio n. 1
0
        protected override BinaryRequest Build()
        {
            OpCode op;

            switch (this.mode)
            {
            case StoreMode.Add: op = OpCode.Add; break;

            case StoreMode.Set: op = OpCode.Set; break;

            case StoreMode.Replace: op = OpCode.Replace; break;

            default: throw new ArgumentOutOfRangeException("mode", mode + " is not supported");
            }

            var extra = new byte[8];

            BinaryConverter.EncodeUInt32((uint)this.value.Flags, extra, 0);
            BinaryConverter.EncodeUInt32(expires, extra, 4);

            var request = new BinaryRequest(op)
            {
                Key   = this.Key,
                Cas   = this.Cas,
                Extra = new ArraySegment <byte>(extra),
                Data  = this.value.Data
            };

            return(request);
        }
        protected override BinaryRequest Build(string key)
        {
            var request = new BinaryRequest(OpCode.GetQ)
            {
                Key = key
            };

            return(request);
        }
Esempio n. 3
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.SaslStep)
            {
                Key  = this.Provider.Type,
                Data = new ArraySegment <byte>(this.Provider.Continue(this.continuation))
            };

            return(request);
        }
Esempio n. 4
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Get)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            return(request);
        }
Esempio n. 5
0
        protected override BinaryRequest Build()
        {
            // create a Sasl Start command
            var request = new BinaryRequest(OpCode.SaslStart)
            {
                Key  = this.Provider.Type,
                Data = new ArraySegment <byte>(this.Provider.Authenticate())
            };

            return(request);
        }
Esempio n. 6
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest((OpCode)this.mode)
            {
                Key  = this.Key,
                Cas  = this.Cas,
                Data = this.data
            };

            return(request);
        }
Esempio n. 7
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Stat);

            if (!String.IsNullOrEmpty(this.type))
            {
                request.Key = this.type;
            }

            return(request);
        }
Esempio n. 8
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest((OpCode)this.mode)
            {
                Key = this.Key,
                Cas = this.Cas
            };

            this.UpdateExtra(request);

            return(request);
        }
Esempio n. 9
0
        protected unsafe void UpdateExtra(BinaryRequest request)
        {
            byte[] extra = new byte[20];

            fixed(byte *buffer = extra)
            {
                BinaryConverter.EncodeUInt64(this.delta, buffer, 0);

                BinaryConverter.EncodeUInt64(this.defaultValue, buffer, 8);
                BinaryConverter.EncodeUInt32(this.expires, buffer, 16);
            }

            request.Extra = new ArraySegment <byte>(extra);
        }
Esempio n. 10
0
        protected internal override IList <ArraySegment <byte> > GetBuffer()
        {
            var keys = this.Keys;

            if (keys == null || keys.Count == 0)
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("Empty multiget!");
                }

                return(new ArraySegment <byte> [0]);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Building multi-get for {0} keys", keys.Count);
            }

            // map the command's correlationId to the item key,
            // so we can use GetQ (which only returns the item data)
            this.idToKey = new Dictionary <int, string>();

            // get ops have 2 segments, header + key
            var buffers = new List <ArraySegment <byte> >(keys.Count * 2);

            foreach (var key in keys)
            {
                var request = this.Build(key);

                request.CreateBuffer(buffers);

                // we use this to map the responses to the keys
                idToKey[request.CorrelationId] = key;
            }

            // uncork the server
            var noop = new BinaryRequest(OpCode.NoOp);

            this.noopId = noop.CorrelationId;

            noop.CreateBuffer(buffers);

            return(buffers);
        }
Esempio n. 11
0
        protected override BinaryRequest Build()
        {
            var request = new BinaryRequest(OpCode.Flush);

            return(request);
        }