|
|
|
@ -27,10 +27,13 @@ import java.util.Map.Entry;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.RCountDownLatch;
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
import org.redisson.api.RLock;
|
|
|
|
|
import org.redisson.api.RMultimap;
|
|
|
|
|
import org.redisson.api.RPermitExpirableSemaphore;
|
|
|
|
|
import org.redisson.api.RReadWriteLock;
|
|
|
|
|
import org.redisson.api.RSemaphore;
|
|
|
|
|
import org.redisson.client.RedisClient;
|
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
|
import org.redisson.client.codec.LongCodec;
|
|
|
|
@ -40,7 +43,6 @@ import org.redisson.client.protocol.RedisCommands;
|
|
|
|
|
import org.redisson.client.protocol.decoder.MapScanResult;
|
|
|
|
|
import org.redisson.codec.CompositeCodec;
|
|
|
|
|
import org.redisson.command.CommandAsyncExecutor;
|
|
|
|
|
import org.redisson.command.CommandExecutor;
|
|
|
|
|
import org.redisson.misc.Hash;
|
|
|
|
|
import org.redisson.misc.RedissonPromise;
|
|
|
|
|
|
|
|
|
@ -67,24 +69,39 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RLock getLock(K key) {
|
|
|
|
|
String lockName = getLockName(key);
|
|
|
|
|
return new RedissonLock((CommandExecutor) commandExecutor, lockName);
|
|
|
|
|
public RLock getFairLock(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "fairlock");
|
|
|
|
|
return new RedissonFairLock(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RReadWriteLock getReadWriteLock(K key) {
|
|
|
|
|
String lockName = getLockName(key);
|
|
|
|
|
return new RedissonReadWriteLock((CommandExecutor) commandExecutor, lockName);
|
|
|
|
|
public RPermitExpirableSemaphore getPermitExpirableSemaphore(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "permitexpirablesemaphore");
|
|
|
|
|
return new RedissonPermitExpirableSemaphore(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getLockName(Object key) {
|
|
|
|
|
ByteBuf keyState = encodeMapKey(key);
|
|
|
|
|
try {
|
|
|
|
|
return suffixName(getName(), Hash.hash128toBase64(keyState) + ":key");
|
|
|
|
|
} finally {
|
|
|
|
|
keyState.release();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public RCountDownLatch getCountDownLatch(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "countdownlatch");
|
|
|
|
|
return new RedissonCountDownLatch(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RSemaphore getSemaphore(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "semaphore");
|
|
|
|
|
return new RedissonSemaphore(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RLock getLock(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "lock");
|
|
|
|
|
return new RedissonLock(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RReadWriteLock getReadWriteLock(K key) {
|
|
|
|
|
String lockName = getLockByMapKey(key, "rw_lock");
|
|
|
|
|
return new RedissonReadWriteLock(commandExecutor, lockName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String hash(ByteBuf objectState) {
|
|
|
|
|