redis中geo的使用

判断一个坐标周边相近的坐标:

  • 在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的时候,会遇到如下的问题,修改版本号3.8.0解决(版本超过3.8.0默认使用的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对应的依赖:

<dependency>
      <groupId>org.redisson</groupId>
      <artifactId>redisson-spring-boot-starter</artifactId>
      <version>2.14.0</version>
</dependency>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。