问题描述
jedis.geoadd("storegeodata",51.5074,0.1278,"London");
//while member string is mostly json
jedis.geoadd("storegeodata","{place: London}");
jedis.geoadd("storegeodata","{place: London,lat: 51.5074,lon: 0.1278}");
由于成员字符串不同而重复了geohash时,如何获取基于geohash的唯一值以避免冗余
public Map<String,Object> checkRedisGeo(double lat,double lon,Jedis j) {
Map<String,Object> result = new HashMap<>();
try
{
GeoRadiusParam param = GeoRadiusParam.geoRadiusparam();
param.sortAscending();
param.withdist();
param.count(1);
System.out.println("lat :"+lat+",lon :"+lon);
List<GeoRadiusResponse> response = j.georadius("commander",lon,lat,150,GeoUnit.M,param);
//System.out.println(response.size()+" size");
if(response.size() > 0)
{
for (GeoRadiusResponse geoRadiusResponse : response) {
System.out.println("lat :"+lat+",lon :"+lon+",stringmember :"+geoRadiusResponse.getMemberByString());
//System.out.println(geoRadiusResponse.getdistance());
Object[] data= {geoRadiusResponse.getMemberByString()};
System.out.println(data);
result.put("result",data);
}
}else {
// sendEvents(streamEvent,null,streamEventChunk);
System.out.println("E");
}
} catch (Exception e) {
LOGGER.error("checkRedisGeo err : "+e);
}
return result;
}
哪个会检索结果,但是如何根据geohash / score值进行过滤,如何获取所有不同的分数?
解决方法
由于得分是唯一的,因此能够通过比较得分来获得重复和唯一得分 并按照相同的代码存储了多个相同得分的成员
Double previous_score = 0.0;
int DuplincatesCount = 0;
int UniqueCount = 0;
Set<String> values = jedis.zrange("rediskey",-1);// get all the members
for (String member : values) {
Double current_score = jedis.zscore("rediskey",member);//each member looped
if (Double.compare(current_score,previous_score) == 0) { //comparing current score with previous
// score
DuplincatesCount++;
} else {
UniqueCount++;
}
previous_score = current_score;// score mapping
}
System.out.println("Duplincates entry " + DuplincatesCount);
System.out.println("Unique entry " + UniqueCount);