Java Code Examples for org.redisson.api.RGeo#add()

The following examples show how to use org.redisson.api.RGeo#add() . 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: RedissonGeoTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRadiusWithDistanceOrder() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, Double> descExpected = new LinkedHashMap<String, Double>();
    descExpected.put("Palermo", 190.4424);
    descExpected.put("Catania", 56.4413);
    assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet())
        .containsExactlyElementsOf(descExpected.entrySet());
    
    Map<String, Double> ascExpected = new LinkedHashMap<String, Double>();
    ascExpected.put("Catania", 56.4413);
    ascExpected.put("Palermo", 190.4424);
    assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet())
        .containsExactlyElementsOf(ascExpected.entrySet());
}
 
Example 2
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRadiusMemberWithPositionOrderCount() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, GeoPosition> ascExpected = new LinkedHashMap<String, GeoPosition>();
    ascExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet()).containsExactlyElementsOf(ascExpected.entrySet());
    
    Map<String, GeoPosition> descExpected = new LinkedHashMap<String, GeoPosition>();
    descExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet()).containsExactlyElementsOf(descExpected.entrySet());
    
    RGeo<String> geo2 = redisson.getGeo("test2");
    geo2.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(13.361390, 38.115557, "Catania"));
    Map<String, GeoPosition> ascExpected2 = new LinkedHashMap<String, GeoPosition>();
    ascExpected2.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    ascExpected2.put("Catania", new GeoPosition(13.361389338970184, 38.115556395496299));
    assertThat(geo2.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 2).entrySet()).containsExactlyElementsOf(ascExpected2.entrySet());
}
 
Example 3
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusStoreMember() {
    RGeo<String> geoSource = redisson.getGeo("test");
    RGeo<String> geoDest = redisson.getGeo("test-store");
    geoSource.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    assertThat(geoSource.radiusStoreTo(geoDest.getName(), "Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(2);
    assertThat(geoDest.readAll()).containsExactlyInAnyOrder("Palermo", "Catania");
}
 
Example 4
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusStoreCount() {
    RGeo<String> geoSource = redisson.getGeo("test");
    RGeo<String> geoDest = redisson.getGeo("test-store");
    geoSource.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    assertThat(geoSource.radiusStoreTo(geoDest.getName(), 15, 37, 200, GeoUnit.KILOMETERS, 1)).isEqualTo(1);
    assertThat(geoDest.readAll()).containsExactly("Catania");
}
 
Example 5
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusStoreSorted() {
    RGeo<String> geoSource = redisson.getGeo("test");
    RGeo<String> geoDest = redisson.getGeo("test-store");
    geoSource.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    assertThat(geoSource.radiusStoreSortedTo(geoDest.getName(), 15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(2);
    assertThat(geoDest.readAll()).containsExactly("Catania", "Palermo");
}
 
Example 6
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusMemberWithDistanceOrder() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, Double> ascExpected = new LinkedHashMap<String, Double>();
    ascExpected.put("Palermo", 0.0);
    ascExpected.put("Catania", 166.2742);
    assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()).containsExactlyElementsOf(ascExpected.entrySet());

    Map<String, Double> descExpected = new LinkedHashMap<String, Double>();
    descExpected.put("Catania", 166.2742);
    descExpected.put("Palermo", 0.0);
    assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()).containsExactlyElementsOf(descExpected.entrySet());
}
 
Example 7
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusWithDistanceHugeAmount() {
    RGeo<String> geo = redisson.getGeo("test");

    for (int i = 0; i < 10000; i++) {
        geo.add(10 + 0.000001*i, 11 + 0.000001*i, "" + i);
    }
    
    Map<String, Double> res = geo.radiusWithDistance(10, 11, 200, GeoUnit.KILOMETERS);
    assertThat(res).hasSize(10000);
}
 
Example 8
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusWithDistanceOrderCount() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, Double> descExpected = new LinkedHashMap<String, Double>();
    descExpected.put("Palermo", 190.4424);
    assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet())
        .containsExactlyElementsOf(descExpected.entrySet());
    
    Map<String, Double> ascExpected = new LinkedHashMap<String, Double>();
    ascExpected.put("Catania", 56.4413);
    assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet())
        .containsExactlyElementsOf(ascExpected.entrySet());
}
 
Example 9
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusWithPositionOrder() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, GeoPosition> descExpected = new LinkedHashMap<String, GeoPosition>();
    descExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    descExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()).containsExactlyElementsOf(descExpected.entrySet());
    
    Map<String, GeoPosition> ascExpected = new LinkedHashMap<String, GeoPosition>();
    ascExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    ascExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()).containsExactlyElementsOf(ascExpected.entrySet());
}
 
Example 10
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusWithDistance() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, Double> expected = new HashMap<String, Double>();
    expected.put("Palermo", 190.4424);
    expected.put("Catania", 56.4413);
    assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
 
Example 11
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusOrderCount() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1)).containsExactly("Palermo");
    assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1)).containsExactly("Catania");
}
 
Example 12
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusMemberWithDistanceCount() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, Double> expected = new HashMap<String, Double>();
    expected.put("Palermo", 0.0);
    expected.put("Catania", 166.2742);
    assertThat(expected.entrySet().removeAll(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, 1).entrySet())).isTrue();
    assertThat(expected).hasSize(1);
}
 
Example 13
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadius() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania");
}
 
Example 14
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPos() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
    
    Map<String, GeoPosition> expected = new LinkedHashMap<String, GeoPosition>();
    expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(geo.pos("test2", "Palermo", "test3", "Catania", "test1")).isEqualTo(expected);
}
 
Example 15
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusWithPositionCount() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, GeoPosition> expected = new HashMap<String, GeoPosition>();
    expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(expected.entrySet().removeAll(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, 1).entrySet())).isTrue();
    assertThat(expected).hasSize(1);
}
 
Example 16
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPos3() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(0.123,0.893,"hi");
    Map<String, GeoPosition> res = geo.pos("hi", "123f", "sdfdsf");
    assertThat(res.get("hi").getLatitude()).isNotNull();
    assertThat(res.get("hi").getLongitude()).isNotNull();
}
 
Example 17
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPos1() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(0.123,0.893,"hi");
    Map<String, GeoPosition> res = geo.pos("hi");
    assertThat(res.get("hi").getLatitude()).isNotNull();
    assertThat(res.get("hi").getLongitude()).isNotNull();
}
 
Example 18
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPos4() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
    
    Map<String, GeoPosition> expected = new LinkedHashMap<String, GeoPosition>();
    expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(geo.pos("Palermo", "Catania")).isEqualTo(expected);
}
 
Example 19
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testHash() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
    
    Map<String, String> expected = new LinkedHashMap<String, String>();
    expected.put("Palermo", "sqc8b49rny0");
    expected.put("Catania", "sqdtr74hyu0");
    assertThat(geo.hash("Palermo", "Catania")).isEqualTo(expected);
}
 
Example 20
Source File: RedissonGeoTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRadiusMemberWithPosition() {
    RGeo<String> geo = redisson.getGeo("test");
    geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));

    Map<String, GeoPosition> expected = new HashMap<String, GeoPosition>();
    expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
    expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
    assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}