Java Code Examples for org.springframework.data.redis.connection.RedisGeoCommands#GeoLocation

The following examples show how to use org.springframework.data.redis.connection.RedisGeoCommands#GeoLocation . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRadiusWithCoords() {
    connection.geoAdd("key1".getBytes(), new Point(13.361389, 38.115556), "value1".getBytes());
    connection.geoAdd("key1".getBytes(), new Point(15.087269, 37.502669), "value2".getBytes());

    GeoResults<RedisGeoCommands.GeoLocation<byte[]>> l = connection.geoRadius("key1".getBytes(),
            new Circle(new Point(15, 37), new Distance(200, RedisGeoCommands.DistanceUnit.KILOMETERS)),
            RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates());

    assertThat(l.getContent()).hasSize(2);
    assertThat(l.getContent().get(0).getContent().getName()).isEqualTo("value1".getBytes());
    assertThat(l.getContent().get(0).getContent().getPoint().toString()).isEqualTo(new Point(13.361389, 38.115556).toString());
    assertThat(l.getContent().get(1).getContent().getName()).isEqualTo("value2".getBytes());
    assertThat(l.getContent().get(1).getContent().getPoint().toString()).isEqualTo(new Point(15.087267, 37.502668).toString());

    GeoResults<RedisGeoCommands.GeoLocation<byte[]>> l2 = connection.geoRadius("key1".getBytes(),
            new Circle(new Point(15, 37), new Distance(200, RedisGeoCommands.DistanceUnit.KILOMETERS)),
            RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs());

    assertThat(l2.getContent()).hasSize(2);
    assertThat(l2.getContent().get(0).getContent().getName()).isEqualTo("value1".getBytes());
    assertThat(l2.getContent().get(1).getContent().getName()).isEqualTo("value2".getBytes());

}
 
Example 2
Source File: RedissonConnectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadius() {
    connection.geoAdd("key1".getBytes(), new Point(13.361389, 38.115556), "value1".getBytes());
    connection.geoAdd("key1".getBytes(), new Point(15.087269, 37.502669), "value2".getBytes());

    GeoResults<RedisGeoCommands.GeoLocation<byte[]>> l = connection.geoRadius("key1".getBytes(), new Circle(new Point(15, 37), new Distance(200, RedisGeoCommands.DistanceUnit.KILOMETERS)));
    assertThat(l.getContent()).hasSize(2);
    assertThat(l.getContent().get(0).getContent().getName()).isEqualTo("value1".getBytes());
    assertThat(l.getContent().get(1).getContent().getName()).isEqualTo("value2".getBytes());
}
 
Example 3
Source File: TaxiController.java    From Spring-Boot-2.0-Projects with MIT License 4 votes vote down vote up
@GetMapping
public Flux<TaxiAvailableResponseDTO> getAvailableTaxis(@RequestParam("type") TaxiType taxiType, @RequestParam("latitude") Double latitude, @RequestParam("longitude") Double longitude, @RequestParam(value = "radius", defaultValue = "1") Double radius) {
    Flux<GeoResult<RedisGeoCommands.GeoLocation<String>>> availableTaxisFlux = taxiService.getAvailableTaxis(taxiType, latitude, longitude, radius);
    return availableTaxisFlux.map(r -> new TaxiAvailableResponseDTO(r.getContent().getName()));
}
 
Example 4
Source File: TaxiService.java    From Spring-Boot-2.0-Projects with MIT License 4 votes vote down vote up
public Flux<GeoResult<RedisGeoCommands.GeoLocation<String>>> getAvailableTaxis(TaxiType taxiType, Double latitude, Double longitude, Double radius) {
    return reactiveRedisTemplate.opsForGeo().radius(taxiType.toString(), new Circle(new Point(longitude, latitude), new Distance(radius, Metrics.KILOMETERS)));
}
 
Example 5
Source File: TaxiBookingService.java    From Spring-Boot-2.0-Projects with MIT License 4 votes vote down vote up
public Flux<GeoResult<RedisGeoCommands.GeoLocation<String>>> getBookings(TaxiType taxiType, Double latitude, Double longitude, Double radius) {
    return reactiveRedisTemplate.opsForGeo().radius(getTaxiTypeBookings(taxiType), new Circle(new Point(longitude, latitude), new Distance(radius, Metrics.KILOMETERS)));
}