redis.clients.jedis.GeoCoordinate Java Examples

The following examples show how to use redis.clients.jedis.GeoCoordinate. 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
private void prepareGeoData() {
  Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>();
  coordinateMap.put("a", new GeoCoordinate(3, 4));
  coordinateMap.put("b", new GeoCoordinate(2, 3));
  coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241));

  long size = jedis.geoadd("foo", coordinateMap);
  assertEquals(3, size);

  Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>();
  bcoordinateMap.put(bA, new GeoCoordinate(3, 4));
  bcoordinateMap.put(bB, new GeoCoordinate(2, 3));
  bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241));

  size = jedis.geoadd(bfoo, bcoordinateMap);
  assertEquals(3, size);
}
 
Example #2
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void geopos() {
  prepareGeoData();

  List<GeoCoordinate> coordinates = jedis.geopos("foo", "a", "b", "notexist");
  assertEquals(3, coordinates.size());
  assertTrue(equalsWithinEpsilon(3.0, coordinates.get(0).getLongitude()));
  assertTrue(equalsWithinEpsilon(4.0, coordinates.get(0).getLatitude()));
  assertTrue(equalsWithinEpsilon(2.0, coordinates.get(1).getLongitude()));
  assertTrue(equalsWithinEpsilon(3.0, coordinates.get(1).getLatitude()));
  assertNull(coordinates.get(2));

  List<GeoCoordinate> bcoordinates = jedis.geopos(bfoo, bA, bB, bNotexist);
  assertEquals(3, bcoordinates.size());
  assertTrue(equalsWithinEpsilon(3.0, bcoordinates.get(0).getLongitude()));
  assertTrue(equalsWithinEpsilon(4.0, bcoordinates.get(0).getLatitude()));
  assertTrue(equalsWithinEpsilon(2.0, bcoordinates.get(1).getLongitude()));
  assertTrue(equalsWithinEpsilon(3.0, bcoordinates.get(1).getLatitude()));
  assertNull(bcoordinates.get(2));
}
 
Example #3
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
  Span span = helper.buildSpan("geoadd");
  span.setTag("memberCoordinateMap", TracingHelper.toString(memberCoordinateMap));
  try {
    return super.geoadd(key, memberCoordinateMap);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #4
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 #5
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 #6
Source File: GeoCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void geoadd() {
  long size = jedis.geoadd("foo", 1, 2, "a");
  assertEquals(1, size);
  size = jedis.geoadd("foo", 2, 3, "a");
  assertEquals(0, size);

  Map<String, GeoCoordinate> coordinateMap = new HashMap<String, GeoCoordinate>();
  coordinateMap.put("a", new GeoCoordinate(3, 4));
  coordinateMap.put("b", new GeoCoordinate(2, 3));
  coordinateMap.put("c", new GeoCoordinate(3.314, 2.3241));

  size = jedis.geoadd("foo", coordinateMap);
  assertEquals(2, size);

  // binary
  size = jedis.geoadd(bfoo, 1, 2, bA);
  assertEquals(1, size);
  size = jedis.geoadd(bfoo, 2, 3, bA);
  assertEquals(0, size);

  Map<byte[], GeoCoordinate> bcoordinateMap = new HashMap<byte[], GeoCoordinate>();
  bcoordinateMap.put(bA, new GeoCoordinate(3, 4));
  bcoordinateMap.put(bB, new GeoCoordinate(2, 3));
  bcoordinateMap.put(bC, new GeoCoordinate(3.314, 2.3241));

  size = jedis.geoadd(bfoo, bcoordinateMap);
  assertEquals(2, size);
}
 
Example #7
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(String key, String... members) {
  Span span = helper.buildSpan("geopos", key);
  span.setTag("members", Arrays.toString(members));
  try {
    return super.geopos(key, members);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #8
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(final String key, final Map<String, GeoCoordinate> memberCoordinateMap) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<Long>(connectionHandler, maxAttempts) {
		@Override
		public Long doExecute(Jedis connection) {
			return connection.geoadd(key, memberCoordinateMap);
		}
	}.run(key);
}
 
Example #9
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(byte[] key, byte[]... members) {
  Span span = helper.buildSpan("geopos", key);
  span.setTag("members", Arrays.toString(members));
  try {
    return super.geopos(key, members);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #10
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap) {
  Span span = helper.buildSpan("geoadd", key);
  span.setTag("memberCoordinateMap", TracingHelper.toStringMap2(memberCoordinateMap));
  try {
    return super.geoadd(key, memberCoordinateMap);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #11
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(String key, String... members) {
  Span span = helper.buildSpan("geopos", key);
  span.setTag("members", Arrays.toString(members));
  try {
    return super.geopos(key, members);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #12
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
  Span span = helper.buildSpan("geoadd");
  span.setTag("memberCoordinateMap", TracingHelper.toString(memberCoordinateMap));
  try {
    return super.geoadd(key, memberCoordinateMap);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #13
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(byte[] key, byte[]... members) {
  Span span = helper.buildSpan("geopos", key);
  span.setTag("members", Arrays.toString(members));
  try {
    return super.geopos(key, members);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #14
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap) {
  Span span = helper.buildSpan("geoadd", key);
  span.setTag("memberCoordinateMap", TracingHelper.toStringMap2(memberCoordinateMap));
  try {
    return super.geoadd(key, memberCoordinateMap);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #15
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(final byte[] key, final byte[]... members) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoCoordinate>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoCoordinate> doExecute(Jedis connection) {
			return connection.geopos(key, members);
		}
	}.runBinary(key);
}
 
Example #16
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public Long geoadd(final byte[] key, final Map<byte[], GeoCoordinate> memberCoordinateMap) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<Long>(connectionHandler, maxAttempts) {
		@Override
		public Long doExecute(Jedis connection) {
			return connection.geoadd(key, memberCoordinateMap);
		}
	}.runBinary(key);
}
 
Example #17
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(final String key, final String... members) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<List<GeoCoordinate>>(connectionHandler, maxAttempts) {
		@Override
		public List<GeoCoordinate> doExecute(Jedis connection) {
			return connection.geopos(key, members);
		}
	}.run(key);
}
 
Example #18
Source File: JedisSentinel.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
    try (Jedis jedis = jedisPool.getResource()) {
        return jedis.geoadd(key, memberCoordinateMap);
    }
}
 
Example #19
Source File: JedisSentinel.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(String key, String... members) {
    try (Jedis jedis = jedisPool.getResource()) {
        return jedis.geopos(key, members);
    }
}
 
Example #20
Source File: JedisCluster.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
    return jedisCluster.geoadd(key, memberCoordinateMap);
}
 
Example #21
Source File: JedisCluster.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public List<GeoCoordinate> geopos(String key, String... members) {
    return jedisCluster.geopos(key, members);
}