Polishing.

Reformat code. Reduce visibility, simplify code.

Original Pull Request: #2287
This commit is contained in:
Mark Paluch
2022-03-08 14:01:55 +01:00
committed by Christoph Strobl
parent 1e4cd6f341
commit f232a5b3fe
31 changed files with 151 additions and 379 deletions

View File

@@ -58,9 +58,8 @@ import org.springframework.util.StringUtils;
* @author Mark Paluch
* @author Christoph Strobl
*/
abstract public class Converters {
public abstract class Converters {
// private static final Log LOGGER = LogFactory.getLog(Converters.class);
private static final Log LOGGER = LogFactory.getLog(Converters.class);
private static final byte[] ONE = new byte[] { '1' };

View File

@@ -15,21 +15,13 @@
*/
package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.Connection;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.commands.ProtocolCommand;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.springframework.util.ReflectionUtils;
/**
* Utility class to dispatch arbitrary Redis commands using Jedis commands.
*
@@ -41,107 +33,23 @@ import org.springframework.util.ReflectionUtils;
@SuppressWarnings({ "unchecked", "ConstantConditions" })
class JedisClientUtils {
private static final Field TRANSACTION;
private static final Set<String> KNOWN_COMMANDS;
static {
TRANSACTION = ReflectionUtils.findField(Jedis.class, "transaction");
ReflectionUtils.makeAccessible(TRANSACTION);
KNOWN_COMMANDS = Arrays.stream(Protocol.Command.values()).map(Enum::name).collect(Collectors.toSet());
}
/**
* Execute an arbitrary on the supplied {@link Jedis} instance.
*
* @param command the command.
* @param keys must not be {@literal null}, may be empty.
* @param args must not be {@literal null}, may be empty.
* @param jedis must not be {@literal null}.
* @return the response, can be {@literal null}.
*/
static <T> T execute(String command, byte[][] keys, byte[][] args, Supplier<Jedis> jedis) {
return execute(command, keys, args, jedis, it -> (T) it.getOne());
}
/**
* Execute an arbitrary on the supplied {@link Jedis} instance.
*
* @param command the command.
* @param keys must not be {@literal null}, may be empty.
* @param args must not be {@literal null}, may be empty.
* @param jedis must not be {@literal null}.
* @param responseMapper must not be {@literal null}.
* @return the response, can be {@literal null}.
* @since 2.1
*/
static <T> T execute(String command, byte[][] keys, byte[][] args, Supplier<Jedis> jedis,
Function<Connection, T> responseMapper) {
byte[][] commandArgs = getCommandArguments(keys, args);
Connection Connection = sendCommand(command, commandArgs, jedis.get());
return responseMapper.apply(Connection);
}
/**
* Send a Redis command and retrieve the {@link Connection} for response retrieval.
*
* @param command the command.
* @param args must not be {@literal null}, may be empty.
* @param jedis must not be {@literal null}.
* @return the {@link Connection} instance used to send the command.
*/
static Connection sendCommand(String command, byte[][] args, Jedis jedis) {
Connection Connection = jedis.getConnection();
sendCommand(Connection, command, args);
return Connection;
}
private static void sendCommand(Connection Connection, String command, byte[][] args) {
public static ProtocolCommand getCommand(String command) {
if (isKnownCommand(command)) {
Connection.sendCommand(Protocol.Command.valueOf(command.trim().toUpperCase()), args);
} else {
Connection.sendCommand(() -> command.trim().toUpperCase().getBytes(StandardCharsets.UTF_8), args);
return Protocol.Command.valueOf(command.trim().toUpperCase());
}
return () -> JedisConverters.toBytes(command);
}
private static boolean isKnownCommand(String command) {
return KNOWN_COMMANDS.contains(command);
}
private static byte[][] getCommandArguments(byte[][] keys, byte[][] args) {
if (keys.length == 0) {
return args;
}
if (args.length == 0) {
return keys;
}
byte[][] commandArgs = new byte[keys.length + args.length][];
System.arraycopy(keys, 0, commandArgs, 0, keys.length);
System.arraycopy(args, 0, commandArgs, keys.length, args.length);
return commandArgs;
}
/**
* @param jedis the Connection instance.
* @return {@literal true} if the connection has entered {@literal MULTI} state.
*/
static boolean isInMulti(Jedis jedis) {
Object field = ReflectionUtils.getField(TRANSACTION, jedis);
return field instanceof Transaction;
}
}

View File

@@ -76,8 +76,6 @@ public class JedisClusterConnection implements RedisClusterConnection {
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy(
JedisExceptionConverter.INSTANCE);
private static final byte[][] EMPTY_2D_BYTE_ARRAY = new byte[0][];
private final Log log = LogFactory.getLog(getClass());
private final JedisCluster cluster;
@@ -95,7 +93,7 @@ public class JedisClusterConnection implements RedisClusterConnection {
private boolean closed;
private final ClusterTopologyProvider topologyProvider;
private ClusterCommandExecutor clusterCommandExecutor;
private final ClusterCommandExecutor clusterCommandExecutor;
private final boolean disposeClusterCommandExecutorOnClose;
private volatile @Nullable JedisSubscription subscription;
@@ -117,7 +115,6 @@ public class JedisClusterConnection implements RedisClusterConnection {
new JedisClusterNodeResourceProvider(cluster, topologyProvider), EXCEPTION_TRANSLATION);
disposeClusterCommandExecutorOnClose = true;
try {
DirectFieldAccessor executorDfa = new DirectFieldAccessor(cluster);
@@ -170,9 +167,8 @@ public class JedisClusterConnection implements RedisClusterConnection {
Assert.notNull(command, "Command must not be null!");
Assert.notNull(args, "Args must not be null!");
return clusterCommandExecutor
.executeCommandOnArbitraryNode((JedisClusterCommandCallback<Object>) client -> JedisClientUtils.execute(command,
EMPTY_2D_BYTE_ARRAY, args, () -> client))
return clusterCommandExecutor.executeCommandOnArbitraryNode(
(JedisClusterCommandCallback<Object>) client -> client.sendCommand(JedisClientUtils.getCommand(command), args))
.getValue();
}
@@ -189,7 +185,7 @@ public class JedisClusterConnection implements RedisClusterConnection {
RedisClusterNode keyMaster = topologyProvider.getTopology().getKeyServingMasterNode(key);
return clusterCommandExecutor.executeCommandOnSingleNode((JedisClusterCommandCallback<T>) client -> {
return (T) client.sendCommand(() -> JedisConverters.toBytes(command), commandArgs);
return (T) client.sendCommand(JedisClientUtils.getCommand(command), commandArgs);
}, keyMaster).getValue();
}
@@ -236,9 +232,9 @@ public class JedisClusterConnection implements RedisClusterConnection {
Assert.notNull(args, "Args must not be null!");
return clusterCommandExecutor.executeMultiKeyCommand((JedisMultiKeyClusterCommandCallback<T>) (client, key) -> {
return JedisClientUtils.execute(command, new byte[][] { key }, args.toArray(new byte[args.size()][]),
() -> client);
return (T) client.sendCommand(JedisClientUtils.getCommand(command), getCommandArguments(key, args));
}, keys).resultsAsList();
}
@Override
@@ -421,8 +417,8 @@ public class JedisClusterConnection implements RedisClusterConnection {
@Override
public String ping(RedisClusterNode node) {
return clusterCommandExecutor
.executeCommandOnSingleNode((JedisClusterCommandCallback<String>) Jedis::ping, node).getValue();
return clusterCommandExecutor.executeCommandOnSingleNode((JedisClusterCommandCallback<String>) Jedis::ping, node)
.getValue();
}
/*

View File

@@ -279,8 +279,8 @@ class JedisClusterHashCommands implements RedisHashCommands {
ScanParams params = JedisConverters.toScanParams(options);
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key,
JedisConverters.toBytes(cursorId), params);
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key, JedisConverters.toBytes(cursorId),
params);
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
}
}.open();

View File

@@ -43,8 +43,8 @@ class JedisClusterScriptingCommands implements RedisScriptingCommands {
public void scriptFlush() {
try {
connection.getClusterCommandExecutor().executeCommandOnAllNodes(
(JedisClusterConnection.JedisClusterCommandCallback<String>) Jedis::scriptFlush);
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterConnection.JedisClusterCommandCallback<String>) Jedis::scriptFlush);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -54,8 +54,8 @@ class JedisClusterScriptingCommands implements RedisScriptingCommands {
public void scriptKill() {
try {
connection.getClusterCommandExecutor().executeCommandOnAllNodes(
(JedisClusterConnection.JedisClusterCommandCallback<String>) Jedis::scriptKill);
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterConnection.JedisClusterCommandCallback<String>) Jedis::scriptKill);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -89,8 +89,7 @@ class JedisClusterScriptingCommands implements RedisScriptingCommands {
Assert.notNull(script, "Script must not be null!");
try {
return (T) new JedisScriptReturnConverter(returnType)
.convert(getCluster().eval(script, numKeys, keysAndArgs));
return (T) new JedisScriptReturnConverter(returnType).convert(getCluster().eval(script, numKeys, keysAndArgs));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}

View File

@@ -150,9 +150,8 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void flushAll(FlushOption option) {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes(
(JedisClusterCommandCallback<String>) it -> it.flushAll(JedisConverters.toFlushMode(option)));
connection.getClusterCommandExecutor().executeCommandOnAllNodes(
(JedisClusterCommandCallback<String>) it -> it.flushAll(JedisConverters.toFlushMode(option)));
}
@Override
@@ -220,11 +219,10 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void shutdown() {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) jedis -> {
jedis.shutdown();
return null;
});
connection.getClusterCommandExecutor().executeCommandOnAllNodes((JedisClusterCommandCallback<String>) jedis -> {
jedis.shutdown();
return null;
});
}
@Override

View File

@@ -397,8 +397,7 @@ class JedisClusterSetCommands implements RedisSetCommands {
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
ScanParams params = JedisConverters.toScanParams(options);
ScanResult<byte[]> result = connection.getCluster().sscan(key,
JedisConverters.toBytes(cursorId), params);
ScanResult<byte[]> result = connection.getCluster().sscan(key, JedisConverters.toBytes(cursorId), params);
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
}
}.open();

View File

@@ -77,7 +77,7 @@ class JedisClusterStreamCommands implements RedisStreamCommands {
Assert.notNull(record, "Record must not be null!");
Assert.notNull(record.getStream(), "Stream must not be null!");
XAddParams params = StreamConverters.toXAddParams(record, options);
XAddParams params = StreamConverters.toXAddParams(record.getId(), options);
try {
return RecordId
@@ -122,9 +122,8 @@ class JedisClusterStreamCommands implements RedisStreamCommands {
XClaimParams xClaimParams = StreamConverters.toXClaimParams(options);
try {
return convertToByteRecord(key,
connection.getCluster().xclaim(key, JedisConverters.toBytes(group), JedisConverters.toBytes(newOwner),
minIdleTime, xClaimParams, entryIdsToBytes(options.getIds())));
return convertToByteRecord(key, connection.getCluster().xclaim(key, JedisConverters.toBytes(group),
JedisConverters.toBytes(newOwner), minIdleTime, xClaimParams, entryIdsToBytes(options.getIds())));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}

View File

@@ -55,7 +55,7 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* {@code RedisConnection} implementation on top of <a href="https://github.com/xetorthio/jedis">Jedis</a> library.
* {@code RedisConnection} implementation on top of <a href="https://github.com/redis/jedis">Jedis</a> library.
*
* @author Costin Leau
* @author Jennifer Hickey
@@ -97,7 +97,6 @@ public class JedisConnection extends AbstractRedisConnection {
private final @Nullable Pool<Jedis> pool;
private final JedisClientConfig sentinelConfig;
private List<JedisResult> pipelinedResults = new ArrayList<>();
private Queue<FutureResult<Response<?>>> txResults = new LinkedList<>();
@@ -272,7 +271,6 @@ public class JedisConnection extends AbstractRedisConnection {
@Override
public Object execute(String command, byte[]... args) {
Assert.hasText(command, "A valid command needs to be specified!");
Assert.notNull(args, "Arguments must not be null!");
@@ -517,12 +515,6 @@ public class JedisConnection extends AbstractRedisConnection {
return JedisResultBuilder.<T, T> forResponse(response).build();
}
<T, R> JedisResult<T, R> newJedisResult(Response<T> response, Converter<T, R> converter) {
return JedisResultBuilder.<T, R> forResponse(response).mappedWith(converter)
.convertPipelineAndTxResults(convertPipelineAndTxResults).build();
}
<T, R> JedisResult<T, R> newJedisResult(Response<T> response, Converter<T, R> converter, Supplier<R> defaultValue) {
return JedisResultBuilder.<T, R> forResponse(response).mappedWith(converter)
@@ -566,7 +558,7 @@ public class JedisConnection extends AbstractRedisConnection {
doWithJedis(it -> {
for (byte[] key : keys) {
it.watch(key);
it.watch(key);
}
});
}

View File

@@ -108,8 +108,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
private boolean destroyed;
/**
* Constructs a new <code>JedisConnectionFactory</code> instance with default settings (default connection pooling, no
* shard information).
* Constructs a new {@link JedisConnectionFactory} instance with default settings (default connection pooling).
*/
public JedisConnectionFactory() {
this(new MutableJedisClientConfiguration());
@@ -129,7 +128,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
}
/**
* Constructs a new <code>JedisConnectionFactory</code> instance using the given pool configuration.
* Constructs a new {@link JedisConnectionFactory} instance using the given pool configuration.
*
* @param poolConfig pool configuration
*/
@@ -274,7 +273,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
}
private Jedis createJedis() {
return new Jedis(new HostAndPort(getHostName(), getPort()), this.clientConfig);
}
@@ -835,7 +833,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
throw new InvalidDataAccessResourceUsageException("No Sentinel found");
}
private static Set<HostAndPort> convertToJedisSentinelSet(Collection<RedisNode> nodes) {
if (CollectionUtils.isEmpty(nodes)) {

View File

@@ -16,13 +16,8 @@
package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.GeoCoordinate;
import redis.clients.jedis.GeoRadiusResponse;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.ListPosition;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.BitOP;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.GeoUnit;
import redis.clients.jedis.args.ListPosition;
import redis.clients.jedis.params.GeoRadiusParam;
@@ -39,7 +34,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -107,7 +101,7 @@ import org.springframework.util.StringUtils;
* @author dengliming
*/
@SuppressWarnings("ConstantConditions")
public abstract class JedisConverters extends Converters {
abstract class JedisConverters extends Converters {
public static final byte[] PLUS_BYTES;
public static final byte[] MINUS_BYTES;
@@ -140,9 +134,6 @@ public abstract class JedisConverters extends Converters {
return new ListConverter<>(stringToBytes());
}
/**
* @deprecated since 2.5
*/
static Set<Tuple> toTupleSet(Set<redis.clients.jedis.resps.Tuple> source) {
return new SetConverter<>(JedisConverters::toTuple).convert(source);
}
@@ -163,10 +154,8 @@ public abstract class JedisConverters extends Converters {
Assert.notNull(tuples, "Tuple set must not be null!");
Map<byte[], Double> args = new LinkedHashMap<>(tuples.size(), 1);
Set<Double> scores = new HashSet<>(tuples.size(), 1);
for (Tuple tuple : tuples) {
scores.add(tuple.getScore());
args.put(tuple.getValue(), tuple.getScore());
}
@@ -251,7 +240,6 @@ public abstract class JedisConverters extends Converters {
* @since 1.4
*/
public static List<RedisServer> toListOfRedisServer(List<Map<String, String>> source) {
return toList(it -> RedisServer.newServerFrom(Converters.toProperties(it)), source);
}
@@ -902,8 +890,7 @@ public abstract class JedisConverters extends Converters {
return new GeoResultConverter(metric);
}
private static class GeoResultConverter
implements Converter<GeoRadiusResponse, GeoResult<GeoLocation<byte[]>>> {
private static class GeoResultConverter implements Converter<GeoRadiusResponse, GeoResult<GeoLocation<byte[]>>> {
private final Metric metric;

View File

@@ -167,8 +167,8 @@ class JedisGeoCommands implements RedisGeoCommands {
Converter<List<redis.clients.jedis.resps.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> converter = JedisConverters
.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric());
return connection.invoke().from(Jedis::georadius, PipelineBinaryCommands::georadius, key,
within.getCenter().getX(),
return connection.invoke()
.from(Jedis::georadius, PipelineBinaryCommands::georadius, key, within.getCenter().getX(),
within.getCenter().getY(), within.getRadius().getValue(),
JedisConverters.toGeoUnit(within.getRadius().getMetric()), geoRadiusParam)
.get(converter);
@@ -185,8 +185,8 @@ class JedisGeoCommands implements RedisGeoCommands {
Converter<List<redis.clients.jedis.resps.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> converter = JedisConverters
.geoRadiusResponseToGeoResultsConverter(radius.getMetric());
return connection.invoke().from(Jedis::georadiusByMember, PipelineBinaryCommands::georadiusByMember, key,
member, radius.getValue(), geoUnit).get(converter);
return connection.invoke().from(Jedis::georadiusByMember, PipelineBinaryCommands::georadiusByMember, key, member,
radius.getValue(), geoUnit).get(converter);
}
@Override
@@ -203,8 +203,8 @@ class JedisGeoCommands implements RedisGeoCommands {
.geoRadiusResponseToGeoResultsConverter(radius.getMetric());
redis.clients.jedis.params.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(args);
return connection.invoke().from(Jedis::georadiusByMember, PipelineBinaryCommands::georadiusByMember, key,
member, radius.getValue(), geoUnit, geoRadiusParam).get(converter);
return connection.invoke().from(Jedis::georadiusByMember, PipelineBinaryCommands::georadiusByMember, key, member,
radius.getValue(), geoUnit, geoRadiusParam).get(converter);
}
@Override

View File

@@ -121,8 +121,7 @@ class JedisHashCommands implements RedisHashCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke()
.from(Jedis::hrandfieldWithValues, PipelineBinaryCommands::hrandfieldWithValues, key, 1L)
return connection.invoke().from(Jedis::hrandfieldWithValues, PipelineBinaryCommands::hrandfieldWithValues, key, 1L)
.get(it -> it.isEmpty() ? null : it.entrySet().iterator().next());
}

View File

@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Queable;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.commands.DatabasePipelineCommands;
@@ -1017,25 +1018,23 @@ class JedisInvoker {
@Nullable
@SuppressWarnings({ "unchecked", "rawtypes" })
default <I, T> T invoke(Function<Jedis, I> callFunction,
Function<ResponseCommands, Response<I>> pipelineFunction) {
return (T) doInvoke((Function) callFunction, (Function) pipelineFunction, Converters.identityConverter(), () -> null);
default <I, T> T invoke(Function<Jedis, I> callFunction, Function<ResponseCommands, Response<I>> pipelineFunction) {
return (T) doInvoke((Function) callFunction, (Function) pipelineFunction, Converters.identityConverter(),
() -> null);
}
@Nullable
@SuppressWarnings({ "unchecked", "rawtypes" })
default <I, T> T invoke(Function<Jedis, I> callFunction,
Function<ResponseCommands, Response<I>> pipelineFunction, Converter<I, T> converter,
Supplier<T> nullDefault) {
default <I, T> T invoke(Function<Jedis, I> callFunction, Function<ResponseCommands, Response<I>> pipelineFunction,
Converter<I, T> converter, Supplier<T> nullDefault) {
return (T) doInvoke((Function) callFunction, (Function) pipelineFunction, (Converter<Object, Object>) converter,
(Supplier<Object>) nullDefault);
}
@Nullable
Object doInvoke(Function<Jedis, Object> callFunction,
Function<ResponseCommands, Response<Object>> pipelineFunction, Converter<Object, Object> converter,
Supplier<Object> nullDefault);
Object doInvoke(Function<Jedis, Object> callFunction, Function<ResponseCommands, Response<Object>> pipelineFunction,
Converter<Object, Object> converter, Supplier<Object> nullDefault);
}
interface ResponseCommands extends PipelineBinaryCommands, DatabasePipelineCommands {
@@ -1043,16 +1042,16 @@ class JedisInvoker {
Response<Long> publish(String channel, String message);
}
static ResponseCommands createCommands(Transaction transaction) {
/**
* Create a proxy to invoke methods dynamically on {@link Pipeline} or {@link Transaction} as those share many
* commands that are not defined on a common super-type.
*
* @param pipelineOrTransaction
* @return
*/
static ResponseCommands createCommands(Queable pipelineOrTransaction) {
ProxyFactory proxyFactory = new ProxyFactory(transaction);
proxyFactory.addInterface(ResponseCommands.class);
return (ResponseCommands) proxyFactory.getProxy(JedisInvoker.class.getClassLoader());
}
static ResponseCommands createCommands(Pipeline pipeline) {
ProxyFactory proxyFactory = new ProxyFactory(pipeline);
ProxyFactory proxyFactory = new ProxyFactory(pipelineOrTransaction);
proxyFactory.addInterface(ResponseCommands.class);
return (ResponseCommands) proxyFactory.getProxy(JedisInvoker.class.getClassLoader());
}

View File

@@ -167,12 +167,10 @@ class JedisKeyCommands implements RedisKeyCommands {
if (type != null) {
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params, type);
} else {
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(),
params);
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params);
}
return new ScanIteration<>(Long.parseLong(result.getCursor()),
result.getResult());
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
}
protected void doClose() {
@@ -261,8 +259,7 @@ class JedisKeyCommands implements RedisKeyCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke().from(j -> j.move(key, dbIndex))
.get(JedisConverters.longToBoolean());
return connection.invoke().from(j -> j.move(key, dbIndex)).get(JedisConverters.longToBoolean());
}
@Override
@@ -354,8 +351,7 @@ class JedisKeyCommands implements RedisKeyCommands {
}
connection.invokeStatus().just(JedisBinaryCommands::restore, PipelineBinaryCommands::restore, key,
(int) ttlInMillis,
serializedValue);
(int) ttlInMillis, serializedValue);
}
@Nullable

View File

@@ -147,8 +147,7 @@ class JedisListCommands implements RedisListCommands {
Assert.notNull(to, "To direction must not be null!");
return connection.invoke().just(JedisBinaryCommands::lmove, PipelineBinaryCommands::lmove, sourceKey,
destinationKey,
ListDirection.valueOf(from.name()), ListDirection.valueOf(to.name()));
destinationKey, ListDirection.valueOf(from.name()), ListDirection.valueOf(to.name()));
}
@Override
@@ -160,8 +159,7 @@ class JedisListCommands implements RedisListCommands {
Assert.notNull(to, "To direction must not be null!");
return connection.invoke().just(JedisBinaryCommands::blmove, PipelineBinaryCommands::blmove, sourceKey,
destinationKey,
ListDirection.valueOf(from.name()), ListDirection.valueOf(to.name()), timeout);
destinationKey, ListDirection.valueOf(from.name()), ListDirection.valueOf(to.name()), timeout);
}
@Override

View File

@@ -78,8 +78,8 @@ class JedisScriptingCommands implements RedisScriptingCommands {
assertDirectMode();
JedisScriptReturnConverter converter = new JedisScriptReturnConverter(returnType);
return (T) connection.invoke().from(it -> it.eval(script, numKeys, keysAndArgs))
.getOrElse(converter, () -> converter.convert(null));
return (T) connection.invoke().from(it -> it.eval(script, numKeys, keysAndArgs)).getOrElse(converter,
() -> converter.convert(null));
}
@Override

View File

@@ -74,8 +74,7 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void flushDb(FlushOption option) {
connection.invokeStatus().just(BinaryJedis::flushDB, MultiKeyPipelineBase::flushDB,
JedisConverters.toFlushMode(option));
connection.invokeStatus().just(j -> j.flushDB(JedisConverters.toFlushMode(option)));
}
@Override
@@ -85,8 +84,7 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void flushAll(FlushOption option) {
connection.invokeStatus().just(BinaryJedis::flushAll, MultiKeyPipelineBase::flushAll,
JedisConverters.toFlushMode(option));
connection.invokeStatus().just(j -> j.flushAll(JedisConverters.toFlushMode(option)));
}
@Override
@@ -99,8 +97,7 @@ class JedisServerCommands implements RedisServerCommands {
Assert.notNull(section, "Section must not be null!");
return connection.invoke().from(j -> j.info(section))
.get(JedisConverters::toProperties);
return connection.invoke().from(j -> j.info(section)).get(JedisConverters::toProperties);
}
@Override
@@ -129,8 +126,7 @@ class JedisServerCommands implements RedisServerCommands {
Assert.notNull(pattern, "Pattern must not be null!");
return connection.invoke().from(j -> j.configGet(pattern))
.get(Converters::toProperties);
return connection.invoke().from(j -> j.configGet(pattern)).get(Converters::toProperties);
}
@Override
@@ -157,8 +153,7 @@ class JedisServerCommands implements RedisServerCommands {
Assert.notNull(timeUnit, "TimeUnit must not be null.");
return connection.invoke().from(Jedis::time)
.get((List<String> source) -> JedisConverters.toTime(source, timeUnit));
return connection.invoke().from(Jedis::time).get((List<String> source) -> JedisConverters.toTime(source, timeUnit));
}
@Override
@@ -166,10 +161,6 @@ class JedisServerCommands implements RedisServerCommands {
Assert.hasText(host, "Host for 'CLIENT KILL' must not be 'null' or 'empty'.");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'CLIENT KILL' is not supported in transaction / pipline mode.");
}
connection.invokeStatus().just(it -> it.clientKill(String.format("%s:%s", host, port)));
}
@@ -178,30 +169,16 @@ class JedisServerCommands implements RedisServerCommands {
Assert.notNull(name, "Name must not be null!");
if (isPipelined() || isQueueing()) {
throw new UnsupportedOperationException("'CLIENT SETNAME' is not suppored in transacton / pipeline mode.");
}
connection.invokeStatus().just(it -> it.clientSetname(name));
}
@Override
public String getClientName() {
if (isPipelined() || isQueueing()) {
throw new UnsupportedOperationException();
}
return connection.invokeStatus().just(Jedis::clientGetname);
}
@Override
public List<RedisClientInfo> getClientList() {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'CLIENT LIST' is not supported in in pipeline / multi mode.");
}
return connection.invokeStatus().from(Jedis::clientList).get(JedisConverters::toListOfRedisClientInformation);
}
@@ -210,21 +187,12 @@ class JedisServerCommands implements RedisServerCommands {
Assert.hasText(host, "Host must not be null for 'REPLICAOF' command.");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'REPLICAOF' cannot be called in pipeline / transaction mode.");
}
connection.invokeStatus().just(it -> it.slaveof(host, port));
connection.invokeStatus().just(it -> it.replicaof(host, port));
}
@Override
public void replicaOfNoOne() {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'REPLICAOF' cannot be called in pipeline / transaction mode.");
}
connection.invokeStatus().just(Jedis::slaveofNoOne);
connection.invokeStatus().just(Jedis::replicaofNoOne);
}
@Override
@@ -243,12 +211,4 @@ class JedisServerCommands implements RedisServerCommands {
connection.invokeStatus().just(j -> j.migrate(target.getHost(), target.getPort(), key, dbIndex, timeoutToUse));
}
private boolean isPipelined() {
return connection.isPipelined();
}
private boolean isQueueing() {
return connection.isQueueing();
}
}

View File

@@ -231,8 +231,7 @@ class JedisSetCommands implements RedisSetCommands {
ScanParams params = JedisConverters.toScanParams(options);
ScanResult<byte[]> result = connection.getJedis().sscan(key,
JedisConverters.toBytes(cursorId), params);
ScanResult<byte[]> result = connection.getJedis().sscan(key, JedisConverters.toBytes(cursorId), params);
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
}

View File

@@ -77,7 +77,7 @@ class JedisStreamCommands implements RedisStreamCommands {
Assert.notNull(record, "Record must not be null!");
Assert.notNull(record.getStream(), "Stream must not be null!");
XAddParams params = StreamConverters.toXAddParams(record, options);
XAddParams params = StreamConverters.toXAddParams(record.getId(), options);
return connection.invoke()
.from(Jedis::xadd, PipelineBinaryCommands::xadd, record.getStream(), record.getValue(), params)
@@ -110,8 +110,7 @@ class JedisStreamCommands implements RedisStreamCommands {
XClaimParams params = StreamConverters.toXClaimParams(options);
return connection.invoke()
.from(
Jedis::xclaim, ResponseCommands::xclaim, key, JedisConverters.toBytes(group),
.from(Jedis::xclaim, ResponseCommands::xclaim, key, JedisConverters.toBytes(group),
JedisConverters.toBytes(newOwner), options.getMinIdleTime().toMillis(), params,
StreamConverters.entryIdsToBytes(options.getIds()))
.get(r -> StreamConverters.convertToByteRecord(key, r));
@@ -198,14 +197,12 @@ class JedisStreamCommands implements RedisStreamCommands {
return connection.invoke()
.from(Jedis::xinfoConsumers, ResponseCommands::xinfoConsumers, key, JedisConverters.toBytes(groupName))
.get(it -> {
List<StreamConsumersInfo> streamConsumersInfos = BuilderFactory.STREAM_CONSUMERS_INFO_LIST
.build(it);
List<Object> sources = new ArrayList<>();
streamConsumersInfos
.forEach(
List<StreamConsumersInfo> streamConsumersInfos = BuilderFactory.STREAM_CONSUMERS_INFO_LIST.build(it);
List<Object> sources = new ArrayList<>();
streamConsumersInfos.forEach(
streamConsumersInfo -> sources.add(StreamConverters.mapToList(streamConsumersInfo.getConsumerInfo())));
return StreamInfo.XInfoConsumers.fromList(groupName, sources);
});
return StreamInfo.XInfoConsumers.fromList(groupName, sources);
});
}
@Override
@@ -314,12 +311,4 @@ class JedisStreamCommands implements RedisStreamCommands {
return connection.invoke().just(Jedis::xtrim, PipelineBinaryCommands::xtrim, key, count, approximateTrimming);
}
private boolean isPipelined() {
return connection.isPipelined();
}
private boolean isQueueing() {
return connection.isQueueing();
}
}

View File

@@ -164,8 +164,7 @@ class JedisStringCommands implements RedisStringCommands {
Assert.notNull(tuples, "Tuples must not be null!");
return connection.invoke()
.from(Jedis::msetnx, PipelineBinaryCommands::msetnx, JedisConverters.toByteArrays(tuples))
return connection.invoke().from(Jedis::msetnx, PipelineBinaryCommands::msetnx, JedisConverters.toByteArrays(tuples))
.get(Converters.longToBoolean());
}

View File

@@ -70,8 +70,8 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(tuples, "Tuples must not be null!");
return connection.invoke().just(Jedis::zadd, PipelineBinaryCommands::zadd, key,
JedisConverters.toTupleMap(tuples), JedisConverters.toZAddParams(args));
return connection.invoke().just(Jedis::zadd, PipelineBinaryCommands::zadd, key, JedisConverters.toTupleMap(tuples),
JedisConverters.toZAddParams(args));
}
@Override
@@ -106,8 +106,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke().fromMany(Jedis::zrandmember, PipelineBinaryCommands::zrandmember, key, count)
.toList();
return connection.invoke().fromMany(Jedis::zrandmember, PipelineBinaryCommands::zrandmember, key, count).toList();
}
@Override
@@ -290,8 +289,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke().from(Jedis::zpopmin, PipelineBinaryCommands::zpopmin, key)
.get(JedisConverters::toTuple);
return connection.invoke().from(Jedis::zpopmin, PipelineBinaryCommands::zpopmin, key).get(JedisConverters::toTuple);
}
@Nullable
@@ -300,8 +298,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke()
.fromMany(Jedis::zpopmin, PipelineBinaryCommands::zpopmin, key, Math.toIntExact(count))
return connection.invoke().fromMany(Jedis::zpopmin, PipelineBinaryCommands::zpopmin, key, Math.toIntExact(count))
.toSet(JedisConverters::toTuple);
}
@@ -323,8 +320,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke().from(Jedis::zpopmax, PipelineBinaryCommands::zpopmax, key)
.get(JedisConverters::toTuple);
return connection.invoke().from(Jedis::zpopmax, PipelineBinaryCommands::zpopmax, key).get(JedisConverters::toTuple);
}
@Nullable
@@ -333,8 +329,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke()
.fromMany(Jedis::zpopmax, PipelineBinaryCommands::zpopmax, key, Math.toIntExact(count))
return connection.invoke().fromMany(Jedis::zpopmax, PipelineBinaryCommands::zpopmax, key, Math.toIntExact(count))
.toSet(JedisConverters::toTuple);
}
@@ -381,8 +376,7 @@ class JedisZSetCommands implements RedisZSetCommands {
Assert.notNull(key, "Key must not be null!");
return connection.invoke().just(Jedis::zremrangeByRank, PipelineBinaryCommands::zremrangeByRank, key, start,
end);
return connection.invoke().just(Jedis::zremrangeByRank, PipelineBinaryCommands::zremrangeByRank, key, start, end);
}
@Override
@@ -406,8 +400,7 @@ class JedisZSetCommands implements RedisZSetCommands {
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
return connection.invoke().just(Jedis::zremrangeByScore, PipelineBinaryCommands::zremrangeByScore, key, min,
max);
return connection.invoke().just(Jedis::zremrangeByScore, PipelineBinaryCommands::zremrangeByScore, key, min, max);
}
@Override
@@ -477,8 +470,7 @@ class JedisZSetCommands implements RedisZSetCommands {
ZParams zparams = toZParams(aggregate, weights);
return connection.invoke().just(Jedis::zinterstore, PipelineBinaryCommands::zinterstore, destKey, zparams,
sets);
return connection.invoke().just(Jedis::zinterstore, PipelineBinaryCommands::zinterstore, destKey, zparams, sets);
}
@Override
@@ -533,8 +525,7 @@ class JedisZSetCommands implements RedisZSetCommands {
ZParams zparams = toZParams(aggregate, weights);
return connection.invoke().just(Jedis::zunionstore, PipelineBinaryCommands::zunionstore, destKey, zparams,
sets);
return connection.invoke().just(Jedis::zunionstore, PipelineBinaryCommands::zunionstore, destKey, zparams, sets);
}
@Override

View File

@@ -24,7 +24,6 @@ import redis.clients.jedis.params.XReadGroupParams;
import redis.clients.jedis.params.XReadParams;
import redis.clients.jedis.resps.StreamEntry;
import redis.clients.jedis.resps.StreamPendingEntry;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.util.SafeEncoder;
import java.time.Duration;
@@ -41,7 +40,6 @@ import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.RedisStreamCommands;
import org.springframework.data.redis.connection.stream.ByteRecord;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.PendingMessage;
import org.springframework.data.redis.connection.stream.PendingMessages;
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
@@ -206,7 +204,7 @@ class StreamConverters {
return new PendingMessages(groupName, messages).withinRange(range);
}
public static XAddParams toXAddParams(RedisStreamCommands.XAddOptions options, RecordId recordId) {
public static XAddParams toXAddParams(RecordId recordId, RedisStreamCommands.XAddOptions options) {
XAddParams params = new XAddParams();
params.id(toStreamEntryId(recordId.getValue()));