我正在使用Spring Data Redis保存一些地址,每个都包含类型为location
的Point
属性,该属性保存特定地址的地理坐标。同样,该属性用@GeoIndexed
注释。就像这里描述的一样:Geospatial Index。
我的Address
模型看起来像这样:
@RedisHash("addresses")
public class Address {
@Id
private String id;
@GeoIndexed
private Point location;
}
通过此存储库查询,我能够将所有附近的地址获取到给定的点和距离:
public interface AddressRepository extends CrudRepository<Address, String> {
List<Address> findByLocationNear(Point location, Distance distance);
}
我的问题是上述查询返回的地址未排序,但我需要将它们从最近到最远排序(此处描述的ASC
选项:GEORADIUS - Redis Command)。
因此,通常,我需要一种方法来将其他参数传递给该查询,例如对结果进行排序或限制(GEORADIUS - Redis Command的任何选项。
有人可以帮忙吗?
RedisGeoCommands.GeoRadiusCommandArgs.limit(n)
,并且可以将结果数量限制为前n个匹配项。在这里查看Spring Data Redis的官方文档:
您也可以直接在Spring Data Redis测试中找到一些示例。