redis.clients.jedis.params.geo.GeoRadiusParam Java Examples

The following examples show how to use redis.clients.jedis.params.geo.GeoRadiusParam. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void georadiusByMemberBinary() {
  jedis.geoadd(bfoo, 13.583333, 37.316667, bA);
  jedis.geoadd(bfoo, 13.361389, 38.115556, bB);
  jedis.geoadd(bfoo, 15.087269, 37.502669, bC);

  List<GeoRadiusResponse> members = jedis.georadiusByMember(bfoo, bA, 100, GeoUnit.KM);
  assertEquals(2, members.size());

  members = jedis.georadiusByMember(bfoo, bA, 100, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending());
  assertEquals(2, members.size());
  assertArrayEquals(bA, members.get(0).getMember());
  assertArrayEquals(bB, members.get(1).getMember());

  members = jedis.georadiusByMember(bfoo, bA, 100, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending().count(1).withCoord().withDist());
  assertEquals(1, members.size());

  GeoRadiusResponse member = members.get(0);
  assertArrayEquals(bA, member.getMember());
  assertTrue(equalsWithinEpsilon(0, member.getDistance()));
  assertTrue(equalsWithinEpsilon(13.583333, member.getCoordinate().getLongitude()));
  assertTrue(equalsWithinEpsilon(37.316667, member.getCoordinate().getLatitude()));
}
 
Example #2
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMember", key);
  span.setTag("member", Arrays.toString(member));
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  try {
    return super.georadiusByMember(key, member, radius, unit, param);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #3
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadius", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  try {
    return super.georadius(key, longitude, latitude, radius, unit, param);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #4
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadius", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  try {
    return super.georadius(key, longitude, latitude, radius, unit, param);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #5
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMember", key);
  span.setTag("member", member);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  try {
    return super.georadiusByMember(key, member, radius, unit, param);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #6
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void georadiusByMember() {
  jedis.geoadd("Sicily", 13.583333, 37.316667, "Agrigento");
  jedis.geoadd("Sicily", 13.361389, 38.115556, "Palermo");
  jedis.geoadd("Sicily", 15.087269, 37.502669, "Catania");

  List<GeoRadiusResponse> members = jedis.georadiusByMember("Sicily", "Agrigento", 100,
    GeoUnit.KM);
  assertEquals(2, members.size());

  members = jedis.georadiusByMember("Sicily", "Agrigento", 100, GeoUnit.KM, GeoRadiusParam
      .geoRadiusParam().sortAscending());
  assertEquals(2, members.size());
  assertEquals("Agrigento", members.get(0).getMemberByString());
  assertEquals("Palermo", members.get(1).getMemberByString());

  members = jedis.georadiusByMember("Sicily", "Agrigento", 100, GeoUnit.KM, GeoRadiusParam
      .geoRadiusParam().sortAscending().count(1).withCoord().withDist());
  assertEquals(1, members.size());

  GeoRadiusResponse member = members.get(0);
  assertEquals("Agrigento", member.getMemberByString());
  assertTrue(equalsWithinEpsilon(0, member.getDistance()));
  assertTrue(equalsWithinEpsilon(13.583333, member.getCoordinate().getLongitude()));
  assertTrue(equalsWithinEpsilon(37.316667, member.getCoordinate().getLatitude()));
}
 
Example #7
Source File: JedisCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(final String key, final double longitude,
    final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) {
  return new JedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxRedirections) {
    @Override
    public List<GeoRadiusResponse> execute(Jedis connection) {
      return connection.georadius(key, longitude, latitude, radius, unit, param);
    }
  }.run(key);
}
 
Example #8
Source File: JedisCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(final String key, final String member,
    final double radius, final GeoUnit unit, final GeoRadiusParam param) {
  return new JedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxRedirections) {
    @Override
    public List<GeoRadiusResponse> execute(Jedis connection) {
      return connection.georadiusByMember(key, member, radius, unit, param);
    }
  }.run(key);
}
 
