Beispiel #1
0
        public static RedisResult <RedisGeoPosition[]> ToGeoPosition(RedisArray array)
        {
            if (array == null)
            {
                return(new RedisResult <RedisGeoPosition[]>(new RedisGeoPosition[0]));
            }

            var items = array.Value;

            if (items == null)
            {
                return(new RedisResult <RedisGeoPosition[]>(new RedisGeoPosition[0]));
            }

            var count = items.Count;

            var result = new RedisGeoPosition[count];

            if (count > 0)
            {
                for (var i = 0; i < count; i++)
                {
                    result[i] = ToGeoPositionItem((RedisArray)items[i]);
                }
            }

            return(new RedisResult <RedisGeoPosition[]>(result));
        }
        public RedisResult <RedisGeoRadiusResult[]> GeoRadius(RedisParam key, RedisGeoPosition position, double radius,
                                                              RedisGeoDistanceUnit unit, bool withCoord = false, bool withDist = false, bool withHash   = false,
                                                              int count = -1, RedisSortDirection sort = RedisSortDirection.Default, RedisParam?storeKey = null,
                                                              RedisParam?storeDistanceKey = null)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            var parameters = key
                             .Join(position.Longitude.ToBytes())
                             .Join(position.Latitude.ToBytes())
                             .Join(radius.ToBytes())
                             .Join(ToBytes(unit));

            if (withCoord)
            {
                parameters = parameters.Join(RedisCommandList.WithCoord);
            }

            if (withDist)
            {
                parameters = parameters.Join(RedisCommandList.WithDist);
            }

            if (withHash)
            {
                parameters = parameters.Join(RedisCommandList.WithHash);
            }

            if (count > -1)
            {
                parameters = parameters.Join(RedisCommandList.Count).Join(count.ToBytes());
            }

            if (sort == RedisSortDirection.Ascending)
            {
                parameters = parameters.Join(RedisCommandList.Ascending);
            }
            else if (sort == RedisSortDirection.Descending)
            {
                parameters = parameters.Join(RedisCommandList.Descending);
            }

            if (storeKey.HasValue && !storeKey.Value.IsEmpty)
            {
                parameters = parameters.Join(RedisCommandList.Store).Join(storeKey.ToBytes());
            }

            if (storeDistanceKey.HasValue && !storeDistanceKey.Value.IsEmpty)
            {
                parameters = parameters.Join(RedisCommandList.StoreDist).Join(storeDistanceKey.ToBytes());
            }

            return(RedisCommandUtils.ToGeoRadiusArray(ExpectArray(new RedisCommand(DbIndex, RedisCommandList.GeoRadius, parameters))));
        }