From b01b18fdc628db67ed2dea271feedc1041efe50f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 28 Jun 2019 12:56:55 +0200 Subject: [PATCH] DATAREDIS-793 - Use GETRANGE instead of SUBSTR command. We now use GETRANGE with the Jedis client instead of the deprecated SUBSTR command. This allows us to natively use long values for start/end and removes the need for String/byte conversion on command level. --- .../connection/jedis/JedisStringCommands.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java index bc401a4a9..90d291a0b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java @@ -198,7 +198,7 @@ class JedisStringCommands implements RedisStringCommands { } } else { - SetParams params = JedisConverters.toSetCommandNxXxArgument(option, null); + SetParams params = JedisConverters.toSetCommandNxXxArgument(option, null); JedisConverters.toSetCommandExPxArgument(expiration, params); try { @@ -210,8 +210,7 @@ class JedisStringCommands implements RedisStringCommands { "Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis."); } - pipeline(connection.newJedisResult( - connection.getRequiredPipeline().set(key, value, params), + pipeline(connection.newJedisResult(connection.getRequiredPipeline().set(key, value, params), Converters.stringToBooleanConverter(), () -> false)); return null; } @@ -222,8 +221,7 @@ class JedisStringCommands implements RedisStringCommands { "Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis."); } - transaction(connection.newJedisResult( - connection.getRequiredTransaction().set(key, value, params), + transaction(connection.newJedisResult(connection.getRequiredTransaction().set(key, value, params), Converters.stringToBooleanConverter(), () -> false)); return null; } @@ -534,22 +532,16 @@ class JedisStringCommands implements RedisStringCommands { Assert.notNull(key, "Key must not be null!"); - if (start > Integer.MAX_VALUE || end > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Start and end must be less than Integer.MAX_VALUE for getRange in Jedis."); - } - try { if (isPipelined()) { - pipeline(connection.newJedisResult(connection.getRequiredPipeline().substr(key, (int) start, (int) end), - JedisConverters.stringToBytes())); + pipeline(connection.newJedisResult(connection.getRequiredPipeline().getrange(key, start, end))); return null; } if (isQueueing()) { - transaction(connection.newJedisResult(connection.getRequiredTransaction().substr(key, (int) start, (int) end), - JedisConverters.stringToBytes())); + transaction(connection.newJedisResult(connection.getRequiredTransaction().getrange(key, start, end))); return null; } - return connection.getJedis().substr(key, (int) start, (int) end); + return connection.getJedis().getrange(key, start, end); } catch (Exception ex) { throw convertJedisAccessException(ex); }