From 03246b95d667c1c26ab6ff141bd27ef13a32e31f Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 30 Jul 2015 11:13:43 +0300 Subject: [PATCH] RedissonList contains method speed optimization. #199 --- src/main/java/org/redisson/RedissonList.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/redisson/RedissonList.java b/src/main/java/org/redisson/RedissonList.java index 0cd9f0cbe..6525a5549 100644 --- a/src/main/java/org/redisson/RedissonList.java +++ b/src/main/java/org/redisson/RedissonList.java @@ -367,9 +367,15 @@ public class RedissonList extends RedissonExpirable implements RList { private Future indexOfAsync(Object o, Convertor convertor) { return commandExecutor.evalReadAsync(getName(), new RedisCommand("EVAL", convertor, 4), - "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;" + - "return -1", + "local key = KEYS[1] " + + "local obj = ARGV[1] " + + "local items = redis.call('lrange', key, 0, -1) " + + "for i=1,#items do " + + "if items[i] == obj then " + + "return i - 1 " + + "end " + + "end " + + "return -1", Collections.singletonList(getName()), o); }