minor optimization

pull/179/head
Nikita 10 years ago
parent 52168d064e
commit d75a83d68c

@ -54,12 +54,10 @@ public class RedissonAtomicLong extends RedissonExpirable implements RAtomicLong
@Override @Override
public boolean compareAndSet(final long expect, final long update) { public boolean compareAndSet(final long expect, final long update) {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"if redis.call('get', KEYS[1]) == ARGV[1] then redis.call('set', KEYS[1], ARGV[2]); return true else return false end", "if redis.call('get', KEYS[1]) == ARGV[1] then redis.call('set', KEYS[1], ARGV[2]); return true else return false end",
RScript.ReturnType.BOOLEAN, RScript.ReturnType.BOOLEAN,
keys, Collections.EMPTY_LIST, Arrays.asList(expect, update)); Collections.<Object>singletonList(getName()), Collections.EMPTY_LIST, Arrays.asList(expect, update));
} }
@Override @Override
@ -79,22 +77,18 @@ public class RedissonAtomicLong extends RedissonExpirable implements RAtomicLong
@Override @Override
public long getAndAdd(final long delta) { public long getAndAdd(final long delta) {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"local v = redis.call('get', KEYS[1]) or 0; redis.call('set', KEYS[1], v + ARGV[1]); return tonumber(v)", "local v = redis.call('get', KEYS[1]) or 0; redis.call('set', KEYS[1], v + ARGV[1]); return tonumber(v)",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, Collections.EMPTY_LIST, Collections.singletonList(delta)); Collections.<Object>singletonList(getName()), Collections.EMPTY_LIST, Collections.singletonList(delta));
} }
@Override @Override
public long getAndSet(final long newValue) { public long getAndSet(final long newValue) {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"local v = redis.call('get', KEYS[1]) or 0; redis.call('set', KEYS[1], ARGV[1]); return tonumber(v)", "local v = redis.call('get', KEYS[1]) or 0; redis.call('set', KEYS[1], ARGV[1]); return tonumber(v)",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, Collections.EMPTY_LIST, Collections.singletonList(newValue)); Collections.<Object>singletonList(getName()), Collections.EMPTY_LIST, Collections.singletonList(newValue));
} }
@Override @Override
@ -118,12 +112,10 @@ public class RedissonAtomicLong extends RedissonExpirable implements RAtomicLong
@Override @Override
public void set(final long newValue) { public void set(final long newValue) {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
new RedissonScript(connectionManager).evalR( new RedissonScript(connectionManager).evalR(
"redis.call('set', KEYS[1], ARGV[1])", "redis.call('set', KEYS[1], ARGV[1])",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, Collections.EMPTY_LIST, Collections.singletonList(newValue)); Collections.<Object>singletonList(getName()), Collections.EMPTY_LIST, Collections.singletonList(newValue));
} }
public String toString() { public String toString() {

@ -36,7 +36,7 @@ import org.redisson.core.RScript;
* {@link LinkedBlockingQueue} where items are added as soon as * {@link LinkedBlockingQueue} where items are added as soon as
* <code>blpop</code> returns. All {@link BlockingQueue} methods are actually * <code>blpop</code> returns. All {@link BlockingQueue} methods are actually
* delegated to this intermediary queue. * delegated to this intermediary queue.
* *
* @author pdeschen@gmail.com * @author pdeschen@gmail.com
* @author Nikita Koksharov * @author Nikita Koksharov
*/ */
@ -81,7 +81,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
throws InterruptedException { throws InterruptedException {
return pollLastAndOfferFirstTo(queue.getName(), timeout, unit); return pollLastAndOfferFirstTo(queue.getName(), timeout, unit);
} }
@Override @Override
public V pollLastAndOfferFirstTo(final String queueName, final long timeout, final TimeUnit unit) throws InterruptedException { public V pollLastAndOfferFirstTo(final String queueName, final long timeout, final TimeUnit unit) throws InterruptedException {
return connectionManager.write(getName(), new SyncInterruptedOperation<V, V>() { return connectionManager.write(getName(), new SyncInterruptedOperation<V, V>() {
@ -91,7 +91,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
} }
}); });
} }
@Override @Override
public int remainingCapacity() { public int remainingCapacity() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
@ -102,14 +102,12 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
if (c == null) { if (c == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
List<V> list = new RedissonScript(connectionManager).eval( List<V> list = new RedissonScript(connectionManager).eval(
"local vals = redis.call('lrange', KEYS[1], 0, -1); " + "local vals = redis.call('lrange', KEYS[1], 0, -1); " +
"redis.call('ltrim', KEYS[1], -1, 0); " + "redis.call('ltrim', KEYS[1], -1, 0); " +
"return vals", "return vals",
RScript.ReturnType.MAPVALUELIST, RScript.ReturnType.MAPVALUELIST,
keys); Collections.<Object>singletonList(getName()));
c.addAll(list); c.addAll(list);
return list.size(); return list.size();
} }
@ -123,15 +121,13 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
throw new NullPointerException(); throw new NullPointerException();
} }
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
List<V> list = new RedissonScript(connectionManager).evalR( List<V> list = new RedissonScript(connectionManager).evalR(
"local elemNum = math.min(ARGV[1], redis.call('llen', KEYS[1])) - 1;" + "local elemNum = math.min(ARGV[1], redis.call('llen', KEYS[1])) - 1;" +
"local vals = redis.call('lrange', KEYS[1], 0, elemNum); " + "local vals = redis.call('lrange', KEYS[1], 0, elemNum); " +
"redis.call('ltrim', KEYS[1], elemNum + 1, -1); " + "redis.call('ltrim', KEYS[1], elemNum + 1, -1); " +
"return vals", "return vals",
RScript.ReturnType.MAPVALUELIST, RScript.ReturnType.MAPVALUELIST,
keys, Collections.emptyList(), Collections.singletonList(maxElements)); Collections.<Object>singletonList(getName()), Collections.emptyList(), Collections.singletonList(maxElements));
c.addAll(list); c.addAll(list);
return list.size(); return list.size();
} }

