ERR неизвестная команда 'GEOADD' от встраиваемого redis в Java-весне - PullRequest
0 голосов
/ 03 мая 2018

Я выполняю модульное тестирование в Java Spring Framework, где коду необходимо использовать операцию GEOADD для фильтрации местоположения, которое выровнено в пределах 25 километров от исходной точки.

Реализация работает нормально (соединяется с реальным узлом redis), но модульный тест (который соединяется с вложенным redis) показывает следующую ошибку

org.springframework.dao.InvalidDataAccessApiUsageException: ERR unknown command 'GEOADD'; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'GEOADD'

это мой пом

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/>
</parent>

...

<dependencies>

...

<dependency>
        <groupId>com.github.kstyrc</groupId>
        <artifactId>embedded-redis</artifactId>
        <version>0.6</version>
        <scope>test</scope>
    </dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
</dependencies>

Инициализировать вставленный redis в тесте junit

public class EmbeddedRedisServer {

    static RedisServer redisServer = null;

    static {
        try {
            redisServer = new RedisServer(6479);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static RedisServer redisServer() throws IOException {
        return redisServer;
    }

}

контрольный пример

@BeforeClass
public static void init() throws Exception {
    EmbeddedRedisServer.redisServer().start();
    System.setProperty("spring.cloud.bootstrap.enabled", "false");
}

@Test
public void testFindNearByPoint() {
    for (CurrentGeoLocation currentGeoLocation : getCurrentLocationList()) {
        currentGeoLocationService.createOrUpdate(currentGeoLocation);
    }
    List<CurrentGeoLocation> list = nearByDriverService.findNearByPoint(13.392900, 52.491560, null);
    Assert.assertThat(list, hasSize(2));
}

@AfterClass
public static void destroy() throws IOException {
    EmbeddedRedisServer.redisServer().stop();
}

Метод, который необходимо проверить

public List<CurrentGeoLocation> findNearByPoint(final Double longitude, final Double latitude,
                                                                                  final List<Long> driverIds) {
    redisTemplate.delete(GeoTrackingConstants.GEO_KEY);
    List<CurrentGeoLocation> geoLocationList = new ArrayList<>();
    final GeoOperations<String, CurrentGeoLocation> geoOpt = redisTemplate.opsForSet().getOperations().opsForGeo();
    List<CurrentGeoLocation> currentGeoLocations =(CollectionUtils.isEmpty(driverIds))? currentGeoLocationService.findAll()
                                                                      : currentGeoLocationService.findAll(driverIds);
    for (CurrentGeoLocation currentGeoLocation : currentGeoLocations) {
        Point point = new Point(currentGeoLocation.getLongitude(), currentGeoLocation.getLatitude());
        geoOpt.geoAdd(GeoTrackingConstants.GEO_KEY, point, currentGeoLocation);
    }
    Point originPoint = new Point(longitude, latitude);
    Circle circle = new Circle(originPoint, new Distance(radius, RedisGeoCommands.DistanceUnit.KILOMETERS));
    final GeoResults<RedisGeoCommands.GeoLocation<CurrentGeoLocation>> result =
            (CollectionUtils.isEmpty(driverIds))? geoOpt.geoRadius(GeoTrackingConstants.GEO_KEY, circle)
            :  geoOpt.geoRadius(GeoTrackingConstants.GEO_KEY, circle, RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().sortAscending());
    List<GeoResult<RedisGeoCommands.GeoLocation<CurrentGeoLocation>>> locations = result.getContent();
    for (GeoResult<RedisGeoCommands.GeoLocation<CurrentGeoLocation>> location : locations) {
        if (location.getContent().getName() != null) {
            geoLocationList.add(location.getContent().getName());
        }
    }
    return geoLocationList;
}

Есть предложения? Спасибо

1 Ответ

0 голосов
/ 08 июня 2018

Полагаю, возможно, из-за того, что ваша версия redis слишком мала, только redis 3.2 поддерживает гео-операции.

...