主要方法:
add : 添加一个地理位置
distance: 计算两个元素之间的距离
hash: 获取元素经纬度坐标经过geohash算法生成的base32编码值
position: 获取集合中任意元素的经纬度坐标,可以一次获取多个
radius:查询某个坐标或某个成员,附近范围的成员
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.*;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class Controller_redis_geo_1 {
@Autowired
private RedisTemplate redisTemplate;
private final String KEY_GEO = "home";
@RequestMapping("/testGeo")
public void testGeo() {
// geoadd : 添加一个地理位置
// geoadd : (纬度、经度、名称)三元组
redisTemplate.opsForGeo().add(KEY_GEO, new Point(11