From a1b6811b734338366073982fce8077d13695941c Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 30 May 2016 14:47:09 +0300 Subject: [PATCH] RedissonSortedSet refactoring --- .../java/org/redisson/RedissonSortedSet.java | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/redisson/RedissonSortedSet.java b/src/main/java/org/redisson/RedissonSortedSet.java index 920f0fa31..b77c8b0a8 100644 --- a/src/main/java/org/redisson/RedissonSortedSet.java +++ b/src/main/java/org/redisson/RedissonSortedSet.java @@ -362,22 +362,19 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet)conn.sync(codec, RedisCommands.EXEC)).size() == 1) { - return true; - } + } else { + conn.sync(RedisCommands.EVAL_VOID, + "local len = redis.call('llen', KEYS[1]);" + + "local tail = redis.call('lrange', KEYS[1], tonumber(ARGV[1]) + 1, len);" + + "redis.call('ltrim', KEYS[1], 0, tonumber(ARGV[1]) - 1);" + + "if #tail > 0 then " + + "redis.call('rpush', KEYS[1], unpack(tail)); " + + "end;", 1, getName(), res.getIndex()); } - conn.sync(RedisCommands.MULTI); - conn.sync(RedisCommands.EVAL_VOID, - "local len = redis.call('llen', KEYS[1]);" - + "local tail = redis.call('lrange', KEYS[1], tonumber(ARGV[1]) + 1, len);" - + "redis.call('ltrim', KEYS[1], 0, tonumber(ARGV[1]) - 1);" - + "if #tail > 0 then " - + "redis.call('rpush', KEYS[1], unpack(tail)); " - + "end;", 1, getName(), res.getIndex()); if (((List)conn.sync(codec, RedisCommands.EXEC)).size() == 1) { return true; } @@ -473,10 +470,6 @@ public class RedissonSortedSet extends RedissonObject implements RSortedSet extends RedissonObject implements RSortedSet res = binarySearch(value, connection); -// if (res.getIndex() < 0) { -// V element = getAtIndex(-res.getIndex() + indexDiff, connection); -// if (element.getScore() == null && res.getScore() == null && tail) { -// element = getAtIndex(-res.getIndex() - 2, connection); -// return element.getScore(); -// } -// return element.getScore(); -// } -// int ind = res.getIndex(); -// if (tail) { -// ind = res.getIndex() - indexDiff; -// } -// BinarySearchResult element = getAtIndex(ind, connection); -// return element.getScore(); - } - public String toString() { Iterator it = iterator(); if (! it.hasNext())