Refine defaulted connection arrangement.
DefaultedRedis…Connection is now deprecated to help with migration towards segregated/commands interface usage. The connection now exposes a commands() object providing access to RedisCommands so that a composite commands object can be accessed independently from the connection. Redis…Commands provider represent entry points to obtain segregated command interfaces. See: #2273 Original Pull Request: #2276
This commit is contained in:
committed by
Christoph Strobl
parent
f6eaa40019
commit
33e8974578
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class AbstractRedisConnection implements DefaultedRedisConnection {
|
||||
public abstract class AbstractRedisConnection implements RedisConnection {
|
||||
|
||||
private @Nullable RedisSentinelConfiguration sentinelConfiguration;
|
||||
private final Map<RedisNode, RedisSentinelConnection> connectionCache = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -80,6 +80,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author ihaohong
|
||||
* @author Dennis Neufeld
|
||||
*/
|
||||
@SuppressWarnings({ "ConstantConditions", "deprecation" })
|
||||
public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection {
|
||||
|
||||
private static final byte[][] EMPTY_2D_BYTE_ARRAY = new byte[0][];
|
||||
@@ -184,6 +185,66 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
this.byteGeoResultsToStringGeoResults = Converters.deserializingGeoResultsConverter(serializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisCommands commands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisGeoCommands geoCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHashCommands hashCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisScriptingCommands scriptingCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisServerCommands serverCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long append(byte[] key, byte[] value) {
|
||||
return convertAndReturn(delegate.append(key, value), Converters.identityConverter());
|
||||
@@ -1011,6 +1072,13 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.zInterWithScores(aggregate, weights, serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zInterStore(destKey, aggregate, Weights.of(weights), sets),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zInterStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zInterStore(destKey, aggregate, weights, sets), Converters.identityConverter());
|
||||
@@ -1211,6 +1279,13 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.zUnionStore(destKey, aggregate, weights, sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zUnionStore(destKey, aggregate, Weights.of(weights), sets),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zUnionStore(destKey, sets), Converters.identityConverter());
|
||||
}
|
||||
@@ -1303,7 +1378,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
: (GeoReference) data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private StreamOffset<byte[]>[] serialize(StreamOffset<String>[] offsets) {
|
||||
|
||||
return Arrays.stream(offsets).map(it -> StreamOffset.create(serialize(it.getKey()), it.getOffset()))
|
||||
|
||||
@@ -15,14 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -30,7 +27,9 @@ import org.springframework.util.Assert;
|
||||
* @author Dennis Neufeld
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface DefaultedRedisClusterConnection extends RedisClusterConnection, DefaultedRedisConnection {
|
||||
@Deprecated
|
||||
public interface DefaultedRedisClusterConnection
|
||||
extends DefaultedRedisConnection, RedisClusterCommands, RedisClusterServerCommands, RedisClusterCommandsProvider {
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
|
||||
@Override
|
||||
@@ -165,24 +164,4 @@ public interface DefaultedRedisClusterConnection extends RedisClusterConnection,
|
||||
return serverCommands().getClientList(node);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T execute(String command, byte[] key, Collection<byte[]> args) {
|
||||
|
||||
Assert.notNull(command, "Command must not be null!");
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(args, "Args must not be null!");
|
||||
|
||||
byte[][] commandArgs = new byte[args.size() + 1][];
|
||||
|
||||
commandArgs[0] = key;
|
||||
int targetIndex = 1;
|
||||
|
||||
for (byte[] binaryArgument : args) {
|
||||
commandArgs[targetIndex++] = binaryArgument;
|
||||
}
|
||||
|
||||
return (T) execute(command, commandArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ import org.springframework.lang.Nullable;
|
||||
* @author Dennis Neufeld
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface DefaultedRedisConnection extends RedisConnection {
|
||||
@Deprecated
|
||||
public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsProvider {
|
||||
|
||||
// KEY COMMANDS
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
/**
|
||||
* Provides access to {@link RedisClusterCommands} and the segregated command interfaces.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface RedisClusterCommandsProvider extends RedisCommandsProvider {
|
||||
|
||||
/**
|
||||
* Get {@link RedisGeoCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisClusterCommands clusterCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisServerCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisClusterServerCommands serverCommands();
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.Set;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link RedisClusterConnection} allows sending commands to dedicated nodes within the cluster. A
|
||||
@@ -32,7 +33,8 @@ import org.springframework.lang.Nullable;
|
||||
* @author Mark Paluch
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface RedisClusterConnection extends RedisConnection, RedisClusterCommands, RedisClusterServerCommands {
|
||||
public interface RedisClusterConnection
|
||||
extends RedisConnection, DefaultedRedisClusterConnection, RedisClusterCommandsProvider {
|
||||
|
||||
/**
|
||||
* @param node must not be {@literal null}.
|
||||
@@ -89,15 +91,22 @@ public interface RedisClusterConnection extends RedisConnection, RedisClusterCom
|
||||
* @since 2.1
|
||||
*/
|
||||
@Nullable
|
||||
<T> T execute(String command, byte[] key, Collection<byte[]> args);
|
||||
default <T> T execute(String command, byte[] key, Collection<byte[]> args) {
|
||||
|
||||
/**
|
||||
* Get {@link RedisClusterServerCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisClusterServerCommands serverCommands() {
|
||||
return this;
|
||||
Assert.notNull(command, "Command must not be null!");
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(args, "Args must not be null!");
|
||||
|
||||
byte[][] commandArgs = new byte[args.size() + 1][];
|
||||
|
||||
commandArgs[0] = key;
|
||||
int targetIndex = 1;
|
||||
|
||||
for (byte[] binaryArgument : args) {
|
||||
commandArgs[targetIndex++] = binaryArgument;
|
||||
}
|
||||
|
||||
return (T) execute(command, commandArgs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
/**
|
||||
* Provides access to {@link RedisCommands} and the segregated command interfaces.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface RedisCommandsProvider {
|
||||
|
||||
/**
|
||||
* Get {@link RedisCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 3.0
|
||||
*/
|
||||
RedisCommands commands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisGeoCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisGeoCommands geoCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisHashCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisHashCommands hashCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisHyperLogLogCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisHyperLogLogCommands hyperLogLogCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisKeyCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisKeyCommands keyCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisListCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisListCommands listCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisSetCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisSetCommands setCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisScriptingCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisScriptingCommands scriptingCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisServerCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisServerCommands serverCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisStreamCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
RedisStreamCommands streamCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisStringCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisStringCommands stringCommands();
|
||||
|
||||
/**
|
||||
* Get {@link RedisZSetCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
RedisZSetCommands zSetCommands();
|
||||
}
|
||||
@@ -29,117 +29,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @author Mark Paluch
|
||||
* @author James Howe
|
||||
*/
|
||||
public interface RedisConnection extends RedisCommands, AutoCloseable {
|
||||
|
||||
/**
|
||||
* Get {@link RedisGeoCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisGeoCommands geoCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisHashCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisHashCommands hashCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisHyperLogLogCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisKeyCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisKeyCommands keyCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisListCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisListCommands listCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisSetCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisSetCommands setCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisScriptingCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisScriptingCommands scriptingCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisServerCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisServerCommands serverCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisStreamCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.2
|
||||
*/
|
||||
default RedisStreamCommands streamCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisStringCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisStringCommands stringCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link RedisZSetCommands}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
default RedisZSetCommands zSetCommands() {
|
||||
return this;
|
||||
}
|
||||
public interface RedisConnection extends RedisCommandsProvider, DefaultedRedisConnection, AutoCloseable {
|
||||
|
||||
/**
|
||||
* Closes (or quits) the connection.
|
||||
|
||||
@@ -73,7 +73,7 @@ import org.springframework.util.Assert;
|
||||
* @author Liming Deng
|
||||
* @since 1.7
|
||||
*/
|
||||
public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
public class JedisClusterConnection implements RedisClusterConnection {
|
||||
|
||||
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy(
|
||||
JedisExceptionConverter.INSTANCE);
|
||||
@@ -83,6 +83,16 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private final JedisCluster cluster;
|
||||
private final JedisClusterGeoCommands geoCommands = new JedisClusterGeoCommands(this);
|
||||
private final JedisClusterHashCommands hashCommands = new JedisClusterHashCommands(this);
|
||||
private final JedisClusterHyperLogLogCommands hllCommands = new JedisClusterHyperLogLogCommands(this);
|
||||
private final JedisClusterKeyCommands keyCommands = new JedisClusterKeyCommands(this);
|
||||
private final JedisClusterListCommands listCommands = new JedisClusterListCommands(this);
|
||||
private final JedisClusterSetCommands setCommands = new JedisClusterSetCommands(this);
|
||||
private final JedisClusterServerCommands serverCommands = new JedisClusterServerCommands(this);
|
||||
private final JedisClusterStreamCommands streamCommands = new JedisClusterStreamCommands(this);
|
||||
private final JedisClusterStringCommands stringCommands = new JedisClusterStringCommands(this);
|
||||
private final JedisClusterZSetCommands zSetCommands = new JedisClusterZSetCommands(this);
|
||||
|
||||
private boolean closed;
|
||||
|
||||
@@ -233,54 +243,64 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
}, keys).resultsAsList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisCommands commands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisClusterCommands clusterCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisGeoCommands geoCommands() {
|
||||
return new JedisClusterGeoCommands(this);
|
||||
return geoCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHashCommands hashCommands() {
|
||||
return new JedisClusterHashCommands(this);
|
||||
return hashCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return new JedisClusterHyperLogLogCommands(this);
|
||||
return hllCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return doGetKeyCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return new JedisClusterStringCommands(this);
|
||||
return keyCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return new JedisClusterListCommands(this);
|
||||
return listCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return new JedisClusterSetCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return new JedisClusterStreamCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return new JedisClusterZSetCommands(this);
|
||||
return setCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisClusterServerCommands serverCommands() {
|
||||
return new JedisClusterServerCommands(this);
|
||||
return serverCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return streamCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return stringCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return zSetCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,23 +308,19 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
return new JedisClusterScriptingCommands(this);
|
||||
}
|
||||
|
||||
private JedisClusterKeyCommands doGetKeyCommands() {
|
||||
return new JedisClusterKeyCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
|
||||
return doGetKeyCommands().keys(node, pattern);
|
||||
return keyCommands.keys(node, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
|
||||
return doGetKeyCommands().scan(node, options);
|
||||
return keyCommands.scan(node, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] randomKey(RedisClusterNode node) {
|
||||
return doGetKeyCommands().randomKey(node);
|
||||
return keyCommands.randomKey(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -452,12 +468,13 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
|
||||
RedisClusterNode node = clusterGetNodeForSlot(slot);
|
||||
|
||||
clusterCommandExecutor
|
||||
NodeResult<List<byte[]>> result = clusterCommandExecutor
|
||||
.executeCommandOnSingleNode(
|
||||
(JedisClusterCommandCallback<List<byte[]>>) client -> JedisConverters.stringListToByteList()
|
||||
.convert(client.clusterGetKeysInSlot(slot, count != null ? count.intValue() : Integer.MAX_VALUE)),
|
||||
node);
|
||||
return null;
|
||||
|
||||
return result.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -482,7 +499,6 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
|
||||
|
||||
return clusterCommandExecutor.executeCommandOnSingleNode(
|
||||
(JedisClusterCommandCallback<Long>) client -> client.clusterCountKeysInSlot(slot), node).getValue();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,11 +70,24 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
private final JedisInvoker statusInvoker = new JedisInvoker((directFunction, pipelineFunction, converter,
|
||||
nullDefault) -> doInvoke(true, directFunction, pipelineFunction, converter, nullDefault));
|
||||
|
||||
private final JedisGeoCommands geoCommands = new JedisGeoCommands(this);
|
||||
private final JedisHashCommands hashCommands = new JedisHashCommands(this);
|
||||
private final JedisHyperLogLogCommands hllCommands = new JedisHyperLogLogCommands(this);
|
||||
private final JedisKeyCommands keyCommands = new JedisKeyCommands(this);
|
||||
private final JedisListCommands listCommands = new JedisListCommands(this);
|
||||
private final JedisScriptingCommands scriptingCommands = new JedisScriptingCommands(this);
|
||||
private final JedisServerCommands serverCommands = new JedisServerCommands(this);
|
||||
private final JedisSetCommands setCommands = new JedisSetCommands(this);
|
||||
private final JedisStreamCommands streamCommands = new JedisStreamCommands(this);
|
||||
private final JedisStringCommands stringCommands = new JedisStringCommands(this);
|
||||
private final JedisZSetCommands zSetCommands = new JedisZSetCommands(this);
|
||||
|
||||
private final @Nullable Pool<Jedis> pool;
|
||||
private final String clientName;
|
||||
private final JedisClientConfig nodeConfig;
|
||||
private final JedisClientConfig sentinelConfig;
|
||||
|
||||
|
||||
private List<JedisResult> pipelinedResults = new ArrayList<>();
|
||||
private Queue<FutureResult<Response<?>>> txResults = new LinkedList<>();
|
||||
|
||||
@@ -189,58 +202,63 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return new JedisKeyCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return new JedisStreamCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return new JedisStringCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return new JedisListCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return new JedisSetCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return new JedisZSetCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHashCommands hashCommands() {
|
||||
return new JedisHashCommands(this);
|
||||
public RedisCommands commands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisGeoCommands geoCommands() {
|
||||
return new JedisGeoCommands(this);
|
||||
return geoCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisScriptingCommands scriptingCommands() {
|
||||
return new JedisScriptingCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisServerCommands serverCommands() {
|
||||
return new JedisServerCommands(this);
|
||||
public RedisHashCommands hashCommands() {
|
||||
return hashCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return new JedisHyperLogLogCommands(this);
|
||||
return hllCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return keyCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return listCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return setCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return streamCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return stringCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return zSetCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisScriptingCommands scriptingCommands() {
|
||||
return scriptingCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisServerCommands serverCommands() {
|
||||
return serverCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -58,12 +58,22 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Mark Paluch
|
||||
* @since 1.7
|
||||
*/
|
||||
public class LettuceClusterConnection extends LettuceConnection implements DefaultedRedisClusterConnection {
|
||||
public class LettuceClusterConnection extends LettuceConnection
|
||||
implements RedisClusterConnection, DefaultedRedisClusterConnection {
|
||||
|
||||
static final ExceptionTranslationStrategy exceptionConverter = new PassThroughExceptionTranslationStrategy(
|
||||
LettuceExceptionConverter.INSTANCE);
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
private final LettuceClusterGeoCommands geoCommands = new LettuceClusterGeoCommands(this);
|
||||
private final LettuceClusterHashCommands hashCommands = new LettuceClusterHashCommands(this);
|
||||
private final LettuceClusterHyperLogLogCommands hllCommands = new LettuceClusterHyperLogLogCommands(this);
|
||||
private final LettuceClusterKeyCommands keyCommands = new LettuceClusterKeyCommands(this);
|
||||
private final LettuceClusterListCommands listCommands = new LettuceClusterListCommands(this);
|
||||
private final LettuceClusterStringCommands stringCommands = new LettuceClusterStringCommands(this);
|
||||
private final LettuceClusterSetCommands setCommands = new LettuceClusterSetCommands(this);
|
||||
private final LettuceClusterZSetCommands zSetCommands = new LettuceClusterZSetCommands(this);
|
||||
private final LettuceClusterServerCommands serverCommands = new LettuceClusterServerCommands(this);
|
||||
|
||||
private ClusterCommandExecutor clusterCommandExecutor;
|
||||
private ClusterTopologyProvider topologyProvider;
|
||||
@@ -198,53 +208,54 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
||||
connectionProvider.getClass().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.data.redis.connection.RedisClusterCommands clusterCommands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisGeoCommands geoCommands() {
|
||||
return new LettuceClusterGeoCommands(this);
|
||||
return geoCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHashCommands hashCommands() {
|
||||
return new LettuceClusterHashCommands(this);
|
||||
return hashCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return new LettuceClusterHyperLogLogCommands(this);
|
||||
return hllCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return doGetClusterKeyCommands();
|
||||
}
|
||||
|
||||
private LettuceClusterKeyCommands doGetClusterKeyCommands() {
|
||||
return new LettuceClusterKeyCommands(this);
|
||||
return keyCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return new LettuceClusterListCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return new LettuceClusterStringCommands(this);
|
||||
return listCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return new LettuceClusterSetCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return new LettuceClusterZSetCommands(this);
|
||||
return setCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisClusterServerCommands serverCommands() {
|
||||
return new LettuceClusterServerCommands(this);
|
||||
return serverCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return stringCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return zSetCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -438,16 +449,16 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
|
||||
|
||||
@Override
|
||||
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
|
||||
return doGetClusterKeyCommands().keys(node, pattern);
|
||||
return new LettuceClusterKeyCommands(this).keys(node, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
|
||||
return doGetClusterKeyCommands().scan(node, options);
|
||||
return new LettuceClusterKeyCommands(this).scan(node, options);
|
||||
}
|
||||
|
||||
public byte[] randomKey(RedisClusterNode node) {
|
||||
return doGetClusterKeyCommands().randomKey(node);
|
||||
return new LettuceClusterKeyCommands(this).randomKey(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -95,6 +95,18 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
LettuceExceptionConverter.INSTANCE);
|
||||
private static final TypeHints typeHints = new TypeHints();
|
||||
|
||||
private final LettuceGeoCommands geoCommands = new LettuceGeoCommands(this);
|
||||
private final LettuceHashCommands hashCommands = new LettuceHashCommands(this);
|
||||
private final LettuceHyperLogLogCommands hllCommands = new LettuceHyperLogLogCommands(this);
|
||||
private final LettuceKeyCommands keyCommands = new LettuceKeyCommands(this);
|
||||
private final LettuceListCommands listCommands = new LettuceListCommands(this);
|
||||
private final LettuceScriptingCommands scriptingCommands = new LettuceScriptingCommands(this);
|
||||
private final LettuceSetCommands setCommands = new LettuceSetCommands(this);
|
||||
private final LettuceServerCommands serverCommands = new LettuceServerCommands(this);
|
||||
private final LettuceStreamCommands streamCommands = new LettuceStreamCommands(this);
|
||||
private final LettuceStringCommands stringCommands = new LettuceStringCommands(this);
|
||||
private final LettuceZSetCommands zSetCommands = new LettuceZSetCommands(this);
|
||||
|
||||
private final int defaultDbIndex;
|
||||
private int dbIndex;
|
||||
|
||||
@@ -231,59 +243,64 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
return EXCEPTION_TRANSLATION.translate(ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.springframework.data.redis.connection.RedisCommands commands() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisGeoCommands geoCommands() {
|
||||
return new LettuceGeoCommands(this);
|
||||
return geoCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHashCommands hashCommands() {
|
||||
return new LettuceHashCommands(this);
|
||||
return hashCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisHyperLogLogCommands hyperLogLogCommands() {
|
||||
return new LettuceHyperLogLogCommands(this);
|
||||
return hllCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisKeyCommands keyCommands() {
|
||||
return new LettuceKeyCommands(this);
|
||||
return keyCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisListCommands listCommands() {
|
||||
return new LettuceListCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSetCommands setCommands() {
|
||||
return new LettuceSetCommands(this);
|
||||
return listCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisScriptingCommands scriptingCommands() {
|
||||
return new LettuceScriptingCommands(this);
|
||||
return scriptingCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return new LettuceStreamCommands(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return new LettuceStringCommands(this);
|
||||
public RedisSetCommands setCommands() {
|
||||
return setCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisServerCommands serverCommands() {
|
||||
return new LettuceServerCommands(this);
|
||||
return serverCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStreamCommands streamCommands() {
|
||||
return streamCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisStringCommands stringCommands() {
|
||||
return stringCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSetCommands zSetCommands() {
|
||||
return new LettuceZSetCommands(this);
|
||||
return zSetCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user