コード例 #1
0
ファイル: RedisBools.cs プロジェクト: bapti/csredis
 private static bool[] ParseStream(Stream s)
 {
     object[] response = RedisReader.ReadMultiBulk(s);
     bool[] bools = new bool[response.Length];
     for (int i = 0; i < response.Length; i++)
         bools[i] = (long)response[i] == 1;
     return bools;
 }
コード例 #2
0
            public override string Parse(RedisReader reader)
            {
                RedisMessage type = reader.ReadType();

                if (type == RedisMessage.Bulk)
                {
                    return(reader.ReadBulkString(false));
                }
                reader.ReadMultiBulk(false);
                return(null);
            }
コード例 #3
0
        private static string Read(Stream stream)
        {
            var type = RedisReader.ReadType(stream);

            if (type == RedisMessage.Bulk)
            {
                return(RedisReader.ReadBulkUTF8(stream, false));
            }
            RedisReader.ReadMultiBulk(stream, false);
            return(null);
        }
コード例 #4
0
ファイル: RedisHashes.cs プロジェクト: bapti/csredis
        private static Dictionary <string, string>[] ParseStream(Stream stream)
        {
            object[] response = RedisReader.ReadMultiBulk(stream);

            Dictionary <string, string>[] dicts = new Dictionary <string, string> [response.Length];
            for (int i = 0; i < response.Length; i++)
            {
                object[] hash = response[i] as object[];
                dicts[i] = HashMapper.ToDict(hash);
            }
            return(dicts);
        }
コード例 #5
0
        private static string ParseStream(Stream stream)
        {
            RedisMessage type = RedisReader.ReadType(stream);

            if (type == RedisMessage.Status)
            {
                return(RedisReader.ReadStatus(stream, false));
            }

            object[] result = RedisReader.ReadMultiBulk(stream, false);
            if (result != null)
            {
                throw new RedisProtocolException("Expecting null MULTI BULK response. Received: " + result.ToString());
            }
            return(null);
        }
コード例 #6
0
            public override string Parse(RedisReader reader)
            {
                RedisMessage type = reader.ReadType();

                if (type == RedisMessage.Status)
                {
                    return(reader.ReadStatus(false));
                }

                object[] result = reader.ReadMultiBulk(false);
                if (result != null)
                {
                    throw new RedisProtocolException("Expecting null MULTI BULK response. Received: " + result.ToString());
                }

                return(null);
            }
コード例 #7
0
            public override string Parse(RedisReader reader)
            {
                RedisMessage type = reader.ReadType();

                if (type == RedisMessage.Status)
                {
                    return(reader.ReadStatus(false));
                }

                object[] result = reader.ReadMultiBulk(false);
                if (result != null && result.Length > 0)
                {
                    throw new RedisProtocolException("Expecting null MULTI BULK response for command '" + this.Command + "'. Received: " + String.Join(", ", result));
                }

                return(null);
            }
コード例 #8
0
        static RedisScanPair ParseStream(Stream stream)
        {
            object[]      parts  = RedisReader.ReadMultiBulk(stream);
            object[]      values = parts[1] as object[];
            RedisScanPair result = new RedisScanPair
            {
                Cursor = ParseCursor(parts[0]),
                Items  = new Dictionary <string, object>(),
            };

            for (int i = 0; i < values.Length; i += 2)
            {
                result.Items[values[i] as String] = values[i + 1];
            }

            return(result);
        }
コード例 #9
0
ファイル: RedisArray.cs プロジェクト: wxlonstar/Fenix
        public override object[] Parse(RedisReader reader)
        {
            if (_parsers.Count == 0)
            {
                return(reader.ReadMultiBulk(bulkAsString: true));
            }

            reader.ExpectType(RedisMessage.MultiBulk);
            long count = reader.ReadInt(false);

            if (count != _parsers.Count)
            {
                throw new RedisProtocolException(String.Format("Expecting {0} array items; got {1}", _parsers.Count, count));
            }

            object[] results = new object[_parsers.Count];
            for (int i = 0; i < results.Length; i++)
            {
                results[i] = _parsers.Dequeue()(reader);
            }
            return(results);
        }
コード例 #10
0
        public override string Parse(RedisReader reader)
        {
            if (IsEmpty)
            {
                RedisMessage type = reader.ReadType();
                if ((int)type == -1)
                {
                    return(string.Empty);
                }
                else if (type == RedisMessage.Error)
                {
                    throw new RedisException(reader.ReadStatus(false));
                }

                throw new RedisProtocolException($"Unexpected type: {type}");
            }
            else if (IsNullable)
            {
                RedisMessage type = reader.ReadType();
                if (type == RedisMessage.Status)
                {
                    return(reader.ReadStatus(false));
                }

                object[] result = reader.ReadMultiBulk(false);
                if (result != null)
                {
                    throw new RedisProtocolException($"Expecting null MULTI BULK response. Received: {result.ToString()}");
                }

                return(null);
            }
            else
            {
                return(reader.ReadStatus());
            }
        }
コード例 #11
0
 public static RedisSubscriptionResponse ParseStream(Stream stream)
 {
     return(RedisSubscriptionResponse.ReadResponse(RedisReader.ReadMultiBulk(stream)));
 }