This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void geoadd(String objectId, BigDecimal latitude, BigDecimal longitude) { | |
log.info("geoadd(): {} {} {}", objectId, latitude, longitude); | |
try (Jedis jedis = jedisPool.getResource()) { | |
if (geoaddSha == null) { | |
String script = "return redis.call('geoadd','" + GEOSET + "', ARGV[1], ARGV[2], KEYS[1])"; | |
geoaddSha = jedis.scriptLoad(script); | |
} | |
log.info("geoaddSha: {}", geoaddSha); | |
log.info(jedis.evalsha(geoaddSha, 1, objectId, latitude.toString(), longitude.toString()).toString()); | |
} | |
} | |
@SuppressWarnings("unchecked") | |
public List<String> georadius(BigDecimal latitude, BigDecimal longitude, int radius, Unit unit) { | |
log.info("georadius(): {} {} {} {}", latitude, longitude, radius, unit); | |
try (Jedis jedis = jedisPool.getResource()) { | |
if (georadiusSha == null) { | |
String script = "return redis.call('georadius','" + GEOSET + "', ARGV[1], ARGV[2], ARGV[3], ARGV[4])"; | |
georadiusSha = jedis.scriptLoad(script); | |
} | |
log.info("georadiusSha: {}", georadiusSha); | |
List<String> objectIdList = (List<String>) jedis.evalsha(georadiusSha, 0, latitude.toString(), longitude.toString(), String.valueOf(radius), unit.toString()); | |
log.info("objectIdList: {}", objectIdList); | |
return objectIdList; | |
} | |
} | |
public void remove(String objectId) { | |
log.info("remove(): {}", objectId); | |
try (Jedis jedis = jedisPool.getResource()) { | |
jedis.zrem(GEOSET, objectId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment