|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
import org.redisson.api.RSemaphore;
|
|
|
|
|
import org.redisson.client.codec.IntegerCodec;
|
|
|
|
|
import org.redisson.client.codec.LongCodec;
|
|
|
|
|
import org.redisson.client.codec.StringCodec;
|
|
|
|
|
import org.redisson.client.protocol.RedisCommands;
|
|
|
|
@ -441,26 +442,32 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
|
|
|
|
|
Arrays.<Object>asList(getName(), getChannelName()), permits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int drainPermits() {
|
|
|
|
|
RFuture<Long> future = commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG,
|
|
|
|
|
return get(drainPermitsAsync());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> drainPermitsAsync() {
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), IntegerCodec.INSTANCE, RedisCommands.EVAL_LONG,
|
|
|
|
|
"local value = redis.call('get', KEYS[1]); " +
|
|
|
|
|
"if (value == false or value == 0) then " +
|
|
|
|
|
"return 0; " +
|
|
|
|
|
"end; " +
|
|
|
|
|
"redis.call('set', KEYS[1], 0); " +
|
|
|
|
|
"return value;",
|
|
|
|
|
Collections.<Object>singletonList(getName()));
|
|
|
|
|
Long res = get(future);
|
|
|
|
|
return res.intValue();
|
|
|
|
|
Collections.singletonList(getName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int availablePermits() {
|
|
|
|
|
RFuture<Long> future = commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.GET_LONG, getName());
|
|
|
|
|
Long res = get(future);
|
|
|
|
|
return res.intValue();
|
|
|
|
|
RFuture<Integer> future = commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.GET_INTEGER, getName());
|
|
|
|
|
return get(future);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> availablePermitsAsync() {
|
|
|
|
|
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.GET_INTEGER, getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|