Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

How to get all Geo records from single Redis key using java (Jedis)

$
0
0

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 enter image description here


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>