From 4a1681629df1058abe8931fe5ec8243711e5d58f Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 11 Feb 2020 14:20:21 +0300 Subject: [PATCH] refactoring --- .../org/redisson/RedissonPriorityQueue.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java b/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java index 3f7b8279f..66256d460 100644 --- a/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java +++ b/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java @@ -102,8 +102,6 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); - - loadComparator(); } public RedissonPriorityQueue(Codec codec, CommandExecutor commandExecutor, String name, RedissonClient redisson) { @@ -112,8 +110,6 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); - - loadComparator(); } private void loadComparator() { @@ -131,6 +127,8 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori Class clazz = Class.forName(className); comparator = (Comparator) clazz.newInstance(); + } else { + throw new IllegalStateException("Comparator is not set!"); } } catch (IllegalStateException e) { throw e; @@ -166,6 +164,7 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori @Override public boolean contains(Object o) { + checkComparator(); return binarySearch((V) o, codec).getIndex() >= 0; } @@ -232,8 +231,9 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori @Override public boolean containsAll(Collection c) { + checkComparator(); for (Object object : c) { - if (!contains(object)) { + if (binarySearch((V) object, codec).getIndex() < 0) { return false; } } @@ -355,14 +355,7 @@ public class RedissonPriorityQueue extends RedissonList implements RPriori String className = comparator.getClass().getName(); String comparatorSign = className + ":" + calcClassSign(className); - Boolean res = commandExecutor.evalWrite(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, - "if redis.call('llen', KEYS[1]) == 0 then " - + "redis.call('set', KEYS[2], ARGV[1]); " - + "return 1; " - + "else " - + "return 0; " - + "end", - Arrays.asList(getName(), getComparatorKeyName()), comparatorSign); + Boolean res = get(commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.SETNX, getComparatorKeyName(), comparatorSign)); if (res) { this.comparator = comparator; } -- GitLab