Example #9
Source File: BinaryJedisCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(final byte[] key, final double longitude,
    final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) {
  return new JedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxRedirections) {
    @Override
    public List<GeoRadiusResponse> execute(Jedis connection) {
      return connection.georadius(key, longitude, latitude, radius, unit, param);
    }
  }.runBinary(key);
}
 
Example #10
Source File: BinaryJedisCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(final byte[] key, final byte[] member,
    final double radius, final GeoUnit unit, final GeoRadiusParam param) {
    return new JedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxRedirections) {
        @Override
        public List<GeoRadiusResponse> execute(Jedis connection) {
            return connection.georadiusByMember(key, member, radius, unit, param);
        }
    }.runBinary(key);
}
 
Example #11
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void georadius() {
  // prepare datas
  Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>();
  coordinateMap.put("Palermo", new GeoCoordinate(13.361389, 38.115556));
  coordinateMap.put("Catania", new GeoCoordinate(15.087269, 37.502669));
  jedis.geoadd("Sicily", coordinateMap);

  List<GeoRadiusResponse> members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM);
  assertEquals(2, members.size());

  // sort
  members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending());
  assertEquals(2, members.size());
  assertEquals("Catania", members.get(0).getMemberByString());
  assertEquals("Palermo", members.get(1).getMemberByString());

  // sort, count 1
  members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending().count(1));
  assertEquals(1, members.size());

  // sort, count 1, withdist, withcoord
  members = jedis.georadius("Sicily", 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending().count(1).withCoord().withDist());
  assertEquals(1, members.size());
  GeoRadiusResponse response = members.get(0);
  assertTrue(equalsWithinEpsilon(56.4413, response.getDistance()));
  assertTrue(equalsWithinEpsilon(15.087269, response.getCoordinate().getLongitude()));
  assertTrue(equalsWithinEpsilon(37.502669, response.getCoordinate().getLatitude()));
}
 
Example #12
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void georadiusBinary() {
  // prepare datas
  Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>();
  bcoordinateMap.put(bA, new GeoCoordinate(13.361389, 38.115556));
  bcoordinateMap.put(bB, new GeoCoordinate(15.087269, 37.502669));
  jedis.geoadd(bfoo, bcoordinateMap);

  List<GeoRadiusResponse> members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM);
  assertEquals(2, members.size());

  // sort
  members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending());
  assertEquals(2, members.size());
  assertArrayEquals(bB, members.get(0).getMember());
  assertArrayEquals(bA, members.get(1).getMember());

  // sort, count 1
  members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending().count(1));
  assertEquals(1, members.size());

  // sort, count 1, withdist, withcoord
  members = jedis.georadius(bfoo, 15, 37, 200, GeoUnit.KM, GeoRadiusParam.geoRadiusParam()
      .sortAscending().count(1).withCoord().withDist());
  assertEquals(1, members.size());
  GeoRadiusResponse response = members.get(0);
  assertTrue(equalsWithinEpsilon(56.4413, response.getDistance()));
  assertTrue(equalsWithinEpsilon(15.087269, response.getCoordinate().getLongitude()));
  assertTrue(equalsWithinEpsilon(37.502669, response.getCoordinate().getLatitude()));
}
 
Example #13
Source File: BinaryJedis.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  checkIsInMultiOrPipeline();
  client.georadiusByMember(key, member, radius, unit, param);
  return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}
 
Example #14
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(String key, String member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMemberReadonly", key);
  span.setTag("member", member);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span, () -> super.georadiusByMemberReadonly(key, member, radius, unit, param));
}
 
Example #15
Source File: BinaryJedis.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  checkIsInMultiOrPipeline();
  client.georadius(key, longitude, latitude, radius, unit, param);
  return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}
 
Example #16
Source File: Jedis.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  checkIsInMultiOrPipeline();
  client.georadius(key, longitude, latitude, radius, unit, param);
  return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}
 
Example #17
Source File: Jedis.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  checkIsInMultiOrPipeline();
  client.georadiusByMember(key, member, radius, unit, param);
  return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());

}
 
