refactoring

pull/4966/head
Nikita Koksharov 2 years ago
parent 6049be1012
commit 209bde4cef

@ -1846,6 +1846,11 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
}
@Override
public RFuture<Boolean> clearAsync() {
return deleteAsync();
}
@Override
public void destroy() {
if (writeBehindService != null) {

@ -2376,6 +2376,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
get(future);
}
@Override
public RFuture<Boolean> clearAsync() {
return deleteAsync(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName());
}
@Override
public RFuture<Boolean> deleteAsync() {
return deleteAsync(getRawName(), getTimeoutSetName(), getIdleSetName(), getLastAccessTimeSetName(), getOptionsName());

@ -411,4 +411,11 @@ public interface RMapAsync<K, V> extends RExpirableAsync {
*/
RFuture<V> putIfExistsAsync(K key, V value);
/**
* Clears map without removing options data used during map creation.
*
* @return <code>true</code> if map was cleared <code>false</code> if not
*/
RFuture<Boolean> clearAsync();
}

@ -15,17 +15,20 @@
*/
package org.redisson.spring.cache;
import java.lang.reflect.Constructor;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.redisson.api.RFuture;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.redisson.api.RMapCache;
import org.redisson.client.RedisException;
import org.springframework.cache.Cache;
import org.springframework.cache.support.SimpleValueWrapper;
import java.lang.reflect.Constructor;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
*
* @author Nikita Koksharov
@ -161,7 +164,23 @@ public class RedissonCache implements Cache {
}
public boolean invalidate() {
return map.delete();
return get(map.clearAsync());
}
private <V> V get(RFuture<V> future) {
if (Thread.currentThread().getName().startsWith("redisson-netty")) {
throw new IllegalStateException("Sync methods can't be invoked from async/rx/reactive listeners");
}
try {
return future.get();
} catch (InterruptedException e) {
future.cancel(true);
Thread.currentThread().interrupt();
throw new RedisException(e);
} catch (ExecutionException e) {
throw new RedisException(e.getCause());
}
}
private ValueWrapper toValueWrapper(Object value) {

Loading…
Cancel
Save