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
2
Answers
Was able to get all the values by key(stored value as json string with lat long mapped so with each return from zrange return value without geometry was able to get lat lon too
But as Praga_t said this will just get the value the idea is to map lat lon and store as a json so that by key also we can get the latlong with it.(Thanks @Praga_t)
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
.,It will return all records with co-ordinates. However, you can’t order the locations by using this.