Example #1
0
        protected override IMemcachedRequest CreateRequest()
        {
            var builder = new BinaryRequestBuilder(allocator, 0)
            {
                Operation = OpCode.Stat
            };

            try
            {
                if (!String.IsNullOrEmpty(type))
                {
                    using var data = allocator.Rent(type.Length);
                    var span  = data.Memory.Span;
                    var count = Encoding.ASCII.GetBytes(type.AsSpan(), span);

                    builder.SetKeyRaw(span.Take(count));
                }

                builder.Commit();
            }
            catch
            {
                builder.Dispose();
                throw;
            }

            return(builder);
        }
        protected BinaryItemOperation(MemoryPool <byte> allocator, string key, IKeyFormatter keyFormatter, byte extraLength = 0)
        {
            Allocator = allocator;

            try
            {
                Request = new BinaryRequestBuilder(allocator, extraLength);
                Key     = Request.SetKey(keyFormatter, key);
            }
            catch
            {
                Request?.Dispose();
                throw;
            }
        }
Example #3
0
        /*
         *      Request:
         *
         *      MAY have extras.
         *      MUST NOT have key.
         *      MUST NOT have value.
         *      Extra data for flush:
         *
         *               Byte/     0       |       1       |       2       |       3       |
         *                      /              |               |               |               |
         |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
         +---------------+---------------+---------------+---------------+
         *                0| Expiration                                                    |
         +---------------+---------------+---------------+---------------+
         *               Total 4 bytes
         *
         */
        protected override IMemcachedRequest CreateRequest()
        {
            const byte NoExtra  = 0;
            const byte HasExtra = 4;

            var builder = new BinaryRequestBuilder(allocator, When.IsNever ? NoExtra : HasExtra)
            {
                Operation = OpCode.Flush
            };

            if (!When.IsNever)
            {
                BinaryPrimitives.WriteUInt32BigEndian(builder.GetExtraBuffer(), When.Value);
            }

            builder.Commit();

            return(builder);
        }