From 1fd9aadd70e329fc42ea0b09f5af8a2b878fb462 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 24 Oct 2016 14:43:57 +0200 Subject: [PATCH] =?UTF-8?q?DATAREDIS-564=20-=20Delegate=20expire(=E2=80=A6?= =?UTF-8?q?)=20to=20pExpire=20if=20timeout=20exceeds=20Integer.MAX=5FVALUE?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove pExpireAt workaround that can lead to NullPointerException if called within a transaction/pipeline. Calls to expire(…) with a timeout greater Integer.MAX_VALUE are delegated to pExpire converting seconds to milliseconds. Related ticket: DATAREDIS-286. Original Pull Request: #228 --- .../connection/jedis/JedisConnection.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index a589fe837..3f2698e04 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -818,15 +818,10 @@ public class JedisConnection extends AbstractRedisConnection { public Boolean expire(byte[] key, long seconds) { - /* - * @see DATAREDIS-286 to avoid overflow in Jedis - * - * TODO Remove this workaround when we upgrade to a Jedis version that contains a - * fix for: https://github.com/xetorthio/jedis/pull/575 - */ - if (seconds > Integer.MAX_VALUE) { + Assert.notNull(key, "Key must not be null!"); - return pExpireAt(key, time() + TimeUnit.SECONDS.toMillis(seconds)); + if (seconds > Integer.MAX_VALUE) { + return pExpire(key, TimeUnit.SECONDS.toMillis(seconds)); } try { @@ -845,6 +840,9 @@ public class JedisConnection extends AbstractRedisConnection { } public Boolean expireAt(byte[] key, long unixTime) { + + Assert.notNull(key, "Key must not be null!"); + try { if (isPipelined()) { pipeline(new JedisResult(pipeline.expireAt(key, unixTime), JedisConverters.longToBoolean())); @@ -1038,6 +1036,8 @@ public class JedisConnection extends AbstractRedisConnection { } public Boolean pExpire(byte[] key, long millis) { + + Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { @@ -1055,6 +1055,9 @@ public class JedisConnection extends AbstractRedisConnection { } public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { + + Assert.notNull(key, "Key must not be null!"); + try { if (isPipelined()) { pipeline(new JedisResult(pipeline.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean()));