@Override public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) { List<Object> params = new ArrayList<Object>(memberCoordinateMap.size()*3 + 1); params.add(key); for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) { params.add(entry.getValue().getX()); params.add(entry.getValue().getY()); params.add(entry.getKey()); } return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray()); }
@Override public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) { List<Object> params = new ArrayList<Object>(memberCoordinateMap.size()*3 + 1); params.add(key); for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) { params.add(entry.getValue().getX()); params.add(entry.getValue().getY()); params.add(entry.getKey()); } return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray()); }
@Override public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) { List<Object> params = new ArrayList<Object>(); params.add(key); for (GeoLocation<byte[]> location : locations) { params.add(location.getPoint().getX()); params.add(location.getPoint().getY()); params.add(location.getName()); } return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray()); }
@Override public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) { List<Object> params = new ArrayList<Object>(); params.add(key); for (GeoLocation<byte[]> location : locations) { params.add(location.getPoint().getX()); params.add(location.getPoint().getY()); params.add(location.getName()); } return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray()); }
@Override public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(memberCoordinateMap, "MemberCoordinateMap must not be null!"); List<Object> values = new ArrayList<>(); for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) { values.add(entry.getValue().getX()); values.add(entry.getValue().getY()); values.add(entry.getKey()); } return geoAdd(key, values); }
@Override public Long geoAdd(byte[] key, Point point, byte[] member) { return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, key, point.getX(), point.getY(), member); }
@Override public Long geoAdd(byte[] key, Point point, byte[] member) { return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, key, point.getX(), point.getY(), member); }
/** * 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 Document convert(Point source) { return source == null ? null : new Document("x", source.getX()).append("y", source.getY()); } }
/** * build a GeoPoint from a {@link org.springframework.data.geo.Point} * * @param point {@link org.springframework.data.geo.Point} * @return a {@link org.springframework.data.elasticsearch.core.geo.GeoPoint} */ public static GeoPoint fromPoint(Point point) { return new GeoPoint(point.getX(), point.getY()); }
@Override public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(locations, "Locations must not be null!"); List<Object> values = new ArrayList<>(); for (GeoLocation<byte[]> location : locations) { values.add(location.getPoint().getX()); values.add(location.getPoint().getY()); values.add(location.getName()); } return geoAdd(key, values); }
/** * Convert {@link Point} into {@link GeoCoordinate}. * * @param source * @return * @since 1.8 */ public static GeoCoordinate toGeoCoordinate(Point source) { return source == null ? null : new redis.clients.jedis.GeoCoordinate(source.getX(), source.getY()); }
@Override public Long geoAdd(byte[] key, Point point, byte[] member) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(point, "Point must not be null!"); Assert.notNull(member, "Member must not be null!"); try { return connection.getCluster().geoadd(key, point.getX(), point.getY(), member); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long geoAdd(byte[] key, GeoLocation<byte[]> location) { return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, key, location.getPoint().getX(), location.getPoint().getY(), location.getName()); }
@Override public Long geoAdd(byte[] key, GeoLocation<byte[]> location) { return write(key, StringCodec.INSTANCE, RedisCommands.GEOADD, key, location.getPoint().getX(), location.getPoint().getY(), location.getName()); }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(within.getRadius().getMetric())); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { List<Object> params = new ArrayList<Object>(); params.add(key); params.add(convert(within.getCenter().getX())); params.add(convert(within.getCenter().getY())); params.add(within.getRadius().getValue()); params.add(within.getRadius().getMetric().getAbbreviation()); RedisCommand<GeoResults<GeoLocation<byte[]>>> command; if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) { command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder); params.add("WITHCOORD"); } else { MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(within.getRadius().getMetric())); command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder); params.add("WITHDIST"); } if (args.getLimit() != null) { params.add("COUNT"); params.add(args.getLimit()); } if (args.getSortDirection() != null) { params.add(args.getSortDirection().name()); } return read(key, ByteArrayCodec.INSTANCE, command, params.toArray()); }
@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); } }
@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) { 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()); }