Exemplo n.º 1
0
        public static KeyValuePair <RequestHeader, IEnumerable <byte[]> > InterlockedRequest(Command command, string key, long inter, int expireTime)
        {
            var keyValue = Encoding.ASCII.GetBytes(key);
            var extra    = new byte[20];

            Buffer.BlockCopy(BitConverter.GetBytes(inter), 0, extra, 0, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(0L), 0, extra, 8, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(expireTime), 0, extra, 16, 4);
            var request = new RequestHeader()
            {
                Magic       = Magic.Request,
                OpCode      = command,
                KeyLength   = (ushort)keyValue.Length,
                ExtraLength = (byte)extra.Length,
                DataType    = 0,
                VbucketId   = 0,
                TotalBody   = extra.Length + keyValue.Length,
                Opaque      = 0,
                CAS         = 0,
            };

            var @reqs = request.ToByte();

            RequestReverse(reqs);
            var @enumerable = new[] { @reqs, extra, keyValue };

            return(new KeyValuePair <RequestHeader, IEnumerable <byte[]> >(request, @enumerable));
        }
Exemplo n.º 2
0
        public static unsafe KeyValuePair <RequestHeader, IEnumerable <byte[]> > AddRequest(Command command, string key, byte[] body, byte flag, int expireTime)
        {
            var keyValue = Encoding.ASCII.GetBytes(key);
            var extra    = new byte[8];

            Buffer.BlockCopy(BitConverter.GetBytes((uint)flag), 0, extra, 0, 4);
            Buffer.BlockCopy(BitConverter.GetBytes((uint)expireTime), 0, extra, 4, 4);
            var request = new RequestHeader()
            {
                Magic       = Magic.Request,
                OpCode      = command,
                KeyLength   = (ushort)keyValue.Length,
                ExtraLength = (byte)extra.Length,
                DataType    = 0,
                VbucketId   = 0,
                TotalBody   = extra.Length + keyValue.Length + body.Length,
                Opaque      = 0,
                CAS         = 0,
            };

            var @reqs = request.ToByte();

            RequestReverse(reqs);
            var @enumerable = new[] { @reqs, extra, keyValue, body }.ToArray();

            return(new KeyValuePair <RequestHeader, IEnumerable <byte[]> >(request, @enumerable));
        }
Exemplo n.º 3
0
        public static KeyValuePair <RequestHeader, IEnumerable <byte[]> > DeleteRequest(string key)
        {
            var keyValue = Encoding.ASCII.GetBytes(key);
            var request  = new RequestHeader()
            {
                OpCode      = Command.delete,
                DataType    = 0,
                Magic       = Magic.Request,
                ExtraLength = 0,
                KeyLength   = (ushort)keyValue.Length,
                TotalBody   = keyValue.Length
            };

            var @enumerable = new[] { request.ToByte(), keyValue };

            return(new KeyValuePair <RequestHeader, IEnumerable <byte[]> >(request, @enumerable));
        }
Exemplo n.º 4
0
        public static KeyValuePair <RequestHeader, IEnumerable <byte[]> > GetRequest(string key)
        {
            var keyValue = Encoding.ASCII.GetBytes(key);
            var request  = new RequestHeader()
            {
                Magic       = Magic.Request,
                OpCode      = Command.get,
                KeyLength   = (ushort)keyValue.Length,
                ExtraLength = 0,
                DataType    = 0,
                VbucketId   = 0,
                TotalBody   = keyValue.Length,
                Opaque      = 0,
                CAS         = 0,
            };

            var @reqs = request.ToByte();

            RequestReverse(reqs);
            var @enumerable = new[] { @reqs, keyValue };

            return(new KeyValuePair <RequestHeader, IEnumerable <byte[]> >(request, @enumerable));
        }