@ -193,15 +193,14 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
if (getCount() <= 0) { if (getCount() <= 0) {
return; return;
} }
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
new RedissonScript(connectionManager).evalR( new RedissonScript(connectionManager).evalR(
"local v = redis.call('decr', KEYS[1]);" + "local v = redis.call('decr', KEYS[1]);" +
"if v <= 0 then redis.call('del', KEYS[1]) end;" + "if v <= 0 then redis.call('del', KEYS[1]) end;" +
"if v == 0 then redis.call('publish', ARGV[2], ARGV[1]) end;" + "if v == 0 then redis.call('publish', ARGV[2], ARGV[1]) end;" +
"return 'OK'", "return 'OK'",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, Collections.singletonList(zeroCountMessage), Collections.singletonList(getChannelName())); Collections.<Object>singletonList(getName()), Collections.singletonList(zeroCountMessage), Collections.singletonList(getChannelName()));
} }
private String getEntryName() { private String getEntryName() {
@ -218,13 +217,11 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
} }
private long getCountInner() { private long getCountInner() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
Long val = new RedissonScript(connectionManager).eval( Long val = new RedissonScript(connectionManager).eval(
"return redis.call('get', KEYS[1])", "return redis.call('get', KEYS[1])",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys); Collections.<Object>singletonList(getName()));
if (val == null) { if (val == null) {
return 0; return 0;
@ -233,23 +230,19 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
} }
@Override @Override
public boolean trySetCount(final long count) { public boolean trySetCount(long count) {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"if redis.call('exists', KEYS[1]) == 0 then redis.call('set', KEYS[1], ARGV[2]); redis.call('publish', ARGV[3], ARGV[1]); return true else return false end", "if redis.call('exists', KEYS[1]) == 0 then redis.call('set', KEYS[1], ARGV[2]); redis.call('publish', ARGV[3], ARGV[1]); return true else return false end",
RScript.ReturnType.BOOLEAN, RScript.ReturnType.BOOLEAN,
keys, Collections.singletonList(newCountMessage), Arrays.asList(count, getChannelName())); Collections.<Object>singletonList(getName()), Collections.singletonList(newCountMessage), Arrays.asList(count, getChannelName()));
} }
@Override @Override
public boolean delete() { public boolean delete() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
Boolean deleted = new RedissonScript(connectionManager).evalR( Boolean deleted = new RedissonScript(connectionManager).evalR(
"if redis.call('del', KEYS[1]) == 1 then redis.call('publish', ARGV[2], ARGV[1]); return true else return false end", "if redis.call('del', KEYS[1]) == 1 then redis.call('publish', ARGV[2], ARGV[1]); return true else return false end",
RScript.ReturnType.BOOLEAN, RScript.ReturnType.BOOLEAN,
keys, Collections.singletonList(newCountMessage), Collections.singletonList(getChannelName())); Collections.<Object>singletonList(getName()), Collections.singletonList(newCountMessage), Collections.singletonList(getChannelName()));
if (!deleted) { if (!deleted) {
throw new IllegalStateException(); throw new IllegalStateException();
} }

@ -95,7 +95,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
public boolean add(V e) { public boolean add(V e) {
return addAll(Collections.singleton(e)); return addAll(Collections.singleton(e));
} }
@Override @Override
public Future<Boolean> addAsync(V e) { public Future<Boolean> addAsync(V e) {
return addAllAsync(Collections.singleton(e)); return addAllAsync(Collections.singleton(e));
@ -147,12 +147,12 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
public boolean addAll(Collection<? extends V> c) { public boolean addAll(Collection<? extends V> c) {
return connectionManager.get(addAllAsync(c)); return connectionManager.get(addAllAsync(c));
} }
@Override @Override
public Future<Boolean> addAllAsync(final Collection<? extends V> c) { public Future<Boolean> addAllAsync(final Collection<? extends V> c) {
if (c.isEmpty()) { if (c.isEmpty()) {
return connectionManager.getGroup().next().newSucceededFuture(false); return connectionManager.getGroup().next().newSucceededFuture(false);
} }
return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() { return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() {
@Override @Override
public void execute(final Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) { public void execute(final Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) {
@ -188,9 +188,6 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
// insert into middle of list // insert into middle of list
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return "OK".equals(new RedissonScript(connectionManager).evalR( return "OK".equals(new RedissonScript(connectionManager).evalR(
"local ind = table.remove(ARGV); " + // index is last parameter "local ind = table.remove(ARGV); " + // index is last parameter
"local tail = redis.call('lrange', KEYS[1], ind, -1); " + "local tail = redis.call('lrange', KEYS[1], ind, -1); " +
@ -199,7 +196,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
"for i, v in ipairs(tail) do redis.call('rpush', KEYS[1], v) end;" + "for i, v in ipairs(tail) do redis.call('rpush', KEYS[1], v) end;" +
"return 'OK'", "return 'OK'",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, new ArrayList<Object>(coll), Collections.singletonList(index))); Collections.<Object>singletonList(getName()), new ArrayList<Object>(coll), Collections.singletonList(index)));
} else { } else {
// append to list // append to list
return addAll(coll); return addAll(coll);
@ -260,7 +257,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
} }
}); });
} }
@Override @Override
public V get(int index) { public V get(int index) {
checkIndex(index); checkIndex(index);
@ -296,15 +293,14 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
public V set(final int index, final V element) { public V set(final int index, final V element) {
checkIndex(index); checkIndex(index);
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"local v = redis.call('lindex', KEYS[1], ARGV[2]); " + "local v = redis.call('lindex', KEYS[1], ARGV[2]); " +
"redis.call('lset', KEYS[1], ARGV[2], ARGV[1]); " + "redis.call('lset', KEYS[1], ARGV[2], ARGV[1]); " +
"return v", "return v",
RScript.ReturnType.VALUE, RScript.ReturnType.VALUE,
keys, Collections.singletonList(element), Collections.singletonList(index) Collections.<Object>singletonList(getName()),
Collections.singletonList(element),
Collections.singletonList(index)
); );
} }
@ -338,8 +334,6 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
}); });
} }
// else // else
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager).evalR( return new RedissonScript(connectionManager).evalR(
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " + "local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"local tail = redis.call('lrange', KEYS[1], ARGV[1]);" + "local tail = redis.call('lrange', KEYS[1], ARGV[1]);" +
@ -347,7 +341,7 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
"for i, v in ipairs(tail) do redis.call('rpush', KEYS[1], v) end;" + "for i, v in ipairs(tail) do redis.call('rpush', KEYS[1], v) end;" +
"return v", "return v",
RScript.ReturnType.VALUE, RScript.ReturnType.VALUE,
keys, Collections.emptyList(), Collections.singletonList(index)); Collections.<Object>singletonList(getName()), Collections.emptyList(), Collections.singletonList(index));
} }
@Override @Override
@ -356,14 +350,12 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
return -1; return -1;
} }
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
Long index = new RedissonScript(connectionManager).eval( Long index = new RedissonScript(connectionManager).eval(
"local s = redis.call('llen', KEYS[1]);" + "local s = redis.call('llen', KEYS[1]);" +
"for i = 0, s, 1 do if ARGV[1] == redis.call('lindex', KEYS[1], i) then return i end end;" + "for i = 0, s, 1 do if ARGV[1] == redis.call('lindex', KEYS[1], i) then return i end end;" +
"return -1", "return -1",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, o); Collections.<Object>singletonList(getName()), o);
return index.intValue(); return index.intValue();
} }
@ -373,14 +365,12 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
return -1; return -1;
} }
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
Long index = new RedissonScript(connectionManager).eval( Long index = new RedissonScript(connectionManager).eval(
"local s = redis.call('llen', KEYS[1]);" + "local s = redis.call('llen', KEYS[1]);" +
"for i = s, 0, -1 do if ARGV[1] == redis.call('lindex', KEYS[1], i) then return i end end;" + "for i = s, 0, -1 do if ARGV[1] == redis.call('lindex', KEYS[1], i) then return i end end;" +
"return -1", "return -1",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, o); Collections.<Object>singletonList(getName()), o);
return index.intValue(); return index.intValue();
} }

