From 3b55731b7bf4c46c7a88baf653355ed7f1f83641 Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Wed, 1 Jun 2011 23:54:31 -0400 Subject: [PATCH] Pipeline commands should not throw an exception when a key is unset --- .../redis/clients/jedis/BuilderFactory.java | 13 +++------- .../clients/jedis/tests/PipeliningTest.java | 26 +++++++++++-------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 998ee784d1..ad94282040 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -1,16 +1,9 @@ package redis.clients.jedis; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import redis.clients.util.SafeEncoder; +import java.util.*; + public class BuilderFactory { public static final Builder DOUBLE = new Builder() { public Double build(Object data) { @@ -52,7 +45,7 @@ public String toString() { }; public static final Builder STRING = new Builder() { public String build(Object data) { - return SafeEncoder.encode((byte[]) data); + return data == null ? null : SafeEncoder.encode((byte[]) data); } public String toString() { diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 4ab50b0180..82d28a4607 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -1,22 +1,18 @@ package redis.clients.jedis.tests; -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.Pipeline; -import redis.clients.jedis.PipelineBlock; -import redis.clients.jedis.Response; -import redis.clients.jedis.Tuple; +import redis.clients.jedis.*; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + public class PipeliningTest extends Assert { private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0); @@ -114,4 +110,12 @@ public void pipelineWithPubSub() { assertEquals(0, p1.get().longValue()); assertEquals(0, p2.get().longValue()); } + + @Test + public void canRetrieveUnsetKey() { + Pipeline p = jedis.pipelined(); + Response shouldNotExist = p.get(UUID.randomUUID().toString()); + p.sync(); + assertNull(shouldNotExist.get()); + } } \ No newline at end of file