Merge pull request #528 from mdheeraj24/master

Adding keySize functionality for MultiMaps
pull/537/head
Nikita Koksharov 9 years ago committed by GitHub
commit 7ea33941b2

@ -65,6 +65,8 @@ public class RedissonListMultimap<K, V> extends RedissonMultimap<K, V> implement
"return size; ",
Arrays.<Object>asList(getName()));
}
public Future<Boolean> containsKeyAsync(Object key) {
try {

@ -66,6 +66,11 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
public int size() {
return get(sizeAsync());
}
@Override
public int keySize() {
return get(keySizeAsync());
}
@Override
public boolean isEmpty() {
@ -237,8 +242,12 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
"return redis.call('persist', KEYS[1]); ",
Arrays.<Object>asList(getName()));
}
public Future<Integer> keySizeAsync() {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.HLEN, getName());
}
MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(InetSocketAddress client, long startPos) {
Future<MapScanResult<ScanObjectEntry, ScanObjectEntry>> f = commandExecutor.readAsync(client, getName(), new ScanCodec(codec, StringCodec.INSTANCE), RedisCommands.HSCAN, getName(), startPos);
return get(f);

@ -69,6 +69,8 @@ public class RedissonSetMultimap<K, V> extends RedissonMultimap<K, V> implements
Arrays.<Object>asList(getName()));
}
public Future<Boolean> containsKeyAsync(Object key) {
try {
byte[] keyState = codec.getMapKeyEncoder().encode(key);

@ -162,6 +162,11 @@ public interface RMultimap<K, V> extends RExpirable, RMultimapAsync<K, V> {
* vice versa. However, <i>adding</i> to the returned set is not possible.
*/
Set<K> keySet();
/**
* Returns the count of distinct keys in this multimap.
*/
int keySize();
/**
* Returns a view collection containing the <i>value</i> from each key-value

@ -123,6 +123,14 @@ public interface RMultimapAsync<K, V> extends RExpirableAsync {
Future<Collection<V>> removeAllAsync(Object key);
Future<Collection<V>> getAllAsync(K key);
/**
* Returns the number of key-value pairs in this multimap.
*
* @return
*/
Future<Integer> keySizeAsync();
/**
* Removes <code>keys</code> from map by one operation

@ -131,6 +131,23 @@ public class RedissonListMultimapTest extends BaseTest {
assertThat(s).isEmpty();
assertThat(map.size()).isEqualTo(1);
}
@Test
public void testKeySize() {
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
map.put(new SimpleKey("0"), new SimpleValue("1"));
map.put(new SimpleKey("0"), new SimpleValue("2"));
map.put(new SimpleKey("1"), new SimpleValue("4"));
assertThat(map.keySize()).isEqualTo(2);
assertThat(map.fastRemove(new SimpleKey("0"))).isEqualTo(1);
List<SimpleValue> s = map.get(new SimpleKey("0"));
assertThat(s).isEmpty();
assertThat(map.size()).isEqualTo(1);
}
@Test
public void testPut() {

@ -131,6 +131,22 @@ public class RedissonSetMultimapTest extends BaseTest {
assertThat(s).isEmpty();
assertThat(map.size()).isEqualTo(0);
}
@Test
public void testKeySize() {
RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
map.put(new SimpleKey("0"), new SimpleValue("1"));
map.put(new SimpleKey("0"), new SimpleValue("2"));
map.put(new SimpleKey("1"), new SimpleValue("3"));
assertThat(map.size()).isEqualTo(2);
map.fastRemove(new SimpleKey("0"));
Set<SimpleValue> s = map.get(new SimpleKey("0"));
assertThat(s).isEmpty();
assertThat(map.size()).isEqualTo(1);
}
@Test
public void testPut() {

Loading…
Cancel
Save