How to get all Geo records associated with a key? I am able to push data into Redis and retrieve based on [lon,lat,buffer] using
jedis.georadius(key, lon,lat, radius, GeoUnit.KM,GeoRadiusParam.geoRadiusParam().withCoord());
Is there any way to get all records using the key alone? Following is the code i have used to pull records from redis using geobuffer.
public Map<String, Object> getFromRedis(String key, Double lat, Double lon, Integer radii, Integer resultCount, boolean hasType, String typekey) {
Map<String, Object> result = new HashMap<>();
ArrayList<Map<String,Object>> geoObj= new ArrayList<>();
boolean gotresult = false;
try(Jedis jedis=new Jedis("localhost",6379);)
{
GeoRadiusParam param = GeoRadiusParam.geoRadiusParam();
param.sortAscending();
param.withDist();
param.count(resultCount);
List<GeoRadiusResponse> response;
response = jedis.georadius(key,lat,lon, radii, GeoUnit.M, param);//redis zset key, lon,lat,radii,..
if(response.size() > 0)
{
for (GeoRadiusResponse geoRadiusResponse : response) {
Map<String, Object> resultObj = new HashMap<>();
Object[] data= {geoRadiusResponse.getMemberByString()};
LOGGER.info("Got Result from Redis Server :: "+data);
gotresult = true;
for(Object o : data)
{
JSONObject jObject = new JSONObject(o.toString());
Iterator<?> keys = jObject.keys();
while( keys.hasNext() ){
String keyObj = (String)keys.next();
String value = jObject.getString(keyObj);
resultObj.put(keyObj, value);
}
LOGGER.info("Fetched Value : "+resultObj);
geoObj.add(resultObj);
}
}
result.put("result", geoObj);
}
else {
LOGGER.info("Unable to find matching result in Redis server");
}
} catch (Exception e) {
LOGGER.error("Redis Fetch result failed");
LOGGER.error("Error : "+e);
}
result.put("status", gotresult);
return result;
}
While to push i am using
jedis.geoadd(key, lon, lat, String);
Trying to Get all records to retieve from key(apicache) alone
Geo data is stored into the key as a sorted set. Therefore u can use jedis.zrange
for getting all the points but the retruned value is in geo format.
To get all the records with coordinates just give the entire earth value as follow in jedis.georadius
.,
lat = 0
lon = 0
radii = 22000
param = withCoord
It will return all records with co-ordinates. However, you can't order the locations by using this.