Example #18
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusReadonly(String key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusReadonly", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span,
          () -> super.georadiusReadonly(key, longitude, latitude, radius, unit, param));
}
 
Example #19
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(final String key, final double longitude, final double latitude, final double radius,
		final GeoUnit unit, final GeoRadiusParam param) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoRadiusResponse> doExecute(Jedis connection) {
			return connection.georadius(key, longitude, latitude, radius, unit, param);
		}
	}.run(key);
}
 
Example #20
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(final byte[] key, final double longitude, final double latitude, final double radius,
		final GeoUnit unit, final GeoRadiusParam param) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoRadiusResponse> doExecute(Jedis connection) {
			return connection.georadius(key, longitude, latitude, radius, unit, param);
		}
	}.runBinary(key);
}
 
Example #21
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(final byte[] key, final byte[] member, final double radius,
		final GeoUnit unit, final GeoRadiusParam param) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoRadiusResponse> doExecute(Jedis connection) {
			return connection.georadiusByMember(key, member, radius, unit, param);
		}
	}.runBinary(key);
}
 
Example #22
Source File: LBSServiceRedisImpl.java    From redis_util with Apache License 2.0 5 votes vote down vote up
public List<Postion> radious(String type, GeoCoordinate center, Long distinct, Boolean asc) {
    List<Postion> postions = new ArrayList<Postion>();
    Jedis jedis = redisConnection.getJedis();
    try {
        GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam().withCoord().withDist();
        if (asc) {
            geoRadiusParam.sortAscending();
        } else {
            geoRadiusParam.sortDescending();
        }
        List<GeoRadiusResponse> responses = jedis.georadius(type,
                center.getLongitude(),
                center.getLatitude(),
                distinct.doubleValue(),
                GeoUnit.M,
                geoRadiusParam);
        if (responses != null) {
            for (GeoRadiusResponse response : responses) {
                Postion postion = new Postion(response.getMemberByString(),
                        type,
                        response.getCoordinate().getLongitude(),
                        response.getCoordinate().getLatitude());
                postion.setDistinct(response.getDistance());
                postions.add(postion);
            }
        }
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }

    return postions;
}
 
Example #23
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadius", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span, () -> wrapped.georadius(key, longitude, latitude, radius, unit, param));
}
 
Example #24
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusReadonly(String key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusReadonly", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper.decorate(span,
      () -> wrapped.georadiusReadonly(key, longitude, latitude, radius, unit, param));
}
 
Example #25
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(String key, String member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMemberReadonly", key);
  span.setTag("member", member);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span, () -> wrapped.georadiusByMemberReadonly(key, member, radius, unit, param));
}
 
Example #26
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(final String key, final String member, final double radius,
		final GeoUnit unit, final GeoRadiusParam param) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoRadiusResponse>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoRadiusResponse> doExecute(Jedis connection) {
			return connection.georadiusByMember(key, member, radius, unit, param);
		}
	}.run(key);
}
 
Example #27
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMember", key);
  span.setTag("member", member);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper.decorate(span, () -> wrapped.georadiusByMember(key, member, radius, unit, param));
}
 
Example #28
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadius", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span, () -> wrapped.georadius(key, longitude, latitude, radius, unit, param));
}
 
Example #29
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusReadonly(byte[] key, double longitude, double latitude,
    double radius, GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusReadonly", key);
  span.setTag("longitude", longitude);
  span.setTag("latitude", latitude);
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper
      .decorate(span,
          () -> wrapped.georadiusReadonly(key, longitude, latitude, radius, unit, param));
}
 
Example #30
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius,
    GeoUnit unit, GeoRadiusParam param) {
  Span span = helper.buildSpan("georadiusByMember", key);
  span.setTag("member", Arrays.toString(member));
  span.setTag("radius", radius);
  span.setTag("unit", unit.name());
  span.setTag("param", TracingHelper.toString(param.getByteParams()));
  return helper.decorate(span, () -> wrapped.georadiusByMember(key, member, radius, unit, param));
}