コード例 #1
0
        byte[] NumberToBytes(long value)
        {
            byte[] bytes;
            if (!this.messagePool.TryGetBytes(value, out bytes))
            {
                bytes = RedisCodecUtil.LongToAsciiBytes(value);
            }

            return(bytes);
        }
コード例 #2
0
        FixedRedisMessagePool()
        {
            var stringToSimpleStringValues     = new Dictionary <string, SimpleStringRedisMessage>();
            var byteBufferToSimpleStringValues = new Dictionary <IByteBuffer, SimpleStringRedisMessage>();

            foreach (string simpleString in SimpleStrings)
            {
                IByteBuffer key = Unpooled
                                  .WrappedBuffer(Encoding.UTF8.GetBytes(simpleString))
                                  .Unreleasable();

                var redisMessage = new SimpleStringRedisMessage(simpleString);
                stringToSimpleStringValues.Add(simpleString, redisMessage);
                byteBufferToSimpleStringValues.Add(key, redisMessage);
            }
            this.stringToSimpleStringMessages     = new ReadOnlyDictionary <string, SimpleStringRedisMessage>(stringToSimpleStringValues);
            this.byteBufferToSimpleStringMessages = new ReadOnlyDictionary <IByteBuffer, SimpleStringRedisMessage>(byteBufferToSimpleStringValues);

            var errorToErrorValues      = new Dictionary <string, ErrorRedisMessage>();
            var byteBufferToErrorValues = new Dictionary <IByteBuffer, ErrorRedisMessage>();

            foreach (string error in Errors)
            {
                IByteBuffer key = Unpooled
                                  .WrappedBuffer(Encoding.UTF8.GetBytes(error))
                                  .Unreleasable();

                var redisMessage = new ErrorRedisMessage(error);
                errorToErrorValues.Add(error, redisMessage);
                byteBufferToErrorValues.Add(key, redisMessage);
            }
            this.stringToErrorMessages     = new ReadOnlyDictionary <string, ErrorRedisMessage>(errorToErrorValues);
            this.byteBufferToErrorMessages = new ReadOnlyDictionary <IByteBuffer, ErrorRedisMessage>(byteBufferToErrorValues);

            var longToIntegerValues       = new Dictionary <long, IntegerRedisMessage>();
            var longToByteBufferValues    = new Dictionary <long, byte[]>();
            var byteBufferToIntegerValues = new Dictionary <IByteBuffer, IntegerRedisMessage>();

            for (long value = MinimumCachedIntegerNumber; value < MaximumCachedIntegerNumber; value++)
            {
                byte[]      bytes = RedisCodecUtil.LongToAsciiBytes(value);
                IByteBuffer key   = Unpooled
                                    .WrappedBuffer(bytes)
                                    .Unreleasable();

                var redisMessage = new IntegerRedisMessage(value);
                longToIntegerValues.Add(value, redisMessage);
                longToByteBufferValues.Add(value, bytes);
                byteBufferToIntegerValues.Add(key, redisMessage);
            }

            this.longToIntegerMessages       = new ReadOnlyDictionary <long, IntegerRedisMessage>(longToIntegerValues);
            this.longToBytes                 = new ReadOnlyDictionary <long, byte[]>(longToByteBufferValues);
            this.byteBufferToIntegerMessages = new ReadOnlyDictionary <IByteBuffer, IntegerRedisMessage>(byteBufferToIntegerValues);
        }
コード例 #3
0
        static void ReadEndOfLine(IByteBuffer input)
        {
            short delim = input.ReadShort();

            if (RedisConstants.EndOfLineShort == delim)
            {
                return;
            }
            byte[] bytes = RedisCodecUtil.ShortToBytes(delim);
            throw new RedisCodecException($"delimiter: [{bytes[0]},{bytes[1]}] (expected: \\r\\n)");
        }
コード例 #4
0
        static void ReadEndOfLine(IByteBuffer byteBuffer)
        {
            Contract.Requires(byteBuffer != null);

            short delim = byteBuffer.ReadShort();

            if (RedisConstants.EndOfLine == delim)
            {
                return;
            }

            byte[] bytes = RedisCodecUtil.GetBytes(delim);
            throw new RedisCodecException($"delimiter: [{bytes[0]},{bytes[1]}] (expected: \\r\\n)");
        }
コード例 #5
0
        bool DecodeType(IByteBuffer byteBuffer)
        {
            Contract.Requires(byteBuffer != null);

            if (!byteBuffer.IsReadable())
            {
                return(false);
            }

            RedisMessageType redisMessageType = RedisCodecUtil.ParseMessageType(byteBuffer.ReadByte());

            this.state = IsInline(redisMessageType)
                ? State.DecodeInline
                : State.DecodeLength;
            this.messageType = redisMessageType;

            return(true);
        }
コード例 #6
0
        FixedRedisMessagePool()
        {
            this.byteBufToSimpleStrings = new Dictionary <IByteBuffer, SimpleStringRedisMessage>(DefaultSimpleStrings.Length);
            this.stringToSimpleStrings  = new Dictionary <string, SimpleStringRedisMessage>(DefaultSimpleStrings.Length);

            foreach (string simpleString in DefaultSimpleStrings)
            {
                IByteBuffer key = Unpooled.UnreleasableBuffer(
                    Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(simpleString)));

                var cached = new SimpleStringRedisMessage(simpleString);
                this.byteBufToSimpleStrings.Add(key, cached);
                this.stringToSimpleStrings.Add(simpleString, cached);
            }

            this.byteBufToErrors = new Dictionary <IByteBuffer, ErrorRedisMessage>(DefaultErrors.Length);
            this.stringToErrors  = new Dictionary <string, ErrorRedisMessage>(DefaultErrors.Length);
            foreach (string error in DefaultErrors)
            {
                IByteBuffer key = Unpooled.UnreleasableBuffer(
                    Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(error)));

                var cached = new ErrorRedisMessage(error);
                this.byteBufToErrors.Add(key, cached);
                this.stringToErrors.Add(error, cached);
            }

            this.byteBufToIntegers = new Dictionary <IByteBuffer, IntegerRedisMessage>();
            this.longToIntegers    = new Dictionary <long, IntegerRedisMessage>(SizeCachedIntegerNumber);
            this.longToByteBufs    = new Dictionary <long, byte[]>(SizeCachedIntegerNumber);

            for (long value = MinimumCachedIntegerNumber; value < MaximumCachedIntegerNumber; value++)
            {
                byte[]      keyBytes   = RedisCodecUtil.LongToAsciiBytes(value);
                IByteBuffer keyByteBuf = Unpooled.UnreleasableBuffer(
                    Unpooled.WrappedBuffer(keyBytes));

                var cached = new IntegerRedisMessage(value);
                this.byteBufToIntegers.Add(keyByteBuf, cached);
                this.longToIntegers.Add(value, cached);
                this.longToByteBufs.Add(value, keyBytes);
            }
        }