@ -221,6 +221,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
private Long tryLockInner() { private Long tryLockInner() {
Long ttlRemaining = tryLockInner(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS); Long ttlRemaining = tryLockInner(LOCK_EXPIRATION_INTERVAL_SECONDS, TimeUnit.SECONDS);
// lock acquired
if (ttlRemaining == null) { if (ttlRemaining == null) {
newRefreshTask(); newRefreshTask();
} }
@ -229,8 +230,9 @@ public class RedissonLock extends RedissonExpirable implements RLock {
private void newRefreshTask() { private void newRefreshTask() {
if (refreshTaskMap.containsKey(getName())) { if (refreshTaskMap.containsKey(getName())) {
return; return;
} }
Timeout task = connectionManager.newTimeout(new TimerTask() { Timeout task = connectionManager.newTimeout(new TimerTask() {
@Override @Override
public void run(Timeout timeout) throws Exception { public void run(Timeout timeout) throws Exception {
@ -239,6 +241,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
newRefreshTask(); // reschedule itself newRefreshTask(); // reschedule itself
} }
}, internalLockLeaseTime / 3, TimeUnit.MILLISECONDS); }, internalLockLeaseTime / 3, TimeUnit.MILLISECONDS);
if (refreshTaskMap.putIfAbsent(getName(), task) != null) { if (refreshTaskMap.putIfAbsent(getName(), task) != null) {
task.cancel(); task.cancel();
} }
@ -248,22 +251,17 @@ public class RedissonLock extends RedissonExpirable implements RLock {
* Stop refresh timer * Stop refresh timer
* @return true if timer was stopped successfully * @return true if timer was stopped successfully
*/ */
private boolean stopRefreshTask() { private void stopRefreshTask() {
boolean returnValue =false; Timeout task = refreshTaskMap.remove(getName());
Timeout task = refreshTaskMap.get(getName());
if (task != null) { if (task != null) {
returnValue = task.cancel(); task.cancel();
refreshTaskMap.remove(getName());
} }
return returnValue;
} }
private Long tryLockInner(final long leaseTime, final TimeUnit unit) { private Long tryLockInner(final long leaseTime, final TimeUnit unit) {
internalLockLeaseTime = unit.toMillis(leaseTime); internalLockLeaseTime = unit.toMillis(leaseTime);
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
return new RedissonScript(connectionManager) return new RedissonScript(connectionManager)
.evalR("local v = redis.call('get', KEYS[1]); " + .evalR("local v = redis.call('get', KEYS[1]); " +
"if (v == false) then " + "if (v == false) then " +
@ -278,7 +276,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
" return redis.call('pttl', KEYS[1]); " + " return redis.call('pttl', KEYS[1]); " +
"end", "end",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, Collections.singletonList(id.toString() + "-" + Thread.currentThread().getId()), Collections.singletonList(internalLockLeaseTime)); Collections.<Object>singletonList(getName()), Collections.singletonList(id.toString() + "-" + Thread.currentThread().getId()), Collections.singletonList(internalLockLeaseTime));
} }
public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException { public boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {
@ -340,8 +338,6 @@ public class RedissonLock extends RedissonExpirable implements RLock {
@Override @Override
public void unlock() { public void unlock() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
String opStatus = new RedissonScript(connectionManager) String opStatus = new RedissonScript(connectionManager)
.evalR("local v = redis.call('get', KEYS[1]); " + .evalR("local v = redis.call('get', KEYS[1]); " +
"if (v == false) then " + "if (v == false) then " +
@ -363,7 +359,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
" return nil; " + " return nil; " +
"end", "end",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, Arrays.asList(id.toString() + "-" + Thread.currentThread().getId(), unlockMessage), Arrays.asList(internalLockLeaseTime, getChannelName())); Collections.<Object>singletonList(getName()), Arrays.asList(id.toString() + "-" + Thread.currentThread().getId(), unlockMessage), Arrays.asList(internalLockLeaseTime, getChannelName()));
if ("OK".equals(opStatus)) { if ("OK".equals(opStatus)) {
stopRefreshTask(); stopRefreshTask();
} else if ("FALSE".equals(opStatus)) { } else if ("FALSE".equals(opStatus)) {
@ -383,13 +379,11 @@ public class RedissonLock extends RedissonExpirable implements RLock {
@Override @Override
public void forceUnlock() { public void forceUnlock() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
stopRefreshTask(); stopRefreshTask();
new RedissonScript(connectionManager) new RedissonScript(connectionManager)
.evalR("redis.call('del', KEYS[1]); redis.call('publish', ARGV[2], ARGV[1]); return 'OK'", .evalR("redis.call('del', KEYS[1]); redis.call('publish', ARGV[2], ARGV[1]); return 'OK'",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, Collections.singletonList(unlockMessage), Collections.singletonList(getChannelName())); Collections.<Object>singletonList(getName()), Collections.singletonList(unlockMessage), Collections.singletonList(getChannelName()));
} }
@Override @Override
@ -404,8 +398,6 @@ public class RedissonLock extends RedissonExpirable implements RLock {
@Override @Override
public boolean isHeldByCurrentThread() { public boolean isHeldByCurrentThread() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
String opStatus = new RedissonScript(connectionManager) String opStatus = new RedissonScript(connectionManager)
.eval("local v = redis.call('get', KEYS[1]); " + .eval("local v = redis.call('get', KEYS[1]); " +
"if (v == false) then " + "if (v == false) then " +
@ -419,14 +411,12 @@ public class RedissonLock extends RedissonExpirable implements RLock {
" end;" + " end;" +
"end", "end",
RScript.ReturnType.STATUS, RScript.ReturnType.STATUS,
keys, id.toString() + "-" + Thread.currentThread().getId()); Collections.<Object>singletonList(getName()), id.toString() + "-" + Thread.currentThread().getId());
return "OK".equals(opStatus); return "OK".equals(opStatus);
} }
@Override @Override
public int getHoldCount() { public int getHoldCount() {
ArrayList<Object> keys = new ArrayList<Object>();
keys.add(getName());
Long opStatus = new RedissonScript(connectionManager) Long opStatus = new RedissonScript(connectionManager)
.eval("local v = redis.call('get', KEYS[1]); " + .eval("local v = redis.call('get', KEYS[1]); " +
"if (v == false) then " + "if (v == false) then " +
@ -436,7 +426,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
" return o['c']; " + " return o['c']; " +
"end", "end",
RScript.ReturnType.INTEGER, RScript.ReturnType.INTEGER,
keys, id.toString() + "-" + Thread.currentThread().getId()); Collections.<Object>singletonList(getName()), id.toString() + "-" + Thread.currentThread().getId());
return opStatus.intValue(); return opStatus.intValue();
} }

Loading…
Cancel
Save