Merge branch 'mrniko/master' into live-object

pull/527/head
jackygurui 9 years ago
commit 618d2cbd65

@ -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);
@ -272,7 +281,7 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
@Override
public int size() {
return RedissonMultimap.this.size();
return RedissonMultimap.this.keySize();
}
@Override

@ -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);

@ -291,8 +291,10 @@ public class MasterSlaveEntry {
this.config.getSlaveSubscriptionConnectionMinimumIdleSize(),
this.config.getSlaveSubscriptionConnectionPoolSize(), connectionManager, mode);
if (freezed) {
entry.setFreezed(freezed);
entry.setFreezeReason(FreezeReason.SYSTEM);
synchronized (entry) {
entry.setFreezed(freezed);
entry.setFreezeReason(FreezeReason.SYSTEM);
}
}
return slaveBalancer.add(entry);
}
@ -350,8 +352,10 @@ public class MasterSlaveEntry {
public void unfreeze() {
masterEntry.resetFailedAttempts();
masterEntry.setFreezed(false);
masterEntry.setFreezeReason(null);
synchronized (masterEntry) {
masterEntry.setFreezed(false);
masterEntry.setFreezeReason(null);
}
}
public void shutdownMasterAsync() {

@ -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

@ -17,13 +17,8 @@ package org.redisson.spring.cache;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.redisson.RedissonClient;
import org.redisson.core.RLock;
@ -40,8 +35,6 @@ import org.springframework.cache.support.SimpleValueWrapper;
*/
public class RedissonCache implements Cache {
private final ConcurrentMap<Object, Lock> valueLoaderLocks = new ConcurrentHashMap<Object, Lock>();
private RMapCache<Object, Object> mapCache;
private final RMap<Object, Object> map;
@ -130,18 +123,6 @@ public class RedissonCache implements Cache {
return new SimpleValueWrapper(value);
}
public Lock getLock(Object key) {
Lock lock = valueLoaderLocks.get(key);
if (lock == null) {
Lock newlock = new ReentrantLock();
lock = valueLoaderLocks.putIfAbsent(key, newlock);
if (lock == null) {
lock = newlock;
}
}
return lock;
}
public <T> T get(Object key, Callable<T> valueLoader) {
Object value = map.get(key);
if (value == null) {

@ -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