判斷一個(gè)坐標(biāo)周邊相近的坐標(biāo):
- 在redisson的使用:
double latitude = 32.668206, longitude = -97.248256;
RGeo<String> geo = redisson.getGeo("key");
Map<String, Double> result = geo.radiusWithDistance(longitude,latitude,10, GeoUnit.METERS);
- 在spring-data-redis中的使用:
Circle circle = new Circle(new Point(116.397128, 39.916527), new Distance(10, Metrics.MILES));
GeoResults<RedisGeoCommands.GeoLocation<String>> geoResults = redisTemplate.opsForGeo().radius("key",circle);
- 在jedis中的使用:
try(Jedis jedis = jedisPool.getResource()) {
List<GeoRadiusResponse> list = jedis.georadius("key", longitude , latitude , 10, GeoUnit.M);
}
使用redisson的時(shí)候,會(huì)遇到如下的問(wèn)題,修改版本號(hào)3.8.0解決(版本超過(guò)3.8.0默認(rèn)使用的read only模式查詢眼坏,低版本redis不支持)。
org.redisson.client.RedisException: ERR unknown command 'GEORADIUS_RO'. channel: [id: 0xadbfd179, L:/127.0.0.1:52191 - R:/127.0.0.1:6379] command: (GEORADIUS_RO), params: [geo-expedia-US, -97.248256, 32.668206, 10.0, m, WITHDIST]
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:343)
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:178)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:117)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:102)
maven對(duì)應(yīng)的依賴:
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>2.14.0</version>
</dependency>