Ejemplo n.º 1
0
        public static HScanResponse ToHScanResponse(this ScanResponse source)
        {
            if (source == null)
            {
                return(null);
            }

            Dictionary <string, string> data = null;

            if (source.Data != null && source.Data.Count > 0)
            {
                data = new Dictionary <string, string>();

                for (int i = 0; i < source.Data.Count; i++)
                {
                    var key = source.Data[i];

                    if (!string.IsNullOrEmpty(key))
                    {
                        if (i + 1 <= source.Data.Count)
                        {
                            data.Add(key, source.Data[i + 1]);
                            i++;
                        }
                        else
                        {
                            data.Add(key, string.Empty);
                        }
                    }
                }
            }

            var result = new HScanResponse()
            {
                Offset = source.Offset,
                Data   = data
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static ZScanResponse ToZScanResponse(this ScanResponse source)
        {
            if (source == null)
            {
                return(null);
            }

            List <ZItem> data = null;

            if (source.Data != null && source.Data.Count > 0)
            {
                data = new List <ZItem>();

                for (int i = 0; i < source.Data.Count; i++)
                {
                    var zi = new ZItem();

                    zi.Value = source.Data[i];

                    var score = 0D;

                    if (i + 1 < source.Data.Count)
                    {
                        double.TryParse(source.Data[i + 1], out score);
                        i++;
                    }
                    zi.Score = score;

                    data.Add(zi);
                }
            }

            var result = new ZScanResponse()
            {
                Offset = source.Offset,
                Data   = data
            };

            return(result);
        }
Ejemplo n.º 3
0
        public static ScanResponse ToScanResponse(this ResponseData source)
        {
            var scanResponse = new ScanResponse();

            var dataArr = source.Data.Split(_enter, StringSplitOptions.None);

            var doffset = 0;

            int.TryParse(dataArr[0].Split(":", StringSplitOptions.RemoveEmptyEntries)[1], out doffset);

            scanResponse.Offset = doffset;

            List<string> datas = new List<string>();

            for (int i = 1; i < dataArr.Length; i++)
            {
                if (i + 1 == dataArr.Length) break;
                datas.Add(dataArr[i]);
            }
            scanResponse.Data = datas;
            return scanResponse;
        }
Ejemplo n.º 4
0
        public static ScanResponse ToScanResponse <T>(this ResponseData <T> source)
        {
            if (source == null)
            {
                return(null);
            }

            if (source.Type == ResponseType.Error)
            {
                throw new Exception(source.Data);
            }

            var scanResponse = new ScanResponse();

            var dataArr = source.Data.Split(RedisCoder.SEPARATOR);

            var doffset = 0;

            int.TryParse(dataArr[0].Split(":", StringSplitOptions.RemoveEmptyEntries)[1], out doffset);

            scanResponse.Offset = doffset;

            List <string> datas = new List <string>();

            for (int i = 1; i < dataArr.Length; i++)
            {
                if (string.IsNullOrEmpty(dataArr[i]))
                {
                    continue;
                }

                datas.Add(dataArr[i]?.TrimEnd('\r', '\n'));
            }
            scanResponse.Data = datas;
            return(scanResponse);
        }