diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
index 562afdf48..31344f2c4 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java
@@ -913,8 +913,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[])
*/
@Override
- public void set(byte[] key, byte[] value) {
- delegate.set(key, value);
+ public Boolean set(byte[] key, byte[] value) {
+ return delegate.set(key, value);
}
/*
@@ -922,8 +922,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOptions)
*/
@Override
- public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
- delegate.set(key, value, expiration, option);
+ public Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
+ return delegate.set(key, value, expiration, option);
}
/*
@@ -949,8 +949,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisStringCommands#setEx(byte[], long, byte[])
*/
@Override
- public void setEx(byte[] key, long seconds, byte[] value) {
- delegate.setEx(key, seconds, value);
+ public Boolean setEx(byte[] key, long seconds, byte[] value) {
+ return delegate.setEx(key, seconds, value);
}
/*
@@ -958,8 +958,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
- public void pSetEx(byte[] key, long milliseconds, byte[] value) {
- delegate.pSetEx(key, milliseconds, value);
+ public Boolean pSetEx(byte[] key, long milliseconds, byte[] value) {
+ return delegate.pSetEx(key, milliseconds, value);
}
/*
diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
index 6f3abb5e2..526bb3d4c 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
@@ -227,15 +227,15 @@ public interface DefaultedRedisConnection extends RedisConnection {
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
- default void set(byte[] key, byte[] value) {
- stringCommands().set(key, value);
+ default Boolean set(byte[] key, byte[] value) {
+ return stringCommands().set(key, value);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
- default void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
- stringCommands().set(key, value, expiration, option);
+ default Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
+ return stringCommands().set(key, value, expiration, option);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@@ -248,15 +248,15 @@ public interface DefaultedRedisConnection extends RedisConnection {
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
- default void setEx(byte[] key, long seconds, byte[] value) {
- stringCommands().setEx(key, seconds, value);
+ default Boolean setEx(byte[] key, long seconds, byte[] value) {
+ return stringCommands().setEx(key, seconds, value);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
- default void pSetEx(byte[] key, long milliseconds, byte[] value) {
- stringCommands().pSetEx(key, milliseconds, value);
+ default Boolean pSetEx(byte[] key, long milliseconds, byte[] value) {
+ return stringCommands().pSetEx(key, milliseconds, value);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisStringCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisStringCommands.java
index 172b64680..fc7217c82 100644
--- a/src/main/java/org/springframework/data/redis/connection/RedisStringCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/RedisStringCommands.java
@@ -72,7 +72,7 @@ public interface RedisStringCommands {
* @param value must not be {@literal null}.
* @see Redis Documentation: SET
*/
- void set(byte[] key, byte[] value);
+ Boolean set(byte[] key, byte[] value);
/**
* Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values
@@ -85,7 +85,7 @@ public interface RedisStringCommands {
* @since 1.7
* @see Redis Documentation: SET
*/
- void set(byte[] key, byte[] value, Expiration expiration, SetOption option);
+ Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option);
/**
* Set {@code value} for {@code key}, only if {@code key} does not exist.
@@ -106,7 +106,7 @@ public interface RedisStringCommands {
* @param value must not be {@literal null}.
* @see Redis Documentation: SETEX
*/
- void setEx(byte[] key, long seconds, byte[] value);
+ Boolean setEx(byte[] key, long seconds, byte[] value);
/**
* Set the {@code value} and expiration in {@code milliseconds} for {@code key}.
@@ -117,7 +117,7 @@ public interface RedisStringCommands {
* @since 1.3
* @see Redis Documentation: PSETEX
*/
- void pSetEx(byte[] key, long milliseconds, byte[] value);
+ Boolean pSetEx(byte[] key, long milliseconds, byte[] value);
/**
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple}.
diff --git a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java
index 3eff9d305..04b6fd8cf 100644
--- a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java
+++ b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java
@@ -193,7 +193,11 @@ abstract public class Converters {
}
public static Boolean stringToBoolean(String s) {
- return ObjectUtils.nullSafeEquals("OK", s);
+ return stringToBooleanConverter().convert(s);
+ }
+
+ public static Converter stringToBooleanConverter() {
+ return (source) -> ObjectUtils.nullSafeEquals("OK", source);
}
public static Converter stringToProps() {
diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterStringCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterStringCommands.java
index 6692fdebf..c692b41ce 100644
--- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterStringCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterStringCommands.java
@@ -24,6 +24,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.RedisStringCommands;
+import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterCommandCallback;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisMultiKeyClusterCommandCallback;
import org.springframework.data.redis.core.types.Expiration;
@@ -102,13 +103,13 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[])
*/
@Override
- public void set(byte[] key, byte[] value) {
+ public Boolean set(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
- connection.getCluster().set(key, value);
+ return Converters.stringToBoolean(connection.getCluster().set(key, value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -119,7 +120,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOptions)
*/
@Override
- public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
+ public Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
@@ -129,7 +130,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
if (expiration == null || expiration.isPersistent()) {
if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
- set(key, value);
+ return set(key, value);
} else {
// BinaryCluster does not support set with nxxx and binary key/value pairs.
@@ -137,16 +138,16 @@ class JedisClusterStringCommands implements RedisStringCommands {
throw new UnsupportedOperationException("Jedis does not support SET XX without PX or EX on BinaryCluster.");
}
- setNX(key, value);
+ return setNX(key, value);
}
} else {
if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) {
- pSetEx(key, expiration.getExpirationTime(), value);
+ return pSetEx(key, expiration.getExpirationTime(), value);
} else {
- setEx(key, expiration.getExpirationTime(), value);
+ return setEx(key, expiration.getExpirationTime(), value);
}
} else {
@@ -154,7 +155,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
byte[] expx = JedisConverters.toSetCommandExPxArgument(expiration);
try {
- connection.getCluster().set(key, value, nxxx, expx, expiration.getExpirationTime());
+ return Converters
+ .stringToBoolean(connection.getCluster().set(key, value, nxxx, expx, expiration.getExpirationTime()));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -184,7 +186,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#setEx(byte[], long, byte[])
*/
@Override
- public void setEx(byte[] key, long seconds, byte[] value) {
+ public Boolean setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
@@ -194,7 +196,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
}
try {
- connection.getCluster().setex(key, Long.valueOf(seconds).intValue(), value);
+ return Converters.stringToBoolean(connection.getCluster().setex(key, Long.valueOf(seconds).intValue(), value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -205,14 +207,16 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
- public void pSetEx(byte[] key, long milliseconds, byte[] value) {
+ public Boolean pSetEx(byte[] key, long milliseconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
- connection.getClusterCommandExecutor().executeCommandOnSingleNode(
- (JedisClusterCommandCallback) client -> client.psetex(key, milliseconds, value),
- connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
+ return Converters.stringToBoolean(connection.getClusterCommandExecutor()
+ .executeCommandOnSingleNode(
+ (JedisClusterCommandCallback) client -> client.psetex(key, milliseconds, value),
+ connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
+ .getValue());
}
/*
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 4a7e51eac..1ee1e844a 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
@@ -142,6 +142,11 @@ public class JedisConnection extends AbstractRedisConnection {
super(resultHolder);
setStatus(true);
}
+
+ public JedisStatusResult(Response resultHolder, Converter converter) {
+ super(resultHolder, converter);
+ setStatus(true);
+ }
}
/**
@@ -647,6 +652,10 @@ public class JedisConnection extends AbstractRedisConnection {
return new JedisStatusResult(response);
}
+ JedisStatusResult newStatusResult(Response response, Converter converter) {
+ return new JedisStatusResult(response, converter);
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisTxCommands#multi()
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 a6c4f5786..ca7493221 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
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.data.redis.connection.RedisStringCommands;
+import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.jedis.JedisConnection.JedisResult;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.util.Assert;
@@ -118,21 +119,23 @@ class JedisStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[])
*/
@Override
- public void set(byte[] key, byte[] value) {
+ public Boolean set(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
- pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value)));
- return;
+ pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
if (isQueueing()) {
- transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value)));
- return;
+ transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
- connection.getJedis().set(key, value);
+ return Converters.stringToBoolean(connection.getJedis().set(key, value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -143,7 +146,7 @@ class JedisStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOption)
*/
@Override
- public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
+ public Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
@@ -153,7 +156,7 @@ class JedisStringCommands implements RedisStringCommands {
if (expiration.isPersistent()) {
if (ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
- set(key, value);
+ return set(key, value);
} else {
try {
@@ -162,16 +165,18 @@ class JedisStringCommands implements RedisStringCommands {
if (isPipelined()) {
- pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value, nxxx)));
- return;
+ pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value, nxxx),
+ Converters.stringToBooleanConverter()));
+ return null;
}
if (isQueueing()) {
- transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value, nxxx)));
- return;
+ transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value, nxxx),
+ Converters.stringToBooleanConverter()));
+ return null;
}
- connection.getJedis().set(key, value, nxxx);
+ return Converters.stringToBoolean(connection.getJedis().set(key, value, nxxx));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -182,9 +187,9 @@ class JedisStringCommands implements RedisStringCommands {
if (ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) {
- pSetEx(key, expiration.getExpirationTime(), value);
+ return pSetEx(key, expiration.getExpirationTime(), value);
} else {
- setEx(key, expiration.getExpirationTime(), value);
+ return setEx(key, expiration.getExpirationTime(), value);
}
} else {
@@ -201,8 +206,9 @@ class JedisStringCommands implements RedisStringCommands {
}
pipeline(connection.newStatusResult(
- connection.getRequiredPipeline().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
- return;
+ connection.getRequiredPipeline().set(key, value, nxxx, expx, (int) expiration.getExpirationTime()),
+ Converters.stringToBooleanConverter()));
+ return null;
}
if (isQueueing()) {
@@ -212,11 +218,13 @@ class JedisStringCommands implements RedisStringCommands {
}
transaction(connection.newStatusResult(
- connection.getRequiredTransaction().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
- return;
+ connection.getRequiredTransaction().set(key, value, nxxx, expx, (int) expiration.getExpirationTime()),
+ Converters.stringToBooleanConverter()));
+ return null;
}
- connection.getJedis().set(key, value, nxxx, expx, expiration.getExpirationTime());
+ return Converters
+ .stringToBoolean(connection.getJedis().set(key, value, nxxx, expx, expiration.getExpirationTime()));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
@@ -258,7 +266,7 @@ class JedisStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#setEx(byte[], long, byte[])
*/
@Override
- public void setEx(byte[] key, long seconds, byte[] value) {
+ public Boolean setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
@@ -269,14 +277,16 @@ class JedisStringCommands implements RedisStringCommands {
try {
if (isPipelined()) {
- pipeline(connection.newStatusResult(connection.getRequiredPipeline().setex(key, (int) seconds, value)));
- return;
+ pipeline(connection.newStatusResult(connection.getRequiredPipeline().setex(key, (int) seconds, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
if (isQueueing()) {
- transaction(connection.newStatusResult(connection.getRequiredTransaction().setex(key, (int) seconds, value)));
- return;
+ transaction(connection.newStatusResult(connection.getRequiredTransaction().setex(key, (int) seconds, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
- connection.getJedis().setex(key, (int) seconds, value);
+ return Converters.stringToBoolean(connection.getJedis().setex(key, (int) seconds, value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -287,21 +297,23 @@ class JedisStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
- public void pSetEx(byte[] key, long milliseconds, byte[] value) {
+ public Boolean pSetEx(byte[] key, long milliseconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
- pipeline(connection.newStatusResult(connection.getRequiredPipeline().psetex(key, milliseconds, value)));
- return;
+ pipeline(connection.newStatusResult(connection.getRequiredPipeline().psetex(key, milliseconds, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
if (isQueueing()) {
- transaction(connection.newStatusResult(connection.getRequiredTransaction().psetex(key, milliseconds, value)));
- return;
+ transaction(connection.newStatusResult(connection.getRequiredTransaction().psetex(key, milliseconds, value),
+ Converters.stringToBooleanConverter()));
+ return null;
}
- connection.getJedis().psetex(key, milliseconds, value);
+ return Converters.stringToBoolean(connection.getJedis().psetex(key, milliseconds, value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
index c712eee1d..9d028dbbd 100644
--- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
@@ -144,16 +144,25 @@ public class LettuceConnection extends AbstractRedisConnection {
private class LettuceStatusResult extends LettuceResult {
@SuppressWarnings("rawtypes")
- public LettuceStatusResult(Future resultHolder) {
+ LettuceStatusResult(Future resultHolder) {
super(resultHolder);
setStatus(true);
}
+
+ LettuceStatusResult(Future resultHolder, Converter converter) {
+ super(resultHolder, converter);
+ setStatus(true);
+ }
}
LettuceStatusResult newLettuceStatusResult(Future> resultHolder) {
return new LettuceStatusResult(resultHolder);
}
+ LettuceStatusResult newLettuceStatusResult(Future resultHolder, Converter converter) {
+ return new LettuceStatusResult(resultHolder, converter);
+ }
+
class LettuceTxResult extends FutureResult