RBuckets object added. #460, #430

pull/461/head
Nikita 9 years ago
parent a95a08330a
commit 22a3dd2a09

@ -47,6 +47,7 @@ import org.redisson.core.RBlockingDeque;
import org.redisson.core.RBlockingQueue;
import org.redisson.core.RBloomFilter;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import org.redisson.core.RCountDownLatch;
import org.redisson.core.RDeque;
import org.redisson.core.RGeo;
@ -202,6 +203,16 @@ public class Redisson implements RedissonClient {
return new RedissonBucket<V>(codec, commandExecutor, name);
}
@Override
public RBuckets getBuckets() {
return new RedissonBuckets(this, commandExecutor);
}
@Override
public RBuckets getBuckets(Codec codec) {
return new RedissonBuckets(this, codec, commandExecutor);
}
@Override
public <V> List<RBucket<V>> findBuckets(String pattern) {
Collection<String> keys = commandExecutor.get(commandExecutor.<List<String>, String>readAllAsync(RedisCommands.KEYS, pattern));
@ -260,11 +271,6 @@ public class Redisson implements RedissonClient {
commandExecutor.write(params.get(0).toString(), RedisCommands.MSET, params.toArray());
}
@Override
public <V> List<RBucket<V>> getBuckets(String pattern) {
return findBuckets(pattern);
}
@Override
public <V> RHyperLogLog<V> getHyperLogLog(String name) {
return new RedissonHyperLogLog<V>(commandExecutor, name);

@ -0,0 +1,118 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DelegateDecoderCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.connection.decoder.MapGetAllDecoder;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import io.netty.util.concurrent.Future;
public class RedissonBuckets implements RBuckets {
private final Codec codec;
private final CommandExecutor commandExecutor;
private final Redisson redisson;
public RedissonBuckets(Redisson redisson, CommandExecutor commandExecutor) {
this(redisson, commandExecutor.getConnectionManager().getCodec(), commandExecutor);
}
public RedissonBuckets(Redisson redisson, Codec codec, CommandExecutor commandExecutor) {
super();
this.codec = codec;
this.commandExecutor = commandExecutor;
this.redisson = redisson;
}
@Override
public <V> List<RBucket<V>> find(String pattern) {
Collection<String> keys = commandExecutor.get(commandExecutor.<List<String>, String>readAllAsync(RedisCommands.KEYS, pattern));
List<RBucket<V>> buckets = new ArrayList<RBucket<V>>(keys.size());
for (String key : keys) {
if(key == null) {
continue;
}
buckets.add(redisson.<V>getBucket(key, codec));
}
return buckets;
}
@Override
public <V> Map<String, V> get(String... keys) {
if (keys.length == 0) {
return Collections.emptyMap();
}
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.asList(keys), 0), ValueType.OBJECTS);
Future<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
return commandExecutor.get(future);
}
@Override
public boolean trySet(Map<String, ?> buckets) {
if (buckets.isEmpty()) {
return false;
}
List<Object> params = new ArrayList<Object>(buckets.size());
for (Entry<String, ?> entry : buckets.entrySet()) {
params.add(entry.getKey());
try {
params.add(codec.getValueEncoder().encode(entry.getValue()));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
return commandExecutor.write(params.get(0).toString(), RedisCommands.MSETNX, params.toArray());
}
@Override
public void set(Map<String, ?> buckets) {
if (buckets.isEmpty()) {
return;
}
List<Object> params = new ArrayList<Object>(buckets.size());
for (Entry<String, ?> entry : buckets.entrySet()) {
params.add(entry.getKey());
try {
params.add(codec.getValueEncoder().encode(entry.getValue()));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
commandExecutor.write(params.get(0).toString(), RedisCommands.MSET, params.toArray());
}
}

@ -31,6 +31,7 @@ import org.redisson.core.RBlockingDeque;
import org.redisson.core.RBlockingQueue;
import org.redisson.core.RBloomFilter;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import org.redisson.core.RCountDownLatch;
import org.redisson.core.RDeque;
import org.redisson.core.RGeo;
@ -151,57 +152,43 @@ public interface RedissonClient {
<V> RBucket<V> getBucket(String name, Codec codec);
/**
* <p>Returns a list of object holder instances by a key pattern.
* Returns interface for mass operations with Bucket objects.
*
* <pre>Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
* h[^e]llo matches hallo, hbllo, ... but not hello
* h[a-b]llo matches hallo and hbllo</pre>
* <p>Use \ to escape special characters if you want to match them verbatim.
*
* <p>Uses <code>KEYS</code> Redis command.
*
* @param pattern
* @return
*/
<V> List<RBucket<V>> findBuckets(String pattern);
RBuckets getBuckets();
/**
* <p>Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* <p>Uses <code>MGET</code> Redis command.
* Returns interface for mass operations with Bucket objects
* using provided codec for object.
*
* @param keys
* @return
*/
<V> Map<String, V> loadBucketValues(Collection<String> keys);
RBuckets getBuckets(Codec codec);
/**
* <p>Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* <p>Uses <code>MGET</code> Redis command.
*
* @param keys
* @return
* Use {@link RBuckets#find(String)}
*/
<V> Map<String, V> loadBucketValues(String ... keys);
@Deprecated
<V> List<RBucket<V>> findBuckets(String pattern);
/**
* Saves Redis object mapped by key.
*
* @param buckets
* Use {@link RBuckets#get(String...)}
*/
void saveBuckets(Map<String, ?> buckets);
@Deprecated
<V> Map<String, V> loadBucketValues(Collection<String> keys);
/**
* Use {@link #findBuckets(String)}
* Use {@link RBuckets#get(String...)}
*/
@Deprecated
<V> List<RBucket<V>> getBuckets(String pattern);
<V> Map<String, V> loadBucketValues(String ... keys);
/**
* Use {@link RBuckets#set(Map)}
*/
@Deprecated
void saveBuckets(Map<String, ?> buckets);
/**
* Returns HyperLogLog instance by name.

@ -104,7 +104,7 @@ public class RedissonGeo<V> extends RedissonExpirable implements RGeo<V> {
List<Object> params = new ArrayList<Object>(members.length + 1);
params.add(getName());
params.addAll(Arrays.asList(members));
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params), 2, ValueType.OBJECTS);
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params, 1), 2, ValueType.OBJECTS);
return commandExecutor.readAsync(getName(), new ScoredCodec(codec), command, params.toArray());
}

@ -130,7 +130,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
List<Object> args = new ArrayList<Object>(keys.size() + 1);
args.add(getName());
args.addAll(keys);
return commandExecutor.readAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("HMGET", new MapGetAllDecoder(args), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE), args.toArray());
return commandExecutor.readAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("HMGET", new MapGetAllDecoder(args, 1), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE), args.toArray());
}
@Override

@ -162,11 +162,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
return newSucceededFuture(Collections.<K, V>emptyMap());
}
List<Object> args = new ArrayList<Object>(keys.size() + 2);
List<Object> args = new ArrayList<Object>(keys.size() + 1);
args.add(System.currentTimeMillis());
args.addAll(keys);
return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("EVAL", new MapGetAllDecoder(args), 7, ValueType.MAP_KEY, ValueType.MAP_VALUE),
return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("EVAL", new MapGetAllDecoder(args, 1), 7, ValueType.MAP_KEY, ValueType.MAP_VALUE),
"local expireHead = redis.call('zrange', KEYS[2], 0, 0, 'withscores');" +
"local expireIdleHead = redis.call('zrange', KEYS[3], 0, 0, 'withscores');" +
"local maxDate = table.remove(ARGV, 1); " // index is the first parameter

@ -0,0 +1,34 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client.codec;
import org.redisson.client.protocol.Decoder;
public class DelegateDecoderCodec extends StringCodec {
private final Codec delegate;
public DelegateDecoderCodec(Codec delegate) {
super();
this.delegate = delegate;
}
@Override
public Decoder<Object> getValueDecoder() {
return delegate.getValueDecoder();
}
}

@ -196,6 +196,7 @@ public interface RedisCommands {
RedisStrictCommand<List<String>> KEYS = new RedisStrictCommand<List<String>>("KEYS", new StringListReplayDecoder());
RedisCommand<List<Object>> MGET = new RedisCommand<List<Object>>("MGET", new ObjectListReplayDecoder<Object>());
RedisStrictCommand<Void> MSET = new RedisStrictCommand<Void>("MSET", new VoidReplayConvertor());
RedisStrictCommand<Boolean> MSETNX = new RedisStrictCommand<Boolean>("MSETNX", new BooleanReplayConvertor());
RedisCommand<Boolean> HSETNX = new RedisCommand<Boolean>("HSETNX", new BooleanReplayConvertor(), 2, ValueType.MAP);
RedisCommand<Boolean> HSET = new RedisCommand<Boolean>("HSET", new BooleanReplayConvertor(), 2, ValueType.MAP);

@ -25,7 +25,6 @@ import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> {
@ -40,7 +39,6 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
System.out.println("1 " + buf.toString(CharsetUtil.UTF_8));
if (pos.get() % 2 == 0) {
return codec.getValueDecoder().decode(buf, state);
}
@ -55,7 +53,6 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
@Override
public Map<Object, Object> decode(List<Object> parts, State state) {
System.out.println(parts);
Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
for (int i = 0; i < parts.size(); i++) {
if (i % 2 != 0) {

@ -28,10 +28,12 @@ import io.netty.buffer.ByteBuf;
public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
private final int shiftIndex;
private final List<Object> args;
public MapGetAllDecoder(List<Object> args) {
public MapGetAllDecoder(List<Object> args, int shiftIndex) {
this.args = args;
this.shiftIndex = shiftIndex;
}
@Override
@ -50,12 +52,12 @@ public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
return Collections.emptyMap();
}
Map<Object, Object> result = new HashMap<Object, Object>(parts.size());
for (int index = 0; index < args.size()-1; index++) {
for (int index = 0; index < args.size()-shiftIndex; index++) {
Object value = parts.get(index);
if (value == null) {
continue;
}
result.put(args.get(index+1), value);
result.put(args.get(index+shiftIndex), value);
}
return result;
}

@ -0,0 +1,64 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.core;
import java.util.List;
import java.util.Map;
public interface RBuckets {
/**
* <p>Returns a list of object holder instances by a key pattern.
*
* <pre>Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
* h[^e]llo matches hallo, hbllo, ... but not hello
* h[a-b]llo matches hallo and hbllo</pre>
* <p>Use \ to escape special characters if you want to match them verbatim.
*
* @param pattern
* @return
*/
<V> List<RBucket<V>> find(String pattern);
/**
* Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* @param keys
* @return
*/
<V> Map<String, V> get(String ... keys);
/**
* Try to save objects mapped by Redis key.
* If at least one of them is already exist then
* don't set none of them.
*
* @param buckets
*/
boolean trySet(Map<String, ?> buckets);
/**
* Saves objects mapped by Redis key.
*
* @param buckets
*/
void set(Map<String, ?> buckets);
}

@ -64,35 +64,6 @@ public class RedissonBucketTest extends BaseTest {
assertThat(r1.get()).isNull();
}
@Test
public void testSaveBuckets() {
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
redisson.saveBuckets(buckets);
RBucket<Object> r1 = redisson.getBucket("12");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isEqualTo(2);
}
@Test
public void testLoadBucketValues() {
RBucket<String> bucket1 = redisson.getBucket("test1");
bucket1.set("someValue1");
RBucket<String> bucket3 = redisson.getBucket("test3");
bucket3.set("someValue3");
Map<String, String> result = redisson.loadBucketValues("test1", "test2", "test3", "test4");
Map<String, String> expected = new HashMap<String, String>();
expected.put("test1", "someValue1");
expected.put("test3", "someValue3");
Assert.assertEquals(expected, result);
}
@Test
public void testExpire() throws InterruptedException {
RBucket<String> bucket = redisson.getBucket("test1");
@ -175,20 +146,4 @@ public class RedissonBucketTest extends BaseTest {
Assert.assertFalse(bucket.isExists());
}
@Test
public void testGetPattern() {
Collection<String> names = Arrays.asList("test:testGetPattern:one", "test:testGetPattern:two");
Collection<String> vals = Arrays.asList("one-val", "two-val");
redisson.getBucket("test:testGetPattern:one").set("one-val");
redisson.getBucket("test:testGetPattern:two").set("two-val");
List<RBucket<String>> buckets = redisson.getBuckets("test:testGetPattern:*");
Assert.assertEquals(2, buckets.size());
Assert.assertTrue(names.contains(buckets.get(0).getName()));
Assert.assertTrue(names.contains(buckets.get(1).getName()));
Assert.assertTrue(vals.contains(buckets.get(0).get()));
Assert.assertTrue(vals.contains(buckets.get(1).get()));
for (RBucket<String> bucket : buckets) {
bucket.delete();
}
}
}

@ -0,0 +1,91 @@
package org.redisson;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.*;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.core.RBucket;
public class RedissonBucketsTest extends BaseTest {
@Test
public void testGet() {
RBucket<String> bucket1 = redisson.getBucket("test1");
bucket1.set("someValue1");
RBucket<String> bucket3 = redisson.getBucket("test3");
bucket3.set("someValue3");
Map<String, String> result = redisson.getBuckets().get("test1", "test2", "test3", "test4");
Map<String, String> expected = new HashMap<String, String>();
expected.put("test1", "someValue1");
expected.put("test3", "someValue3");
Assert.assertEquals(expected, result);
}
@Test
public void testFind() {
Collection<String> names = Arrays.asList("test:testGetPattern:one", "test:testGetPattern:two");
Collection<String> vals = Arrays.asList("one-val", "two-val");
redisson.getBucket("test:testGetPattern:one").set("one-val");
redisson.getBucket("test:testGetPattern:two").set("two-val");
List<RBucket<String>> buckets = redisson.getBuckets().find("test:testGetPattern:*");
Assert.assertEquals(2, buckets.size());
Assert.assertTrue(names.contains(buckets.get(0).getName()));
Assert.assertTrue(names.contains(buckets.get(1).getName()));
Assert.assertTrue(vals.contains(buckets.get(0).get()));
Assert.assertTrue(vals.contains(buckets.get(1).get()));
for (RBucket<String> bucket : buckets) {
bucket.delete();
}
}
@Test
public void testSet() {
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
redisson.getBuckets().set(buckets);
RBucket<Object> r1 = redisson.getBucket("12");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isEqualTo(2);
}
@Test
public void testTrySet() {
redisson.getBucket("12").set("341");
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
assertThat(redisson.getBuckets().trySet(buckets)).isFalse();
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isNull();
Map<String, Integer> buckets2 = new HashMap<String, Integer>();
buckets2.put("61", 1);
buckets2.put("41", 2);
assertThat(redisson.getBuckets().trySet(buckets2)).isTrue();
RBucket<Object> r1 = redisson.getBucket("61");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r3 = redisson.getBucket("41");
assertThat(r3.get()).isEqualTo(2);
}
}

@ -0,0 +1,183 @@
package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.redisson.core.GeoEntry;
import org.redisson.core.GeoPosition;
import org.redisson.core.GeoUnit;
import org.redisson.core.RGeo;
public class RedissonGeoTest extends BaseTest {
@Test
public void testAdd() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.add(2.51, 3.12, "city1")).isEqualTo(1);
}
@Test
public void testAddEntries() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.add(new GeoEntry(3.11, 9.10321, "city1"), new GeoEntry(81.1231, 38.65478, "city2"))).isEqualTo(2);
}
@Test
public void testDist() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
assertThat(geo.dist("Palermo", "Catania", GeoUnit.METERS)).isEqualTo(166274.15156960033D);
}
@Test
public void testDistEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.dist("Palermo", "Catania", GeoUnit.METERS)).isNull();
}
@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);
}
@Test
public void testHashEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.hash("Palermo", "Catania")).isEmpty();
}
@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);
}
@Test
public void testPosEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.pos("test2", "Palermo", "test3", "Catania", "test1")).isEmpty();
}
@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");
}
@Test
public void testRadiusEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@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);
}
@Test
public void testRadiusWithDistanceEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusWithPosition() {
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(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusWithPositionEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusMember() {
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("Palermo", 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania");
}
@Test
public void testRadiusMemberEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusMemberWithDistance() {
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(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusMemberWithDistanceEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
@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);
}
@Test
public void testRadiusMemberWithPositionEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
}
Loading…
Cancel
Save