From 25ed6d59bbe26363dd1f9e37739d0b45944d6b63 Mon Sep 17 00:00:00 2001 From: Nikita Date: Sun, 7 Feb 2016 13:45:02 +0300 Subject: [PATCH] Script error fixed during RSetCache.toArray or RSetCache.readAll invocation. --- src/main/java/org/redisson/RedissonSetCache.java | 14 ++++++++++---- .../java/org/redisson/RedissonSetCacheTest.java | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/redisson/RedissonSetCache.java b/src/main/java/org/redisson/RedissonSetCache.java index ecc358281..42726bafb 100644 --- a/src/main/java/org/redisson/RedissonSetCache.java +++ b/src/main/java/org/redisson/RedissonSetCache.java @@ -230,7 +230,10 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< public Future> readAllAsync() { return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_SET, "local expireHead = redis.call('zrange', KEYS[2], 0, 0, 'withscores');" + - "local keys = redis.call('hkeys', KEYS[1]);" + + "local keys = redis.call('hkeys', KEYS[1]); " + + "if #keys == 0 then " + + "return {}; " + + "end; " + "local maxDate = ARGV[1]; " + "local minExpireDate = 92233720368547758;" + "if #expireHead == 2 and tonumber(expireHead[2]) <= tonumber(maxDate) then " + @@ -250,7 +253,10 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< private Future> readAllasListAsync() { return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_LIST, "local expireHead = redis.call('zrange', KEYS[2], 0, 0, 'withscores');" + - "local keys = redis.call('hkeys', KEYS[1]);" + + "local keys = redis.call('hkeys', KEYS[1]); " + + "if #keys == 0 then " + + "return {}; " + + "end; " + "local maxDate = ARGV[1]; " + "local minExpireDate = 92233720368547758;" + "if #expireHead == 2 and tonumber(expireHead[2]) <= tonumber(maxDate) then " + @@ -310,8 +316,8 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); " + "if redis.call('hexists', KEYS[1], ARGV[3]) == 0 then " + - "redis.call('hset', KEYS[1], ARGV[3], ARGV[2]); " + - "return 1; " + + "redis.call('hset', KEYS[1], ARGV[3], ARGV[2]); " + + "return 1; " + "end;" + "return 0; ", Arrays.asList(getName(), getTimeoutSetName()), timeoutDate, objectState, key); diff --git a/src/test/java/org/redisson/RedissonSetCacheTest.java b/src/test/java/org/redisson/RedissonSetCacheTest.java index 9e5532ab0..69acd3519 100644 --- a/src/test/java/org/redisson/RedissonSetCacheTest.java +++ b/src/test/java/org/redisson/RedissonSetCacheTest.java @@ -32,6 +32,12 @@ public class RedissonSetCacheTest extends BaseTest { } + @Test + public void testEmptyReadAll() { + RSetCache set = redisson.getSetCache("set"); + assertThat(set.readAll()).isEmpty(); + } + @Test public void testAddBean() throws InterruptedException, ExecutionException { SimpleBean sb = new SimpleBean();