DATAREDIS-705 - Polishing.
Change return type for mset from void to Boolean. Add missing Nullable annotations. Add Javadoc. Disable flakey tests for now. Related pull request: #279.
This commit is contained in:
@@ -715,8 +715,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void mSet(Map<byte[], byte[]> tuple) {
|
||||
delegate.mSet(tuple);
|
||||
public Boolean mSet(Map<byte[], byte[]> tuple) {
|
||||
return delegate.mSet(tuple);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2096,8 +2096,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#mSetString(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void mSetString(Map<String, String> tuple) {
|
||||
delegate.mSet(serialize(tuple));
|
||||
public Boolean mSetString(Map<String, String> tuple) {
|
||||
return delegate.mSet(serialize(tuple));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2231,8 +2231,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#set(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void set(String key, String value) {
|
||||
delegate.set(serialize(key), serialize(value));
|
||||
public Boolean set(String key, String value) {
|
||||
return delegate.set(serialize(key), serialize(value));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2240,8 +2240,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#set(java.lang.String, java.lang.String, org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOptions)
|
||||
*/
|
||||
@Override
|
||||
public void set(String key, String value, Expiration expiration, SetOption option) {
|
||||
set(serialize(key), serialize(value), expiration, option);
|
||||
public Boolean set(String key, String value, Expiration expiration, SetOption option) {
|
||||
return set(serialize(key), serialize(value), expiration, option);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2258,8 +2258,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#setEx(java.lang.String, long, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setEx(String key, long seconds, String value) {
|
||||
delegate.setEx(serialize(key), seconds, serialize(value));
|
||||
public Boolean setEx(String key, long seconds, String value) {
|
||||
return delegate.setEx(serialize(key), seconds, serialize(value));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2267,8 +2267,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#pSetEx(java.lang.String, long, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void pSetEx(String key, long seconds, String value) {
|
||||
pSetEx(serialize(key), seconds, serialize(value));
|
||||
public Boolean pSetEx(String key, long seconds, String value) {
|
||||
return pSetEx(serialize(key), seconds, serialize(value));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -256,14 +256,14 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
@Override
|
||||
@Deprecated
|
||||
default Boolean pSetEx(byte[] key, long milliseconds, byte[] value) {
|
||||
return stringCommands().pSetEx(key, milliseconds, value);
|
||||
return stringCommands().pSetEx(key, milliseconds, value);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default void mSet(Map<byte[], byte[]> tuple) {
|
||||
stringCommands().mSet(tuple);
|
||||
default Boolean mSet(Map<byte[], byte[]> tuple) {
|
||||
return stringCommands().mSet(tuple);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
|
||||
|
||||
@@ -70,8 +70,10 @@ public interface RedisStringCommands {
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param value must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
@Nullable
|
||||
Boolean set(byte[] key, byte[] value);
|
||||
|
||||
/**
|
||||
@@ -82,9 +84,11 @@ public interface RedisStringCommands {
|
||||
* @param value must not be {@literal null}.
|
||||
* @param expiration must not be {@literal null}. Use {@link Expiration#persistent()} to not set any ttl.
|
||||
* @param option must not be {@literal null}. Use {@link SetOption#upsert()} to add non existing.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 1.7
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
@Nullable
|
||||
Boolean set(byte[] key, byte[] value, Expiration expiration, SetOption option);
|
||||
|
||||
/**
|
||||
@@ -104,8 +108,10 @@ public interface RedisStringCommands {
|
||||
* @param key must not be {@literal null}.
|
||||
* @param seconds
|
||||
* @param value must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="http://redis.io/commands/setex">Redis Documentation: SETEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Boolean setEx(byte[] key, long seconds, byte[] value);
|
||||
|
||||
/**
|
||||
@@ -114,18 +120,22 @@ public interface RedisStringCommands {
|
||||
* @param key must not be {@literal null}.
|
||||
* @param milliseconds
|
||||
* @param value must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 1.3
|
||||
* @see <a href="http://redis.io/commands/psetex">Redis Documentation: PSETEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Boolean pSetEx(byte[] key, long milliseconds, byte[] value);
|
||||
|
||||
/**
|
||||
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple}.
|
||||
*
|
||||
* @param tuple must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="http://redis.io/commands/mset">Redis Documentation: MSET</a>
|
||||
*/
|
||||
void mSet(Map<byte[], byte[]> tuple);
|
||||
@Nullable
|
||||
Boolean mSet(Map<byte[], byte[]> tuple);
|
||||
|
||||
/**
|
||||
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple} only if the provided key does
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Convenience extension of {@link RedisConnection} that accepts and returns {@link String}s instead of byte arrays.
|
||||
@@ -324,7 +325,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
* @see RedisStringCommands#set(byte[], byte[])
|
||||
*/
|
||||
void set(String key, String value);
|
||||
@Nullable
|
||||
Boolean set(String key, String value);
|
||||
|
||||
/**
|
||||
* Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values
|
||||
@@ -338,7 +340,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
* @see RedisStringCommands#set(byte[], byte[], Expiration, SetOption)
|
||||
*/
|
||||
void set(String key, String value, Expiration expiration, SetOption option);
|
||||
@Nullable
|
||||
Boolean set(String key, String value, Expiration expiration, SetOption option);
|
||||
|
||||
/**
|
||||
* Set {@code value} for {@code key}, only if {@code key} does not exist.
|
||||
@@ -349,6 +352,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/setnx">Redis Documentation: SETNX</a>
|
||||
* @see RedisStringCommands#setNX(byte[], byte[])
|
||||
*/
|
||||
@Nullable
|
||||
Boolean setNX(String key, String value);
|
||||
|
||||
/**
|
||||
@@ -360,7 +364,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/setex">Redis Documentation: SETEX</a>
|
||||
* @see RedisStringCommands#setEx(byte[], long, byte[])
|
||||
*/
|
||||
void setEx(String key, long seconds, String value);
|
||||
@Nullable
|
||||
Boolean setEx(String key, long seconds, String value);
|
||||
|
||||
/**
|
||||
* Set the {@code value} and expiration in {@code milliseconds} for {@code key}.
|
||||
@@ -372,7 +377,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/psetex">Redis Documentation: PSETEX</a>
|
||||
* @see RedisStringCommands#pSetEx(byte[], long, byte[])
|
||||
*/
|
||||
void pSetEx(String key, long milliseconds, String value);
|
||||
@Nullable
|
||||
Boolean pSetEx(String key, long milliseconds, String value);
|
||||
|
||||
/**
|
||||
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple}.
|
||||
@@ -381,7 +387,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="http://redis.io/commands/mset">Redis Documentation: MSET</a>
|
||||
* @see RedisStringCommands#mSet(Map)
|
||||
*/
|
||||
void mSetString(Map<String, String> tuple);
|
||||
@Nullable
|
||||
Boolean mSetString(Map<String, String> tuple);
|
||||
|
||||
/**
|
||||
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple} only if the provided key does
|
||||
|
||||
@@ -224,22 +224,25 @@ class JedisClusterStringCommands implements RedisStringCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void mSet(Map<byte[], byte[]> tuples) {
|
||||
public Boolean mSet(Map<byte[], byte[]> tuples) {
|
||||
|
||||
Assert.notNull(tuples, "Tuples must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(tuples.keySet().toArray(new byte[tuples.keySet().size()][]))) {
|
||||
try {
|
||||
connection.getCluster().mset(JedisConverters.toByteArrays(tuples));
|
||||
return;
|
||||
return Converters.stringToBoolean(connection.getCluster().mset(JedisConverters.toByteArrays(tuples)));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = true;
|
||||
for (Map.Entry<byte[], byte[]> entry : tuples.entrySet()) {
|
||||
set(entry.getKey(), entry.getValue());
|
||||
if (!set(entry.getKey(), entry.getValue())) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -324,22 +324,23 @@ class JedisStringCommands implements RedisStringCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void mSet(Map<byte[], byte[]> tuples) {
|
||||
public Boolean mSet(Map<byte[], byte[]> tuples) {
|
||||
|
||||
Assert.notNull(tuples, "Tuples must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(
|
||||
connection.newStatusResult(connection.getRequiredPipeline().mset(JedisConverters.toByteArrays(tuples))));
|
||||
return;
|
||||
pipeline(connection.newStatusResult(connection.getRequiredPipeline().mset(JedisConverters.toByteArrays(tuples)),
|
||||
Converters.stringToBooleanConverter()));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(
|
||||
connection.newStatusResult(connection.getRequiredTransaction().mset(JedisConverters.toByteArrays(tuples))));
|
||||
return;
|
||||
connection.newStatusResult(connection.getRequiredTransaction().mset(JedisConverters.toByteArrays(tuples)),
|
||||
Converters.stringToBooleanConverter()));
|
||||
return null;
|
||||
}
|
||||
connection.getJedis().mset(JedisConverters.toByteArrays(tuples));
|
||||
return Converters.stringToBoolean(connection.getJedis().mset(JedisConverters.toByteArrays(tuples)));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -253,20 +253,22 @@ class LettuceStringCommands implements RedisStringCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void mSet(Map<byte[], byte[]> tuples) {
|
||||
public Boolean mSet(Map<byte[], byte[]> tuples) {
|
||||
|
||||
Assert.notNull(tuples, "Tuples must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceStatusResult(getAsyncConnection().mset(tuples)));
|
||||
return;
|
||||
pipeline(connection.newLettuceStatusResult(getAsyncConnection().mset(tuples),
|
||||
Converters.stringToBooleanConverter()));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceTxStatusResult(getConnection().mset(tuples)));
|
||||
return;
|
||||
transaction(
|
||||
connection.newLettuceTxStatusResult(getConnection().mset(tuples), Converters.stringToBooleanConverter()));
|
||||
return null;
|
||||
}
|
||||
getConnection().mset(tuples);
|
||||
return Converters.stringToBoolean(getConnection().mset(tuples));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user