@Override public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member, "Member must not be null!"); Assert.notNull(radius, "Radius must not be null!"); GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric()); try { return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric()) .convert(connection.getCluster().georadiusByMember(key, member, radius.getValue(), geoUnit)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
/** * Sets the maximum distance supplied in a given metric. Will normalize the distance but not reconfigure the query's * result {@link Metric} if one was configured before. * * @param maxDistance * @param metric must not be {@literal null}. * @return */ public NearQuery maxDistance(double maxDistance, Metric metric) { Assert.notNull(metric, "Metric must not be null!"); return maxDistance(new Distance(maxDistance, metric)); }
@Override public Document convert(Circle source) { if (source == null) { return null; } Document result = new Document(); result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter())); result.put("radius", source.getRadius().getNormalizedValue()); result.put("metric", source.getRadius().getMetric().toString()); return result; } }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder()); return read(key, ByteArrayCodec.INSTANCE, command, key, convert(within.getCenter().getX()), convert(within.getCenter().getY()), within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation()); }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(within, "Within must not be null!"); try { return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric()) .convert(connection.getCluster().georadius(key, within.getCenter().getX(), within.getCenter().getY(), within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric()))); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
/** * Creates a Sphere around the given center {@link Point} with the given radius. * * @param center must not be {@literal null}. * @param radius must not be {@literal null}. */ @PersistenceConstructor public Sphere(Point center, Distance radius) { Assert.notNull(center, "Center point must not be null!"); Assert.notNull(radius, "Radius must not be null!"); Assert.isTrue(radius.getValue() >= 0, "Radius must not be negative!"); this.center = center; this.radius = radius; }
/** * Adds the given distance to the current one. The resulting {@link Distance} will be in the same metric as the * current one. * * @param other must not be {@literal null}. * @return */ public Distance add(Distance other) { Assert.notNull(other, "Distance to add must not be null!"); double newNormalizedValue = getNormalizedValue() + other.getNormalizedValue(); return new Distance(newNormalizedValue * metric.getMultiplier(), metric); }
@Override public Circle convert(Document source) { if (source == null) { return null; } Document center = (Document) source.get("center"); Number radius = (Number) source.get("radius"); Assert.notNull(center, "Center must not be null!"); Assert.notNull(radius, "Radius must not be null!"); Distance distance = new Distance(toPrimitiveDoubleValue(radius)); if (source.containsKey("metric")) { String metricString = (String) source.get("metric"); Assert.notNull(metricString, "Metric must not be null!"); distance = distance.in(Metrics.valueOf(metricString)); } return new Circle(DocumentToPointConverter.INSTANCE.convert(center), distance); } }
/** * Sets the maximum distance to the given {@link Distance}. Will set the returned {@link Metric} to be the one of the * given {@link Distance} if {@link Metric} was {@link Metrics#NEUTRAL} before. * * @param distance must not be {@literal null}. * @return */ public NearQuery maxDistance(Distance distance) { Assert.notNull(distance, "Distance must not be null!"); if (distance.getMetric() != Metrics.NEUTRAL) { this.spherical(true); } if (ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, this.metric)) { in(distance.getMetric()); } this.maxDistance = distance; return this; }
@Override public Sphere convert(Document source) { if (source == null) { return null; } Document center = (Document) source.get("center"); Number radius = (Number) source.get("radius"); Assert.notNull(center, "Center must not be null!"); Assert.notNull(radius, "Radius must not be null!"); Distance distance = new Distance(toPrimitiveDoubleValue(radius)); if (source.containsKey("metric")) { String metricString = (String) source.get("metric"); Assert.notNull(metricString, "Metric must not be null!"); distance = distance.in(Metrics.valueOf(metricString)); } return new Sphere(DocumentToPointConverter.INSTANCE.convert(center), distance); } }
@Override public Flux<CommandResponse<GeoRadiusCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadius( Publisher<GeoRadiusCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getPoint(), "Point must not be null!"); Assert.notNull(command.getDistance(), "Distance must not be null!"); GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get()) : new GeoArgs(); Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd .georadius(command.getKey(), command.getPoint().getX(), command.getPoint().getY(), command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs) // .map(converter(command.getDistance().getMetric())::convert); return Mono.just(new CommandResponse<>(command, result)); })); }
@Override public Flux<CommandResponse<GeoRadiusByMemberCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadiusByMember( Publisher<GeoRadiusByMemberCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getMember(), "Member must not be null!"); Assert.notNull(command.getDistance(), "Distance must not be null!"); GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get()) : new GeoArgs(); Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd .georadiusbymember(command.getKey(), command.getMember(), command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs) .map(converter(command.getDistance().getMetric())::convert); return Mono.just(new CommandResponse<>(command, result)); })); }
@Override public GeoResult<GeoLocation<byte[]>> convert(redis.clients.jedis.GeoRadiusResponse source) { Point point = GEO_COORDINATE_TO_POINT_CONVERTER.convert(source.getCoordinate()); return new GeoResult<>(new GeoLocation<>(source.getMember(), point), new Distance(source.getDistance(), metric)); } }
document.put("maxDistance", maxDistance.getNormalizedValue()); document.put("minDistance", minDistance.getNormalizedValue()); document.put("near", Arrays.asList(point.getX(), point.getY()));
/** * Returns the {@link Shape} as a list of usually {@link Double} or {@link List}s of {@link Double}s. Wildcard bound * to allow implementations to return a more concrete element type. * * @return */ public List<? extends Object> asList() { return Arrays.asList(Arrays.asList(center.getX(), center.getY()), this.radius.getValue()); }
@Override public Distance convert(Object obj) { return new Distance((Double)obj, metric); }
point = ((Circle) o).getCenter(); distance = ((Circle) o).getRadius(); } else if (o instanceof Point) { distance = (Distance) distObject; } else if (distObject instanceof Number) { distance = new Distance(((Number) distObject).doubleValue(), Metrics.KILOMETERS); } else { throw new InvalidDataAccessApiUsageException(String
argument.add(toList(((Circle) shape).getCenter())); argument.add(((Circle) shape).getRadius().getNormalizedValue()); argument.add(toList(((Circle) shape).getCenter())); argument.add(((Circle) shape).getRadius()); argument.add(((Sphere) shape).getRadius().getNormalizedValue());