DATAREDIS-692 - Polishing.

Add NonNullFields to packages. Add missing Nullable annotations. Extend Javadoc. Replace simple equals/hashCode methods using Lomboks EqualsAndHashCode annotation. Use RequiredArgsConstructor for private classes in favor of own constructors. Replace null-checks with qualified access whether objects are empty/applicable. Rearrange methods according to interface ordering.

Remove demo code from KeyspaceConfiguration.

Original pull request: #277.
This commit is contained in:
Mark Paluch
2017-09-19 12:25:13 +02:00
parent 5ca5e9f9c3
commit 6cc383b10a
210 changed files with 5833 additions and 3308 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 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.
@@ -20,8 +20,9 @@ import org.springframework.dao.DataRetrievalFailureException;
/**
* {@link ClusterRedirectException} indicates that a requested slot is not served by the targeted server but can be
* obtained on another one.
*
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
public class ClusterRedirectException extends DataRetrievalFailureException {
@@ -34,11 +35,11 @@ public class ClusterRedirectException extends DataRetrievalFailureException {
/**
* Creates new {@link ClusterRedirectException}.
*
*
* @param slot the slot to redirect to.
* @param targetHost the host to redirect to.
* @param targetPort the port on the host.
* @param e the root cause from the data access API in use
* @param e the root cause from the data access API in use.
*/
public ClusterRedirectException(int slot, String targetHost, int targetPort, Throwable e) {
@@ -50,27 +51,21 @@ public class ClusterRedirectException extends DataRetrievalFailureException {
}
/**
* Get slot to go for.
*
* @return
* @return the slot to go for.
*/
public int getSlot() {
return slot;
}
/**
* Get host serving the slot.
*
* @return
* @return host serving the slot.
*/
public String getTargetHost() {
return host;
}
/**
* Get port on host serving the slot.
*
* @return
* @return port on host serving the slot.
*/
public int getTargetPort() {
return port;

View File

@@ -21,7 +21,7 @@ import org.springframework.dao.DataAccessResourceFailureException;
* {@link DataAccessResourceFailureException} indicating the current local snapshot of cluster state does no longer
* represent the actual remote state. This can happen nodes are removed from cluster, slots get migrated to other nodes
* and so on.
*
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
@@ -32,8 +32,8 @@ public class ClusterStateFailureException extends DataAccessResourceFailureExcep
/**
* Creates new {@link ClusterStateFailureException}.
*
* @param msg
*
* @param msg the detail message.
*/
public ClusterStateFailureException(String msg) {
super(msg);
@@ -41,9 +41,9 @@ public class ClusterStateFailureException extends DataAccessResourceFailureExcep
/**
* Creates new {@link ClusterStateFailureException}.
*
* @param msg
* @param cause
*
* @param msg the detail message.
* @param cause the nested exception.
*/
public ClusterStateFailureException(String msg, Throwable cause) {
super(msg, cause);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
@@ -20,9 +20,10 @@ import org.springframework.dao.DataAccessException;
/**
* {@link FallbackExceptionTranslationStrategy} returns {@link RedisSystemException} for unknown {@link Exception}s.
*
*
* @author Christoph Strobl
* @author Thomas Darimont
* @author Mark Paluch
* @since 1.4
*/
public class FallbackExceptionTranslationStrategy extends PassThroughExceptionTranslationStrategy {
@@ -31,6 +32,10 @@ public class FallbackExceptionTranslationStrategy extends PassThroughExceptionTr
super(converter);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.PassThroughExceptionTranslationStrategy#translate(java.lang.Exception)
*/
@Override
public DataAccessException translate(Exception e) {
@@ -40,11 +45,12 @@ public class FallbackExceptionTranslationStrategy extends PassThroughExceptionTr
/**
* Returns a new {@link RedisSystemException} wrapping the given {@link Exception}.
*
* @param e
* @return
*
* @param e causing exception.
* @return the fallback exception.
*/
protected RedisSystemException getFallback(Exception e) {
return new RedisSystemException("Unknown redis exception", e);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
@@ -17,23 +17,31 @@ package org.springframework.data.redis;
import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* {@link PassThroughExceptionTranslationStrategy} returns {@literal null} for unknown {@link Exception}s.
*
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.4
*/
public class PassThroughExceptionTranslationStrategy implements ExceptionTranslationStrategy {
private Converter<Exception, DataAccessException> converter;
private final Converter<Exception, DataAccessException> converter;
public PassThroughExceptionTranslationStrategy(Converter<Exception, DataAccessException> converter) {
this.converter = converter;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.ExceptionTranslationStrategy#translate(java.lang.Exception)
*/
@Nullable
@Override
public DataAccessException translate(Exception e) {
return this.converter.convert(e);
}
}

View File

@@ -13,23 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis;
import org.springframework.dao.DataAccessResourceFailureException;
/**
* Fatal exception thrown when the Redis connection fails completely.
*
*
* @author Mark Pollack
*/
public class RedisConnectionFailureException extends DataAccessResourceFailureException {
/**
* @param msg the detail message.
*/
public RedisConnectionFailureException(String msg) {
super(msg);
}
/**
* @param msg the detail message.
* @param cause the nested exception.
*/
public RedisConnectionFailureException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -13,19 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis;
import org.springframework.dao.UncategorizedDataAccessException;
/**
* Exception thrown when we can't classify a Redis exception into one of Spring generic data access exceptions.
*
*
* @author Costin Leau
*/
public class RedisSystemException extends UncategorizedDataAccessException {
/**
* @param msg the detail message.
* @param cause the root cause from the data access API in use.
*/
public RedisSystemException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -19,7 +19,7 @@ import org.springframework.dao.DataRetrievalFailureException;
/**
* {@link DataRetrievalFailureException} thrown when following cluster redirects exceeds the max number of edges.
*
*
* @author Christoph Strobl
* @since 1.7
*/
@@ -29,8 +29,8 @@ public class TooManyClusterRedirectionsException extends DataRetrievalFailureExc
/**
* Creates new {@link TooManyClusterRedirectionsException}.
*
* @param msg
*
* @param msg the detail message.
*/
public TooManyClusterRedirectionsException(String msg) {
super(msg);
@@ -38,9 +38,9 @@ public class TooManyClusterRedirectionsException extends DataRetrievalFailureExc
/**
* Creates new {@link TooManyClusterRedirectionsException}.
*
* @param msg
* @param cause
*
* @param msg the detail message.
* @param cause the root cause from the data access API in use.
*/
public TooManyClusterRedirectionsException(String msg, Throwable cause) {
super(msg, cause);

View File

@@ -292,7 +292,7 @@ public class RedisCache extends AbstractValueAdaptingCache {
}
throw new IllegalStateException(
"Cannot convert " + source + " to String. Register a Converter or override toString().");
String.format("Cannot convert %s to String. Register a Converter or override toString().", source));
}
private byte[] createAndConvertCacheKey(Object key) {
@@ -303,7 +303,7 @@ public class RedisCache extends AbstractValueAdaptingCache {
return cacheConfig.getKeyPrefix().orElseGet(() -> name + "::") + key;
}
private <T> T valueFromLoader(Object key, Callable<T> valueLoader) {
private static <T> T valueFromLoader(Object key, Callable<T> valueLoader) {
try {
return valueLoader.call();

View File

@@ -1,6 +1,8 @@
/**
* Package providing a Redis implementation for Spring
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html">cache abstraction</a>.
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache">cache
* abstraction</a>.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.cache;

View File

@@ -49,6 +49,7 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser {
@SuppressWarnings("unchecked")
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
// parse attributes (but replace the value assignment with references)
NamedNodeMap attributes = element.getAttributes();
@@ -73,8 +74,7 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser {
List<Element> listDefs = DomUtils.getChildElementsByTagName(element, "listener");
if (!listDefs.isEmpty()) {
ManagedMap<BeanDefinition, Collection<? extends BeanDefinition>> listeners = new ManagedMap<>(
listDefs.size());
ManagedMap<BeanDefinition, Collection<? extends BeanDefinition>> listeners = new ManagedMap<>(listDefs.size());
for (Element listElement : listDefs) {
Object[] listenerDefinition = parseListener(listElement);
listeners.put((BeanDefinition) listenerDefinition[0],
@@ -97,6 +97,7 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser {
* @return
*/
private Object[] parseListener(Element element) {
Object[] ret = new Object[2];
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageListenerAdapter.class);

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 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
*
*
* http://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.
@@ -20,12 +20,13 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
* {@link NamespaceHandler} for Spring Data Redis namespace.
*
*
* @author Costin Leau
*/
class RedisNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("listener-container", new RedisListenerContainerParser());
registerBeanDefinitionParser("collection", new RedisCollectionParser());
}

View File

@@ -2,4 +2,5 @@
* Namespace and configuration.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.config;

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.connection;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.DataAccessException;
@@ -33,7 +34,7 @@ import org.springframework.util.Assert;
public abstract class AbstractRedisConnection implements DefaultedRedisConnection {
private @Nullable RedisSentinelConfiguration sentinelConfiguration;
private ConcurrentHashMap<RedisNode, RedisSentinelConnection> connectionCache = new ConcurrentHashMap<>();
private final Map<RedisNode, RedisSentinelConnection> connectionCache = new ConcurrentHashMap<>();
/*
* (non-Javadoc)

View File

@@ -23,8 +23,9 @@ import org.springframework.dao.UncategorizedDataAccessException;
/**
* Exception thrown when at least one call to a clustered redis environment fails.
*
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
public class ClusterCommandExecutionFailureException extends UncategorizedDataAccessException {
@@ -35,7 +36,7 @@ public class ClusterCommandExecutionFailureException extends UncategorizedDataAc
/**
* Creates new {@link ClusterCommandExecutionFailureException}.
*
*
* @param cause must not be {@literal null}.
*/
public ClusterCommandExecutionFailureException(Throwable cause) {
@@ -44,19 +45,22 @@ public class ClusterCommandExecutionFailureException extends UncategorizedDataAc
/**
* Creates new {@link ClusterCommandExecutionFailureException}.
*
*
* @param causes must not be {@literal empty}.
*/
public ClusterCommandExecutionFailureException(List<? extends Throwable> causes) {
super(causes.get(0).getMessage(), causes.get(0));
this.causes = causes;
causes.forEach(this::addSuppressed);
}
/**
* Get the collected errors.
*
*
* @return never {@literal null}.
* @deprecated since 2.0, use {@link #getSuppressed()}.
*/
public Collection<? extends Throwable> getCauses() {
return causes;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.connection;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -140,7 +141,7 @@ public class ClusterTopology {
}
throw new ClusterStateFailureException(
String.format("Could not find master node serving slot %s for key '%s',", slot, key));
String.format("Could not find master node serving slot %s for key '%s',", slot, Arrays.toString(key)));
}
/**

View File

@@ -26,7 +26,7 @@ public interface ClusterTopologyProvider {
/**
* Get the current known {@link ClusterTopology}.
*
* @return never {@null}.
* @return never {@literal null}.
*/
ClusterTopology getTopology();

View File

@@ -16,8 +16,11 @@
package org.springframework.data.redis.connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.lang.Nullable;
/**
* Default implementation for {@link SortParameters}.
*
@@ -25,11 +28,11 @@ import java.util.List;
*/
public class DefaultSortParameters implements SortParameters {
private byte[] byPattern;
private Range limit;
private @Nullable byte[] byPattern;
private @Nullable Range limit;
private final List<byte[]> getPattern = new ArrayList<>(4);
private Order order;
private Boolean alphabetic;
private @Nullable Order order;
private @Nullable Boolean alphabetic;
/**
* Constructs a new <code>DefaultSortParameters</code> instance.
@@ -45,7 +48,7 @@ public class DefaultSortParameters implements SortParameters {
* @param order
* @param alphabetic
*/
public DefaultSortParameters(Range limit, Order order, Boolean alphabetic) {
public DefaultSortParameters(@Nullable Range limit, @Nullable Order order, @Nullable Boolean alphabetic) {
this(null, limit, null, order, alphabetic);
}
@@ -58,7 +61,8 @@ public class DefaultSortParameters implements SortParameters {
* @param order
* @param alphabetic
*/
public DefaultSortParameters(byte[] byPattern, Range limit, byte[][] getPattern, Order order, Boolean alphabetic) {
public DefaultSortParameters(@Nullable byte[] byPattern, @Nullable Range limit, @Nullable byte[][] getPattern,
@Nullable Order order, @Nullable Boolean alphabetic) {
super();
this.byPattern = byPattern;
this.limit = limit;
@@ -67,6 +71,7 @@ public class DefaultSortParameters implements SortParameters {
setGetPattern(getPattern);
}
@Nullable
public byte[] getByPattern() {
return byPattern;
}
@@ -87,22 +92,22 @@ public class DefaultSortParameters implements SortParameters {
return getPattern.toArray(new byte[getPattern.size()][]);
}
@Nullable
public void addGetPattern(byte[] gPattern) {
getPattern.add(gPattern);
}
public void setGetPattern(byte[][] gPattern) {
public void setGetPattern(@Nullable byte[][] gPattern) {
getPattern.clear();
if (gPattern == null) {
return;
}
for (byte[] bs : gPattern) {
getPattern.add(bs);
}
Collections.addAll(getPattern, gPattern);
}
@Nullable
public Order getOrder() {
return order;
}
@@ -111,6 +116,7 @@ public class DefaultSortParameters implements SortParameters {
this.order = order;
}
@Nullable
public Boolean isAlphabetic() {
return alphabetic;
}

View File

@@ -796,8 +796,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
*/
@Override
public void rename(byte[] oldName, byte[] newName) {
delegate.rename(oldName, newName);
public void rename(byte[] sourceKey, byte[] targetKey) {
delegate.rename(sourceKey, targetKey);
}
/*
@@ -805,8 +805,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(byte[] oldName, byte[] newName) {
return convertAndReturn(delegate.renameNX(oldName, newName), identityConverter);
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
return convertAndReturn(delegate.renameNX(sourceKey, targetKey), identityConverter);
}
/*
@@ -1129,8 +1129,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[], long, long)
*/
@Override
public Long bitCount(byte[] key, long begin, long end) {
return convertAndReturn(delegate.bitCount(key, begin, end), identityConverter);
public Long bitCount(byte[] key, long start, long end) {
return convertAndReturn(delegate.bitCount(key, start, end), identityConverter);
}
/*
@@ -2420,8 +2420,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
* @see org.springframework.data.redis.connection.StringRedisConnection#bitCount(java.lang.String, long, long)
*/
@Override
public Long bitCount(String key, long begin, long end) {
return bitCount(serialize(key), begin, end);
public Long bitCount(String key, long start, long end) {
return bitCount(serialize(key), start, end);
}
/*
@@ -3463,7 +3463,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@SuppressWarnings("unchecked")
private <T> T convertAndReturn(Object value, Converter converter) {
@Nullable
private <T> T convertAndReturn(@Nullable Object value, Converter converter) {
if (isFutureConversion()) {
@@ -3488,7 +3489,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<Object> convertResults(List<Object> results, Queue<Converter> converters) {
private List<Object> convertResults(@Nullable List<Object> results, Queue<Converter> converters) {
if (!deserializePipelineAndTxResults || results == null) {
return results;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 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
*
*
* http://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.
@@ -15,21 +15,24 @@
*/
package org.springframework.data.redis.connection;
import lombok.EqualsAndHashCode;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
/**
* Default implementation for {@link StringTuple} interface.
*
*
* @author Costin Leau
*/
@EqualsAndHashCode(callSuper = true)
public class DefaultStringTuple extends DefaultTuple implements StringTuple {
private final String valueAsString;
/**
* Constructs a new <code>DefaultStringTuple</code> instance.
*
*
* @param value
* @param score
*/
@@ -41,7 +44,7 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple {
/**
* Constructs a new <code>DefaultStringTuple</code> instance.
*
*
* @param tuple
* @param valueAsString
*/
@@ -54,28 +57,6 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple {
return valueAsString;
}
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((valueAsString == null) ? 0 : valueAsString.hashCode());
return result;
}
public boolean equals(Object obj) {
if (super.equals(obj)) {
if (!(obj instanceof DefaultStringTuple))
return false;
DefaultStringTuple other = (DefaultStringTuple) obj;
if (valueAsString == null) {
if (other.valueAsString != null)
return false;
} else if (!valueAsString.equals(other.valueAsString))
return false;
return true;
}
return false;
}
public String toString() {
return "DefaultStringTuple[value=" + getValueAsString() + ", score=" + getScore() + "]";
}

View File

@@ -92,15 +92,15 @@ public interface DefaultedRedisConnection extends RedisConnection {
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
@Override
@Deprecated
default void rename(byte[] oldName, byte[] newName) {
keyCommands().rename(oldName, newName);
default void rename(byte[] sourceKey, byte[] targetKey) {
keyCommands().rename(sourceKey, targetKey);
}
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
@Override
@Deprecated
default Boolean renameNX(byte[] oldName, byte[] newName) {
return keyCommands().renameNX(oldName, newName);
default Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
return keyCommands().renameNX(sourceKey, targetKey);
}
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
@@ -318,8 +318,8 @@ public interface DefaultedRedisConnection extends RedisConnection {
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
default byte[] getRange(byte[] key, long begin, long end) {
return stringCommands().getRange(key, begin, end);
default byte[] getRange(byte[] key, long start, long end) {
return stringCommands().getRange(key, start, end);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@@ -353,8 +353,8 @@ public interface DefaultedRedisConnection extends RedisConnection {
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */
@Override
@Deprecated
default Long bitCount(byte[] key, long begin, long end) {
return stringCommands().bitCount(key, begin, end);
default Long bitCount(byte[] key, long start, long end) {
return stringCommands().bitCount(key, start, end);
}
/** @deprecated in favor of {@link RedisConnection#stringCommands()}}. */

View File

@@ -20,12 +20,13 @@ import org.springframework.lang.Nullable;
/**
* The result of an asynchronous operation
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
* @param <T> The data type of the object that holds the future result (usually of type Future)
*/
abstract public class FutureResult<T> {
public abstract class FutureResult<T> {
protected T resultHolder;
@@ -50,7 +51,7 @@ abstract public class FutureResult<T> {
/**
* Converts the given result if a converter is specified, else returns the result
*
*
* @param result The result to convert. Can be {@literal null}.
* @return The converted result or {@literal null}.
*/
@@ -73,7 +74,7 @@ abstract public class FutureResult<T> {
/**
* Indicates if this result is the status of an operation. Typically status results will be discarded on conversion.
*
*
* @return true if this is a status result (i.e. OK)
*/
public boolean isStatus() {
@@ -91,5 +92,5 @@ abstract public class FutureResult<T> {
* @return The result of the operation. Can be {@literal null}.
*/
@Nullable
abstract public Object get();
public abstract Object get();
}

View File

@@ -20,9 +20,10 @@ import org.springframework.lang.Nullable;
/**
* Exception thrown when there are issues with a resource pool
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
*/
@SuppressWarnings("serial")
public class PoolException extends NestedRuntimeException {
@@ -30,19 +31,19 @@ public class PoolException extends NestedRuntimeException {
/**
* Constructs a new <code>PoolException</code> instance.
*
* @param msg
* @param cause
* @param msg the detail message.
*/
public PoolException(@Nullable String msg, @Nullable Throwable cause) {
super(msg, cause);
public PoolException(String msg) {
super(msg);
}
/**
* Constructs a new <code>PoolException</code> instance.
*
* @param msg
* @param msg the detail message.
* @param cause the nested exception.
*/
public PoolException(String msg) {
super(msg);
public PoolException(@Nullable String msg, @Nullable Throwable cause) {
super(msg, cause);
}
}

View File

@@ -261,7 +261,7 @@ public interface ReactiveListCommands {
Flux<NumericResponse<KeyCommand, Long>> lLen(Publisher<KeyCommand> commands);
/**
* Get elements between {@literal begin} and {@literal end} from list at {@literal key}.
* Get elements between {@literal start} and {@literal end} from list at {@literal key}.
*
* @param key must not be {@literal null}.
* @param start
@@ -286,7 +286,7 @@ public interface ReactiveListCommands {
Flux<CommandResponse<RangeCommand, Flux<ByteBuffer>>> lRange(Publisher<RangeCommand> commands);
/**
* Trim list at {@literal key} to elements between {@literal begin} and {@literal end}.
* Trim list at {@literal key} to elements between {@literal start} and {@literal end}.
*
* @param key must not be {@literal null}.
* @param start

View File

@@ -519,25 +519,25 @@ public interface ReactiveStringCommands {
Flux<NumericResponse<AppendCommand, Long>> append(Publisher<AppendCommand> commands);
/**
* Get a substring of value of {@literal key} between {@literal begin} and {@literal end}.
* Get a substring of value of {@literal key} between {@literal start} and {@literal end}.
*
* @param key must not be {@literal null}.
* @param begin
* @param start
* @param end
* @return
* @see <a href="http://redis.io/commands/getrange">Redis Documentation: GETRANGE</a>
*/
default Mono<ByteBuffer> getRange(ByteBuffer key, long begin, long end) {
default Mono<ByteBuffer> getRange(ByteBuffer key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
return getRange(Mono.just(RangeCommand.key(key).fromIndex(begin).toIndex(end))) //
return getRange(Mono.just(RangeCommand.key(key).fromIndex(start).toIndex(end))) //
.next() //
.map(ByteBufferResponse::getOutput);
}
/**
* Get a substring of value of {@literal key} between {@literal begin} and {@literal end}.
* Get a substring of value of {@literal key} between {@literal start} and {@literal end}.
*
* @param commands must not be {@literal null}.
* @return
@@ -875,25 +875,25 @@ public interface ReactiveStringCommands {
}
/**
* Count the number of set bits (population counting) of value stored at {@literal key} between {@literal begin} and
* Count the number of set bits (population counting) of value stored at {@literal key} between {@literal start} and
* {@literal end}.
*
* @param key must not be {@literal null}.
* @param begin
* @param start
* @param end
* @return
* @see <a href="http://redis.io/commands/bitcount">Redis Documentation: BITCOUNT</a>
*/
default Mono<Long> bitCount(ByteBuffer key, long begin, long end) {
default Mono<Long> bitCount(ByteBuffer key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
return bitCount(Mono.just(BitCountCommand.bitCount(key).within(new Range<>(begin, end)))).next()
return bitCount(Mono.just(BitCountCommand.bitCount(key).within(new Range<>(start, end)))).next()
.map(NumericResponse::getOutput);
}
/**
* Count the number of set bits (population counting) of value stored at {@literal key} between {@literal begin} and
* Count the number of set bits (population counting) of value stored at {@literal key} between {@literal start} and
* {@literal end}.
*
* @param commands must not be {@literal null}.

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 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
*
*
* http://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.
@@ -25,7 +25,7 @@ import org.springframework.lang.Nullable;
/**
* Key-specific commands supported by Redis.
*
*
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
@@ -92,24 +92,24 @@ public interface RedisKeyCommands {
byte[] randomKey();
/**
* Rename key {@code oldName} to {@code newName}.
* Rename key {@code sourceKey} to {@code targetKey}.
*
* @param oldName must not be {@literal null}.
* @param newName must not be {@literal null}.
* @param sourceKey must not be {@literal null}.
* @param targetKey must not be {@literal null}.
* @see <a href="http://redis.io/commands/rename">Redis Documentation: RENAME</a>
*/
void rename(byte[] oldName, byte[] newName);
void rename(byte[] sourceKey, byte[] targetKey);
/**
* Rename key {@code oldName} to {@code newName} only if {@code newName} does not exist.
* Rename key {@code sourceKey} to {@code targetKey} only if {@code targetKey} does not exist.
*
* @param oldName must not be {@literal null}.
* @param newName must not be {@literal null}.
* @param sourceKey must not be {@literal null}.
* @param targetKey must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
*/
@Nullable
Boolean renameNX(byte[] oldName, byte[] newName);
Boolean renameNX(byte[] sourceKey, byte[] targetKey);
/**
* Set time to live for given {@code key} in seconds.

View File

@@ -21,7 +21,7 @@ import org.springframework.lang.Nullable;
/**
* List-specific commands supported by Redis.
*
*
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch

View File

@@ -24,6 +24,7 @@ import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.Function;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -53,7 +54,7 @@ public class RedisPassword {
* @param passwordAsString the password as string.
* @return the {@link RedisPassword} for {@code passwordAsString}.
*/
public static RedisPassword of(String passwordAsString) {
public static RedisPassword of(@Nullable String passwordAsString) {
return Optional.ofNullable(passwordAsString) //
.filter(StringUtils::hasText) //
@@ -67,7 +68,7 @@ public class RedisPassword {
* @param passwordAsChars the password as char array.
* @return the {@link RedisPassword} for {@code passwordAsChars}.
*/
public static RedisPassword of(char[] passwordAsChars) {
public static RedisPassword of(@Nullable char[] passwordAsChars) {
return Optional.ofNullable(passwordAsChars) //
.filter(it -> !ObjectUtils.isEmpty(passwordAsChars)) //
@@ -133,7 +134,7 @@ public class RedisPassword {
public Optional<char[]> toOptional() {
if (isPresent()) {
return Optional.ofNullable(get());
return Optional.of(get());
}
return Optional.empty();

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 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
*
*
* http://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.
@@ -19,7 +19,7 @@ import org.springframework.lang.Nullable;
/**
* PubSub-specific Redis commands.
*
*
* @author Costin Leau
* @author Mark Paluch
* @author Christoph Strobl
@@ -46,9 +46,10 @@ public interface RedisPubSubCommands {
*
* @param channel the channel to publish to. Must not be {@literal null}.
* @param message message to publish. Must not be {@literal null}.
* @return the number of clients that received the message.
* @return the number of clients that received the message or {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/publish">Redis Documentation: PUBLISH</a>
*/
@Nullable
Long publish(byte[] channel, byte[] message);
/**

View File

@@ -23,7 +23,7 @@ import org.springframework.lang.Nullable;
/**
* String/Value-specific commands supported by Redis.
*
*
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
@@ -92,9 +92,10 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/setnx">Redis Documentation: SETNX</a>
*/
@Nullable
Boolean setNX(byte[] key, byte[] value);
/**
@@ -131,17 +132,20 @@ public interface RedisStringCommands {
* not exist.
*
* @param tuple must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/msetnx">Redis Documentation: MSETNX</a>
*/
@Nullable
Boolean mSetNX(Map<byte[], byte[]> tuple);
/**
* Increment an integer value stored as string value of {@code key} by 1.
*
* @param key must not be {@literal null}.
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/incr">Redis Documentation: INCR</a>
*/
@Nullable
Long incr(byte[] key);
/**
@@ -149,9 +153,10 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/incrby">Redis Documentation: INCRBY</a>
*/
@Nullable
Long incrBy(byte[] key, long value);
/**
@@ -159,18 +164,20 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/incrbyfloat">Redis Documentation: INCRBYFLOAT</a>
*/
@Nullable
Double incrBy(byte[] key, double value);
/**
* Decrement an integer value stored as string value of {@code key} by 1.
*
* @param key must not be {@literal null}.
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/decr">Redis Documentation: DECR</a>
*/
@Nullable
Long decr(byte[] key);
/**
@@ -178,9 +185,10 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param value
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/decrby">Redis Documentation: DECRBY</a>
*/
@Nullable
Long decrBy(byte[] key, long value);
/**
@@ -188,21 +196,23 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/append">Redis Documentation: APPEND</a>
*/
@Nullable
Long append(byte[] key, byte[] value);
/**
* Get a substring of value of {@code key} between {@code begin} and {@code end}.
* Get a substring of value of {@code key} between {@code start} and {@code end}.
*
* @param key must not be {@literal null}.
* @param begin
* @param start
* @param end
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/getrange">Redis Documentation: GETRANGE</a>
*/
byte[] getRange(byte[] key, long begin, long end);
@Nullable
byte[] getRange(byte[] key, long start, long end);
/**
* Overwrite parts of {@code key} starting at the specified {@code offset} with given {@code value}.
@@ -219,9 +229,10 @@ public interface RedisStringCommands {
*
* @param key must not be {@literal null}.
* @param offset
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/getbit">Redis Documentation: GETBIT</a>
*/
@Nullable
Boolean getBit(byte[] key, long offset);
/**
@@ -230,31 +241,34 @@ public interface RedisStringCommands {
* @param key must not be {@literal null}.
* @param offset
* @param value
* @return the original bit value stored at {@code offset}.
* @return the original bit value stored at {@code offset} or {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/setbit">Redis Documentation: SETBIT</a>
*/
@Nullable
Boolean setBit(byte[] key, long offset, boolean value);
/**
* Count the number of set bits (population counting) in value stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/bitcount">Redis Documentation: BITCOUNT</a>
*/
@Nullable
Long bitCount(byte[] key);
/**
* Count the number of set bits (population counting) of value stored at {@code key} between {@code begin} and
* Count the number of set bits (population counting) of value stored at {@code key} between {@code start} and
* {@code end}.
*
* @param key must not be {@literal null}.
* @param begin
* @param start
* @param end
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/bitcount">Redis Documentation: BITCOUNT</a>
*/
Long bitCount(byte[] key, long begin, long end);
@Nullable
Long bitCount(byte[] key, long start, long end);
/**
* Perform bitwise operations between strings.
@@ -262,23 +276,25 @@ public interface RedisStringCommands {
* @param op must not be {@literal null}.
* @param destination must not be {@literal null}.
* @param keys must not be {@literal null}.
* @return never {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/bitop">Redis Documentation: BITOP</a>
*/
@Nullable
Long bitOp(BitOperation op, byte[] destination, byte[]... keys);
/**
* Get the length of the value stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/strlen">Redis Documentation: STRLEN</a>
*/
@Nullable
Long strLen(byte[] key);
/**
* {@code SET} command arguments for {@code NX}, {@code XX}.
*
*
* @author Christoph Strobl
* @since 1.7
*/
@@ -286,28 +302,28 @@ public interface RedisStringCommands {
/**
* Do not set any additional command argument.
*
*
* @return
*/
UPSERT,
/**
* {@code NX}
*
*
* @return
*/
SET_IF_ABSENT,
/**
* {@code XX}
*
*
* @return
*/
SET_IF_PRESENT;
/**
* Do not set any additional command argument.
*
*
* @return
*/
public static SetOption upsert() {
@@ -316,7 +332,7 @@ public interface RedisStringCommands {
/**
* {@code XX}
*
*
* @return
*/
public static SetOption ifPresent() {
@@ -325,7 +341,7 @@ public interface RedisStringCommands {
/**
* {@code NX}
*
*
* @return
*/
public static SetOption ifAbsent() {

View File

@@ -102,7 +102,7 @@ abstract public class Converters {
Set<Flag> flags = parseFlags(args);
String portPart = hostAndPort[1];
if (portPart != null && portPart.contains("@")) {
if (portPart.contains("@")) {
portPart = portPart.substring(0, portPart.indexOf('@'));
}
@@ -171,8 +171,7 @@ abstract public class Converters {
}
}
SlotRange range = new SlotRange(slots);
return range;
return new SlotRange(slots);
}
};

View File

@@ -47,7 +47,8 @@ public class ListConverter<S, T> implements Converter<List<S>, List<T>> {
@Override
public List<T> convert(List<S> source) {
List<T> results = new ArrayList<>();
List<T> results = new ArrayList<>(source.size());
for (S result : source) {
results.add(itemConverter.convert(result));
}

View File

@@ -2,4 +2,5 @@
* Redis specific converters used for sending data and parsing responses.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.connection.convert;

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.redis.connection.jedis;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.HostAndPort;
@@ -38,6 +36,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.PropertyAccessor;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.ClusterStateFailureException;
import org.springframework.data.redis.ExceptionTranslationStrategy;
@@ -49,6 +48,7 @@ import org.springframework.data.redis.connection.ClusterCommandExecutor.NodeResu
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -101,7 +101,6 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
} catch (Exception e) {
// ignore it and work with the executor default
}
}
/**
@@ -229,7 +228,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
}
@Override
public Set<byte[]> keys(RedisClusterNode node, final byte[] pattern) {
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
return doGetKeyCommands().keys(node, pattern);
}
@@ -351,7 +350,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int)
*/
@Override
public void select(final int dbIndex) {
public void select(int dbIndex) {
if (dbIndex != 0) {
throw new InvalidDataAccessApiUsageException("Cannot SELECT non zero index in cluster mode.");
@@ -363,7 +362,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisConnectionCommands#echo(byte[])
*/
@Override
public byte[] echo(final byte[] message) {
public byte[] echo(byte[] message) {
try {
return cluster.echo(message);
@@ -404,13 +403,13 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterSetSlot(org.springframework.data.redis.connection.RedisClusterNode, int, org.springframework.data.redis.connection.RedisClusterCommands.AddSlots)
*/
@Override
public void clusterSetSlot(final RedisClusterNode node, final int slot, final AddSlots mode) {
public void clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode) {
Assert.notNull(node, "Node must not be null.");
Assert.notNull(mode, "AddSlots mode must not be null.");
final RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
final String nodeId = nodeToUse.getId();
RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
String nodeId = nodeToUse.getId();
clusterCommandExecutor.executeCommandOnSingleNode((JedisClusterCommandCallback<String>) client -> {
@@ -435,7 +434,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetKeysInSlot(int, java.lang.Integer)
*/
@Override
public List<byte[]> clusterGetKeysInSlot(final int slot, final Integer count) {
public List<byte[]> clusterGetKeysInSlot(int slot, Integer count) {
RedisClusterNode node = clusterGetNodeForSlot(slot);
@@ -452,11 +451,10 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterAddSlots(org.springframework.data.redis.connection.RedisClusterNode, int[])
*/
@Override
public void clusterAddSlots(RedisClusterNode node, final int... slots) {
public void clusterAddSlots(RedisClusterNode node, int... slots) {
clusterCommandExecutor.executeCommandOnSingleNode(
(JedisClusterCommandCallback<String>) client -> client.clusterAddSlots(slots), node);
}
/*
@@ -476,7 +474,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterCountKeysInSlot(int)
*/
@Override
public Long clusterCountKeysInSlot(final int slot) {
public Long clusterCountKeysInSlot(int slot) {
RedisClusterNode node = clusterGetNodeForSlot(slot);
@@ -490,7 +488,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterDeleteSlots(org.springframework.data.redis.connection.RedisClusterNode, int[])
*/
@Override
public void clusterDeleteSlots(RedisClusterNode node, final int... slots) {
public void clusterDeleteSlots(RedisClusterNode node, int... slots) {
clusterCommandExecutor.executeCommandOnSingleNode(
(JedisClusterCommandCallback<String>) client -> client.clusterDelSlots(slots), node);
@@ -514,10 +512,10 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterForget(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterForget(final RedisClusterNode node) {
public void clusterForget(RedisClusterNode node) {
Set<RedisClusterNode> nodes = new LinkedHashSet<>(topologyProvider.getTopology().getActiveMasterNodes());
final RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
nodes.remove(nodeToRemove);
clusterCommandExecutor.executeCommandAsyncOnNodes(
@@ -529,7 +527,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterMeet(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterMeet(final RedisClusterNode node) {
public void clusterMeet(RedisClusterNode node) {
Assert.notNull(node, "Cluster node must not be null for CLUSTER MEET command!");
Assert.hasText(node.getHost(), "Node to meet cluster must have a host!");
@@ -544,9 +542,9 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterReplicate(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterReplicate(final RedisClusterNode master, RedisClusterNode slave) {
public void clusterReplicate(RedisClusterNode master, RedisClusterNode slave) {
final RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);
RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);
clusterCommandExecutor.executeCommandOnSingleNode(
(JedisClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()), slave);
@@ -558,7 +556,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#getClusterSlotForKey(byte[])
*/
@Override
public Integer clusterGetSlotForKey(final byte[] key) {
public Integer clusterGetSlotForKey(byte[] key) {
return clusterCommandExecutor.executeCommandOnArbitraryNode((JedisClusterCommandCallback<Integer>) client -> client
.clusterKeySlot(JedisConverters.toString(key)).intValue()).getValue();
@@ -594,11 +592,11 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetSlaves(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public Set<RedisClusterNode> clusterGetSlaves(final RedisClusterNode master) {
public Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master) {
Assert.notNull(master, "Master cannot be null!");
final RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);
RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);
return JedisConverters.toSetOfRedisClusterNodes(clusterCommandExecutor
.executeCommandOnSingleNode(
@@ -785,7 +783,8 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster);
this.connectionHandler = accessor.isReadableProperty("connectionHandler")
? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null;
? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler")
: null;
} else {
this.connectionHandler = null;
}

View File

@@ -29,6 +29,7 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
@@ -50,6 +51,10 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Boolean hSet(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().hset(key, field, value));
} catch (Exception ex) {
@@ -64,6 +69,10 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().hsetnx(key, field, value));
} catch (Exception ex) {
@@ -78,6 +87,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public byte[] hGet(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
return connection.getCluster().hget(key, field);
} catch (Exception ex) {
@@ -92,6 +104,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public List<byte[]> hMGet(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
return connection.getCluster().hmget(key, fields);
} catch (Exception ex) {
@@ -106,6 +121,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public void hMSet(byte[] key, Map<byte[], byte[]> hashes) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(hashes, "Hashes must not be null!");
try {
connection.getCluster().hmset(key, hashes);
} catch (Exception ex) {
@@ -120,6 +138,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Long hIncrBy(byte[] key, byte[] field, long delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
return connection.getCluster().hincrBy(key, field, delta);
} catch (Exception ex) {
@@ -133,6 +154,10 @@ class JedisClusterHashCommands implements RedisHashCommands {
*/
@Override
public Double hIncrBy(byte[] key, byte[] field, double delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
return connection.getCluster().hincrByFloat(key, field, delta);
} catch (Exception ex) {
@@ -147,6 +172,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Boolean hExists(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
return connection.getCluster().hexists(key, field);
} catch (Exception ex) {
@@ -161,6 +189,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Long hDel(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
return connection.getCluster().hdel(key, fields);
} catch (Exception ex) {
@@ -175,6 +206,8 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Long hLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().hlen(key);
} catch (Exception ex) {
@@ -189,6 +222,8 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Set<byte[]> hKeys(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().hkeys(key);
} catch (Exception ex) {
@@ -203,6 +238,8 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public List<byte[]> hVals(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return new ArrayList<>(connection.getCluster().hvals(key));
} catch (Exception ex) {
@@ -217,6 +254,8 @@ class JedisClusterHashCommands implements RedisHashCommands {
@Override
public Map<byte[], byte[]> hGetAll(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().hgetAll(key);
} catch (Exception ex) {
@@ -229,7 +268,9 @@ class JedisClusterHashCommands implements RedisHashCommands {
* @see org.springframework.data.redis.connection.RedisHashCommands#hScan(byte[], org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<Entry<byte[], byte[]>> hScan(final byte[] key, ScanOptions options) {
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new ScanCursor<Entry<byte[], byte[]>>(options) {

View File

@@ -20,6 +20,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.RedisHyperLogLogCommands;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
@@ -41,6 +42,9 @@ class JedisClusterHyperLogLogCommands implements RedisHyperLogLogCommands {
@Override
public Long pfAdd(byte[] key, byte[]... values) {
Assert.notEmpty(values, "PFADD requires at least one non 'null' value.");
Assert.noNullElements(values, "Values for PFADD must not contain 'null'.");
try {
return connection.getCluster().pfadd(key, values);
} catch (Exception ex) {
@@ -55,6 +59,9 @@ class JedisClusterHyperLogLogCommands implements RedisHyperLogLogCommands {
@Override
public Long pfCount(byte[]... keys) {
Assert.notEmpty(keys, "PFCOUNT requires at least one non 'null' key.");
Assert.noNullElements(keys, "Keys for PFCOUNT must not contain 'null'.");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
@@ -74,6 +81,10 @@ class JedisClusterHyperLogLogCommands implements RedisHyperLogLogCommands {
@Override
public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
Assert.notNull(destinationKey, "Destination key must not be null");
Assert.notNull(sourceKeys, "Source keys must not be null");
Assert.noNullElements(sourceKeys, "Keys for PFMERGE must not contain 'null'.");
byte[][] allKeys = ByteUtils.mergeArrays(destinationKey, sourceKeys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {

View File

@@ -83,6 +83,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public DataType type(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toDataType(connection.getCluster().type(key));
} catch (Exception ex) {
@@ -95,7 +97,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#keys(byte[])
*/
@Override
public Set<byte[]> keys(final byte[] pattern) {
public Set<byte[]> keys(byte[] pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
@@ -114,8 +116,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterConnection#keys(org.springframework.data.redis.connection.RedisClusterNode, byte[])
*/
public Set<byte[]> keys(RedisClusterNode node, final byte[] pattern) {
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
Assert.notNull(node, "RedisClusterNode must not be null!");
Assert.notNull(pattern, "Pattern must not be null!");
return connection.getClusterCommandExecutor()
@@ -167,6 +170,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
*/
public byte[] randomKey(RedisClusterNode node) {
Assert.notNull(node, "RedisClusterNode must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.randomBinaryKey(), node)
.getValue();
@@ -177,7 +182,10 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
*/
@Override
public void rename(final byte[] sourceKey, final byte[] targetKey) {
public void rename(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
@@ -203,7 +211,10 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(final byte[] sourceKey, final byte[] targetKey) {
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
@@ -232,6 +243,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Boolean expire(byte[] key, long seconds) {
Assert.notNull(key, "Key must not be null!");
if (seconds > Integer.MAX_VALUE) {
throw new UnsupportedOperationException("Jedis does not support seconds exceeding Integer.MAX_VALUE.");
}
@@ -247,7 +260,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#pExpire(byte[], long)
*/
@Override
public Boolean pExpire(final byte[] key, final long millis) {
public Boolean pExpire(byte[] key, long millis) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().pexpire(key, millis));
@@ -263,6 +278,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Boolean expireAt(byte[] key, long unixTime) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().expireAt(key, unixTime));
} catch (Exception ex) {
@@ -277,6 +294,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().pexpireAt(key, unixTimeInMillis));
} catch (Exception ex) {
@@ -291,6 +310,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Boolean persist(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().persist(key));
} catch (Exception ex) {
@@ -314,6 +335,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Long ttl(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().ttl(key);
} catch (Exception ex) {
@@ -328,6 +351,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Long ttl(byte[] key, TimeUnit timeUnit) {
Assert.notNull(key, "Key must not be null!");
try {
return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit);
} catch (Exception ex) {
@@ -340,7 +365,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[])
*/
@Override
public Long pTtl(final byte[] key) {
public Long pTtl(byte[] key) {
Assert.notNull(key, "Key must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.pttl(key),
@@ -353,7 +380,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[], java.util.concurrent.TimeUnit)
*/
@Override
public Long pTtl(final byte[] key, final TimeUnit timeUnit) {
public Long pTtl(byte[] key, TimeUnit timeUnit) {
Assert.notNull(key, "Key must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode(
@@ -367,7 +396,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#dump(byte[])
*/
@Override
public byte[] dump(final byte[] key) {
public byte[] dump(byte[] key) {
Assert.notNull(key, "Key must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.dump(key),
@@ -380,7 +411,10 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#restore(byte[], long, byte[])
*/
@Override
public void restore(final byte[] key, final long ttlInMillis, final byte[] serializedValue) {
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(serializedValue, "Serialized value must not be null!");
if (ttlInMillis > Integer.MAX_VALUE) {
throw new UnsupportedOperationException("Jedis does not support ttlInMillis exceeding Integer.MAX_VALUE.");
@@ -392,12 +426,14 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#sort(byte[], org.springframework.data.redis.connection.SortParameters)
*/
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#sort(byte[], org.springframework.data.redis.connection.SortParameters)
*/
@Override
public List<byte[]> sort(byte[] key, SortParameters params) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().sort(key, JedisConverters.toSortingParams(params));
} catch (Exception ex) {
@@ -412,6 +448,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
@Override
public Long sort(byte[] key, SortParameters params, byte[] storeKey) {
Assert.notNull(key, "Key must not be null!");
List<byte[]> sorted = sort(key, params);
if (!CollectionUtils.isEmpty(sorted)) {
@@ -436,7 +474,9 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#exists(byte[])
*/
@Override
public Boolean exists(final byte[] key) {
public Boolean exists(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().exists(key);

View File

@@ -23,6 +23,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.RedisListCommands;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisMultiKeyClusterCommandCallback;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@@ -45,6 +46,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long rPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().rpush(key, values);
} catch (Exception ex) {
@@ -59,6 +62,10 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long lPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
return connection.getCluster().lpush(key, values);
} catch (Exception ex) {
@@ -73,6 +80,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long rPushX(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().rpushx(key, value);
} catch (Exception ex) {
@@ -87,6 +97,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long lPushX(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().lpushx(key, value);
} catch (Exception ex) {
@@ -101,6 +114,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long lLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().llen(key);
} catch (Exception ex) {
@@ -113,10 +128,12 @@ class JedisClusterListCommands implements RedisListCommands {
* @see org.springframework.data.redis.connection.RedisListCommands#lRange(byte[], long, long)
*/
@Override
public List<byte[]> lRange(byte[] key, long begin, long end) {
public List<byte[]> lRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().lrange(key, begin, end);
return connection.getCluster().lrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -127,10 +144,12 @@ class JedisClusterListCommands implements RedisListCommands {
* @see org.springframework.data.redis.connection.RedisListCommands#lTrim(byte[], long, long)
*/
@Override
public void lTrim(final byte[] key, final long begin, final long end) {
public void lTrim(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
connection.getCluster().ltrim(key, begin, end);
connection.getCluster().ltrim(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -143,6 +162,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public byte[] lIndex(byte[] key, long index) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().lindex(key, index);
} catch (Exception ex) {
@@ -157,6 +178,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().linsert(key, JedisConverters.toListPosition(where), pivot, value);
} catch (Exception ex) {
@@ -171,6 +194,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public void lSet(byte[] key, long index, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
connection.getCluster().lset(key, index, value);
} catch (Exception ex) {
@@ -185,6 +211,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public Long lRem(byte[] key, long count, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().lrem(key, count, value);
} catch (Exception ex) {
@@ -199,6 +228,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public byte[] lPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().lpop(key);
} catch (Exception ex) {
@@ -213,6 +244,8 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public byte[] rPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().rpop(key);
} catch (Exception ex) {
@@ -225,7 +258,10 @@ class JedisClusterListCommands implements RedisListCommands {
* @see org.springframework.data.redis.connection.RedisListCommands#bLPop(int, byte[][])
*/
@Override
public List<byte[]> bLPop(final int timeout, final byte[]... keys) {
public List<byte[]> bLPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
@@ -247,7 +283,10 @@ class JedisClusterListCommands implements RedisListCommands {
* @see org.springframework.data.redis.connection.RedisListCommands#bRPop(int, byte[][])
*/
@Override
public List<byte[]> bRPop(final int timeout, byte[]... keys) {
public List<byte[]> bRPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
return connection.getClusterCommandExecutor()
.executeMultiKeyCommand(
@@ -263,6 +302,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, dstKey)) {
try {
return connection.getCluster().rpoplpush(srcKey, dstKey);
@@ -283,6 +325,9 @@ class JedisClusterListCommands implements RedisListCommands {
@Override
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, dstKey)) {
try {
return connection.getCluster().brpoplpush(srcKey, dstKey, timeout);

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.redis.connection.jedis;
import org.springframework.lang.Nullable;
import redis.clients.jedis.BinaryJedis;
import java.util.ArrayList;
@@ -34,6 +33,7 @@ import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterCommandCallback;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -234,7 +234,9 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisServerCommands#info(java.lang.String)
*/
@Override
public Properties info(final String section) {
public Properties info(String section) {
Assert.notNull(section, "Section must not be null!");
Properties infos = new Properties();
@@ -257,7 +259,9 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#info(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String)
*/
@Override
public Properties info(RedisClusterNode node, final String section) {
public Properties info(RedisClusterNode node, String section) {
Assert.notNull(section, "Section must not be null!");
return JedisConverters.toProperties(executeCommandOnSingleNode(client -> client.info(section), node).getValue());
}
@@ -301,7 +305,9 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisServerCommands#getConfig(java.lang.String)
*/
@Override
public Properties getConfig(final String pattern) {
public Properties getConfig(String pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
List<NodeResult<List<String>>> mapResult = connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<List<String>>) client -> client.configGet(pattern))
@@ -325,7 +331,9 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#getConfig(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String)
*/
@Override
public Properties getConfig(RedisClusterNode node, final String pattern) {
public Properties getConfig(RedisClusterNode node, String pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
return connection.getClusterCommandExecutor().executeCommandOnSingleNode(
(JedisClusterCommandCallback<Properties>) client -> Converters.toProperties(client.configGet(pattern)), node)
@@ -337,7 +345,10 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisServerCommands#setConfig(java.lang.String, java.lang.String)
*/
@Override
public void setConfig(final String param, final String value) {
public void setConfig(String param, String value) {
Assert.notNull(param, "Parameter must not be null!");
Assert.notNull(value, "Value must not be null!");
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) client -> client.configSet(param, value));
@@ -348,7 +359,10 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#setConfig(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String, java.lang.String)
*/
@Override
public void setConfig(RedisClusterNode node, final String param, final String value) {
public void setConfig(RedisClusterNode node, String param, String value) {
Assert.notNull(param, "Parameter must not be null!");
Assert.notNull(value, "Value must not be null!");
executeCommandOnSingleNode(client -> client.configSet(param, value), node);
}
@@ -401,7 +415,8 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void killClient(String host, int port) {
final String hostAndPort = String.format("%s:%s", host, port);
Assert.hasText(host, "Host for 'CLIENT KILL' must not be 'null' or 'empty'.");
String hostAndPort = String.format("%s:%s", host, port);
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) client -> client.clientKill(hostAndPort));
@@ -488,9 +503,11 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
*/
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, @Nullable MigrateOption option,
final long timeout) {
long timeout) {
final int timeoutToUse = timeout <= Integer.MAX_VALUE ? (int) timeout : Integer.MAX_VALUE;
Assert.notNull(key, "Key must not be null!");
Assert.notNull(target, "Target node must not be null!");
int timeoutToUse = timeout <= Integer.MAX_VALUE ? (int) timeout : Integer.MAX_VALUE;
RedisClusterNode node = connection.getTopologyProvider().getTopology().lookup(target.getHost(), target.getPort());

View File

@@ -34,6 +34,7 @@ import org.springframework.data.redis.core.ScanCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
@@ -55,6 +56,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sAdd(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
return connection.getCluster().sadd(key, values);
} catch (Exception ex) {
@@ -69,6 +74,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sRem(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
return connection.getCluster().srem(key, values);
} catch (Exception ex) {
@@ -82,6 +91,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
*/
@Override
public byte[] sPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().spop(key);
} catch (Exception ex) {
@@ -96,6 +108,8 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public List<byte[]> sPop(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
try {
return new ArrayList<>(connection.getCluster().spop(key, count));
} catch (Exception ex) {
@@ -110,6 +124,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(value, "Value must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, destKey)) {
try {
return JedisConverters.toBoolean(connection.getCluster().smove(srcKey, destKey, value));
@@ -133,6 +151,8 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sCard(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().scard(key);
} catch (Exception ex) {
@@ -147,6 +167,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Boolean sIsMember(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().sismember(key, value);
} catch (Exception ex) {
@@ -161,6 +184,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Set<byte[]> sInter(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().sinter(keys);
@@ -204,6 +230,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sInterStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -228,6 +258,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Set<byte[]> sUnion(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().sunion(keys);
@@ -261,6 +294,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sUnionStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -285,6 +322,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Set<byte[]> sDiff(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().sdiff(keys);
@@ -321,6 +361,10 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Long sDiffStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -346,6 +390,8 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public Set<byte[]> sMembers(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().smembers(key);
} catch (Exception ex) {
@@ -360,6 +406,8 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public byte[] sRandMember(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().srandmember(key);
} catch (Exception ex) {
@@ -374,6 +422,8 @@ class JedisClusterSetCommands implements RedisSetCommands {
@Override
public List<byte[]> sRandMember(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
if (count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count cannot exceed Integer.MAX_VALUE!");
}
@@ -390,7 +440,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
* @see org.springframework.data.redis.connection.RedisSetCommands#sScan(byte[], org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<byte[]> sScan(final byte[] key, ScanOptions options) {
public Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new ScanCursor<byte[]>(options) {

View File

@@ -51,6 +51,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public byte[] get(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().get(key);
} catch (Exception ex) {
@@ -65,6 +67,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public byte[] getSet(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().getSet(key, value);
} catch (Exception ex) {
@@ -79,6 +84,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public List<byte[]> mGet(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
@@ -98,6 +104,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public void 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);
} catch (Exception ex) {
@@ -112,6 +121,11 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public void 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!");
Assert.notNull(expiration, "Expiration must not be null!");
Assert.notNull(option, "Option must not be null!");
if (expiration == null || expiration.isPersistent()) {
if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
@@ -155,6 +169,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Boolean setNX(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().setnx(key, value));
} catch (Exception ex) {
@@ -169,6 +186,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public void setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
if (seconds > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Seconds have cannot exceed Integer.MAX_VALUE!");
}
@@ -185,11 +205,10 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
public void pSetEx(final byte[] key, final long milliseconds, final byte[] value) {
public void pSetEx(byte[] key, long milliseconds, byte[] value) {
if (milliseconds > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Milliseconds have cannot exceed Integer.MAX_VALUE!");
}
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
connection.getClusterCommandExecutor().executeCommandOnSingleNode(
(JedisClusterCommandCallback<String>) client -> client.psetex(key, milliseconds, value),
@@ -226,7 +245,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuple must not be null!");
Assert.notNull(tuples, "Tuples must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(tuples.keySet().toArray(new byte[tuples.keySet().size()][]))) {
try {
@@ -252,6 +271,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long incr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().incr(key);
} catch (Exception ex) {
@@ -266,6 +287,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long incrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().incrBy(key, value);
} catch (Exception ex) {
@@ -280,6 +303,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Double incrBy(byte[] key, double value) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().incrByFloat(key, value);
} catch (Exception ex) {
@@ -294,6 +319,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long decr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().decr(key);
} catch (Exception ex) {
@@ -308,6 +335,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long decrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().decrBy(key, value);
} catch (Exception ex) {
@@ -322,6 +351,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long append(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().append(key, value);
} catch (Exception ex) {
@@ -334,10 +366,12 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#getRange(byte[], long, long)
*/
@Override
public byte[] getRange(byte[] key, long begin, long end) {
public byte[] getRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().getrange(key, begin, end);
return connection.getCluster().getrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -350,6 +384,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public void setRange(byte[] key, byte[] value, long offset) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
connection.getCluster().setrange(key, offset, value);
} catch (Exception ex) {
@@ -364,6 +401,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Boolean getBit(byte[] key, long offset) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().getbit(key, offset);
} catch (Exception ex) {
@@ -378,6 +417,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Boolean setBit(byte[] key, long offset, boolean value) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().setbit(key, offset, value);
} catch (Exception ex) {
@@ -392,6 +433,8 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long bitCount(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().bitcount(key);
} catch (Exception ex) {
@@ -404,10 +447,12 @@ class JedisClusterStringCommands implements RedisStringCommands {
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[], long, long)
*/
@Override
public Long bitCount(byte[] key, long begin, long end) {
public Long bitCount(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().bitcount(key, begin, end);
return connection.getCluster().bitcount(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -420,6 +465,9 @@ class JedisClusterStringCommands implements RedisStringCommands {
@Override
public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
Assert.notNull(op, "BitOperation must not be null!");
Assert.notNull(destination, "Destination key must not be null!");
byte[][] allKeys = ByteUtils.mergeArrays(destination, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -439,6 +487,7 @@ class JedisClusterStringCommands implements RedisStringCommands {
*/
@Override
public Long strLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().strlen(key);

View File

@@ -52,6 +52,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Boolean zAdd(byte[] key, double score, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return JedisConverters.toBoolean(connection.getCluster().zadd(key, score, value));
} catch (Exception ex) {
@@ -66,6 +69,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zAdd(byte[] key, Set<Tuple> tuples) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(tuples, "Tuples must not be null!");
try {
return connection.getCluster().zadd(key, JedisConverters.toTupleMap(tuples));
} catch (Exception ex) {
@@ -80,6 +86,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zRem(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
return connection.getCluster().zrem(key, values);
} catch (Exception ex) {
@@ -94,6 +104,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
*/
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().zincrby(key, increment, value);
} catch (Exception ex) {
@@ -108,6 +122,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zRank(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().zrank(key, value);
} catch (Exception ex) {
@@ -122,6 +139,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zRevRank(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().zrevrank(key, value);
} catch (Exception ex) {
@@ -134,10 +154,12 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRange(byte[], long, long)
*/
@Override
public Set<byte[]> zRange(byte[] key, long begin, long end) {
public Set<byte[]> zRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zrange(key, begin, end);
return connection.getCluster().zrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -150,6 +172,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
@@ -173,7 +196,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
@@ -194,6 +219,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCOREWITHSCORES.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
@@ -217,6 +243,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zCount(byte[] key, Range range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZCOUNT.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
@@ -236,6 +263,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREMRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
@@ -256,6 +284,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
@@ -278,6 +307,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZRANGEBYLEX.");
Assert.notNull(limit, "Limit must not be null!");
@@ -299,10 +329,12 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeWithScores(byte[], long, long)
*/
@Override
public Set<Tuple> zRangeWithScores(byte[] key, long begin, long end) {
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toTupleSet(connection.getCluster().zrangeWithScores(key, begin, end));
return JedisConverters.toTupleSet(connection.getCluster().zrangeWithScores(key, start, end));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -315,6 +347,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zrangeByScore(key, min, max);
} catch (Exception ex) {
@@ -329,6 +363,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toTupleSet(connection.getCluster().zrangeByScoreWithScores(key, min, max));
} catch (Exception ex) {
@@ -343,6 +379,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, double min, double max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
if (offset > Integer.MAX_VALUE || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count/Offset cannot exceed Integer.MAX_VALUE!");
}
@@ -362,6 +400,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
if (offset > Integer.MAX_VALUE || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count/Offset cannot exceed Integer.MAX_VALUE!");
}
@@ -379,10 +419,12 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRange(byte[], long, long)
*/
@Override
public Set<byte[]> zRevRange(byte[] key, long begin, long end) {
public Set<byte[]> zRevRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zrevrange(key, begin, end);
return connection.getCluster().zrevrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -393,10 +435,12 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeWithScores(byte[], long, long)
*/
@Override
public Set<Tuple> zRevRangeWithScores(byte[] key, long begin, long end) {
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toTupleSet(connection.getCluster().zrevrangeWithScores(key, begin, end));
return JedisConverters.toTupleSet(connection.getCluster().zrevrangeWithScores(key, start, end));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -409,6 +453,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zrevrangeByScore(key, max, min);
} catch (Exception ex) {
@@ -423,6 +469,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return JedisConverters.toTupleSet(connection.getCluster().zrevrangeByScoreWithScores(key, max, min));
} catch (Exception ex) {
@@ -437,6 +485,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
if (offset > Integer.MAX_VALUE || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count/Offset cannot exceed Integer.MAX_VALUE!");
}
@@ -456,6 +506,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
if (offset > Integer.MAX_VALUE || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count/Offset cannot exceed Integer.MAX_VALUE!");
}
@@ -475,6 +527,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zCount(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zcount(key, min, max);
} catch (Exception ex) {
@@ -489,6 +543,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zCard(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zcard(key);
} catch (Exception ex) {
@@ -503,6 +559,9 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Double zScore(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
return connection.getCluster().zscore(key, value);
} catch (Exception ex) {
@@ -515,10 +574,12 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRemRange(byte[], long, long)
*/
@Override
public Long zRemRange(byte[] key, long begin, long end) {
public Long zRemRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zremrangeByRank(key, begin, end);
return connection.getCluster().zremrangeByRank(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -531,6 +592,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zRemRangeByScore(byte[] key, double min, double max) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zremrangeByScore(key, min, max);
} catch (Exception ex) {
@@ -545,6 +608,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zUnionStore(byte[] destKey, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -566,6 +633,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -589,6 +660,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zInterStore(byte[] destKey, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -610,6 +685,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -631,7 +710,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<Tuple> zScan(final byte[] key, final ScanOptions options) {
public Cursor<Tuple> zScan(byte[] key, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new ScanCursor<Tuple>(options) {
@Override
@@ -654,6 +736,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
Assert.notNull(key, "Key must not be null!");
try {
return connection.getCluster().zrangeByScore(key, JedisConverters.toBytes(min), JedisConverters.toBytes(max));
} catch (Exception ex) {
@@ -668,6 +752,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
if (offset > Integer.MAX_VALUE || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count/Offset cannot exceed Integer.MAX_VALUE!");
}

View File

@@ -102,7 +102,7 @@ public class JedisConnection extends AbstractRedisConnection {
private final Jedis jedis;
private final Client client;
private @Nullable Transaction transaction;
private final Pool<Jedis> pool;
private final @Nullable Pool<Jedis> pool;
/**
* flag indicating whether the connection needs to be dropped or not
*/
@@ -172,7 +172,7 @@ public class JedisConnection extends AbstractRedisConnection {
* @param clientName the client name, can be {@literal null}.
* @since 1.8
*/
protected JedisConnection(Jedis jedis, Pool<Jedis> pool, int dbIndex, String clientName) {
protected JedisConnection(Jedis jedis, @Nullable Pool<Jedis> pool, int dbIndex, String clientName) {
// extract underlying connection for batch operations
client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis);
@@ -469,7 +469,7 @@ public class JedisConnection extends AbstractRedisConnection {
private List<Object> convertPipelineResults() {
List<Object> results = new ArrayList<>();
pipeline.sync();
getRequiredPipeline().sync();
Exception cause = null;
for (FutureResult<Response<?>> result : pipelinedResults) {
try {
@@ -516,11 +516,11 @@ public class JedisConnection extends AbstractRedisConnection {
public byte[] echo(byte[] message) {
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.echo(message)));
pipeline(new JedisResult(getRequiredPipeline().echo(message)));
return null;
}
if (isQueueing()) {
transaction(new JedisResult(transaction.echo(message)));
transaction(new JedisResult(getRequiredTransaction().echo(message)));
return null;
}
return jedis.echo(message);
@@ -537,11 +537,11 @@ public class JedisConnection extends AbstractRedisConnection {
public String ping() {
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.ping()));
pipeline(new JedisResult(getRequiredPipeline().ping()));
return null;
}
if (isQueueing()) {
transaction(new JedisResult(transaction.ping()));
transaction(new JedisResult(getRequiredTransaction().ping()));
return null;
}
return jedis.ping();
@@ -558,10 +558,10 @@ public class JedisConnection extends AbstractRedisConnection {
public void discard() {
try {
if (isPipelined()) {
pipeline(new JedisStatusResult(pipeline.discard()));
pipeline(new JedisStatusResult(getRequiredPipeline().discard()));
return;
}
transaction.discard();
getRequiredTransaction().discard();
} catch (Exception ex) {
throw convertJedisAccessException(ex);
} finally {
@@ -578,7 +578,7 @@ public class JedisConnection extends AbstractRedisConnection {
public List<Object> exec() {
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.exec(),
pipeline(new JedisResult(getRequiredPipeline().exec(),
new TransactionResultConverter<>(new LinkedList<>(txResults), JedisConverters.exceptionConverter())));
return null;
}
@@ -603,11 +603,33 @@ public class JedisConnection extends AbstractRedisConnection {
return pipeline;
}
public Pipeline getRequiredPipeline() {
Pipeline pipeline = getPipeline();
if (pipeline == null) {
throw new IllegalStateException("Connection has no active pipeline");
}
return pipeline;
}
@Nullable
public Transaction getTransaction() {
return transaction;
}
public Transaction getRequiredTransaction() {
Transaction transaction = getTransaction();
if (transaction == null) {
throw new IllegalStateException("Connection has no active transaction");
}
return transaction;
}
public Jedis getJedis() {
return jedis;
}
@@ -635,7 +657,7 @@ public class JedisConnection extends AbstractRedisConnection {
}
try {
if (isPipelined()) {
pipeline.multi();
getRequiredPipeline().multi();
return;
}
this.transaction = jedis.multi();
@@ -652,11 +674,11 @@ public class JedisConnection extends AbstractRedisConnection {
public void select(int dbIndex) {
try {
if (isPipelined()) {
pipeline(new JedisStatusResult(pipeline.select(dbIndex)));
pipeline(new JedisStatusResult(getRequiredPipeline().select(dbIndex)));
return;
}
if (isQueueing()) {
transaction(new JedisStatusResult(transaction.select(dbIndex)));
transaction(new JedisStatusResult(getRequiredTransaction().select(dbIndex)));
return;
}
jedis.select(dbIndex);
@@ -690,7 +712,7 @@ public class JedisConnection extends AbstractRedisConnection {
try {
for (byte[] key : keys) {
if (isPipelined()) {
pipeline(new JedisStatusResult(pipeline.watch(key)));
pipeline(new JedisStatusResult(getRequiredPipeline().watch(key)));
} else {
jedis.watch(key);
}
@@ -712,11 +734,11 @@ public class JedisConnection extends AbstractRedisConnection {
public Long publish(byte[] channel, byte[] message) {
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.publish(channel, message)));
pipeline(new JedisResult(getRequiredPipeline().publish(channel, message)));
return null;
}
if (isQueueing()) {
transaction(new JedisResult(transaction.publish(channel, message)));
transaction(new JedisResult(getRequiredTransaction().publish(channel, message)));
return null;
}
return jedis.publish(channel, message);
@@ -817,10 +839,6 @@ public class JedisConnection extends AbstractRedisConnection {
@Override
protected boolean isActive(RedisNode node) {
if (node == null) {
return false;
}
Jedis temp = null;
try {
temp = getJedis(node);

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.redis.connection.jedis;
import org.springframework.lang.Nullable;
import redis.clients.jedis.Client;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
@@ -61,6 +60,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterTopologyProvider;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -680,6 +680,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
*
* @return the poolConfig
*/
@Nullable
public GenericObjectPoolConfig getPoolConfig() {
return clientConfiguration.getPoolConfig().orElse(null);
}
@@ -736,6 +737,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @return the client name.
* @since 1.8
*/
@Nullable
public String getClientName() {
return clientConfiguration.getClientName().orElse(null);
}
@@ -765,6 +767,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @return the {@link RedisStandaloneConfiguration}.
* @since 2.0
*/
@Nullable
public RedisStandaloneConfiguration getStandaloneConfiguration() {
return standaloneConfig;
}
@@ -773,6 +776,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @return the {@link RedisStandaloneConfiguration}, may be {@literal null}.
* @since 2.0
*/
@Nullable
public RedisSentinelConfiguration getSentinelConfiguration() {
return sentinelConfig;
}
@@ -781,6 +785,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
* @return the {@link RedisClusterConfiguration}, may be {@literal null}.
* @since 2.0
*/
@Nullable
public RedisClusterConfiguration getClusterConfiguration() {
return clusterConfig;
}

View File

@@ -67,6 +67,7 @@ import org.springframework.data.redis.connection.convert.StringToRedisClientInfo
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -354,7 +355,9 @@ abstract public class JedisConverters extends Converters {
return result;
}
public static SortingParams toSortingParams(SortParameters params) {
@Nullable
public static SortingParams toSortingParams(@Nullable SortParameters params) {
SortingParams jedisParams = null;
if (params != null) {
jedisParams = new SortingParams();
@@ -406,7 +409,7 @@ abstract public class JedisConverters extends Converters {
* @return
* @since 1.6
*/
public static byte[] boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) {
public static byte[] boundaryToBytesForZRange(@Nullable Boundary boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return defaultValue;
@@ -422,7 +425,7 @@ abstract public class JedisConverters extends Converters {
* @return
* @since 1.6
*/
public static byte[] boundaryToBytesForZRangeByLex(Boundary boundary, byte[] defaultValue) {
public static byte[] boundaryToBytesForZRangeByLex(@Nullable Boundary boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return defaultValue;

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import redis.clients.jedis.GeoCoordinate;
import redis.clients.jedis.GeoUnit;
@@ -38,13 +40,10 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisGeoCommands implements RedisGeoCommands {
private final JedisConnection connection;
JedisGeoCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -59,12 +58,14 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geoadd(key, point.getX(), point.getY(), member)));
pipeline(connection
.newJedisResult(connection.getRequiredPipeline().geoadd(key, point.getX(), point.getY(), member)));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().geoadd(key, point.getX(), point.getY(), member)));
connection
.newJedisResult(connection.getRequiredTransaction().geoadd(key, point.getX(), point.getY(), member)));
return null;
}
@@ -92,11 +93,11 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geoadd(key, redisGeoCoordinateMap)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geoadd(key, redisGeoCoordinateMap)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().geoadd(key, redisGeoCoordinateMap)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().geoadd(key, redisGeoCoordinateMap)));
return null;
}
@@ -124,11 +125,11 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geoadd(key, redisGeoCoordinateMap)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geoadd(key, redisGeoCoordinateMap)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().geoadd(key, redisGeoCoordinateMap)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().geoadd(key, redisGeoCoordinateMap)));
return null;
}
@@ -153,12 +154,14 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geodist(key, member1, member2), distanceConverter));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geodist(key, member1, member2),
distanceConverter));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().geodist(key, member1, member2), distanceConverter));
connection.newJedisResult(connection.getRequiredTransaction().geodist(key, member1, member2),
distanceConverter));
return null;
}
@@ -185,12 +188,13 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geodist(key, member1, member2, geoUnit),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geodist(key, member1, member2, geoUnit),
distanceConverter));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().geodist(key, member1, member2, geoUnit),
transaction(connection.newJedisResult(
connection.getRequiredTransaction().geodist(key, member1, member2, geoUnit),
distanceConverter));
return null;
}
@@ -214,12 +218,12 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geohash(key, members),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geohash(key, members),
JedisConverters.bytesListToStringListConverter()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().geohash(key, members),
transaction(connection.newJedisResult(connection.getRequiredTransaction().geohash(key, members),
JedisConverters.bytesListToStringListConverter()));
return null;
}
@@ -244,11 +248,11 @@ class JedisGeoCommands implements RedisGeoCommands {
ListConverter<GeoCoordinate, Point> converter = JedisConverters.geoCoordinateToPointConverter();
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().geopos(key, members), converter));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().geopos(key, members), converter));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().geopos(key, members), converter));
transaction(connection.newJedisResult(connection.getRequiredTransaction().geopos(key, members), converter));
return null;
}
return converter.convert(connection.getJedis().geopos(key, members));
@@ -273,7 +277,7 @@ class JedisGeoCommands implements RedisGeoCommands {
if (isPipelined()) {
pipeline(
connection.newJedisResult(
connection.getPipeline().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
connection.getRequiredPipeline().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
converter));
return null;
@@ -281,7 +285,7 @@ class JedisGeoCommands implements RedisGeoCommands {
if (isQueueing()) {
transaction(
connection.newJedisResult(
connection.getTransaction().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
connection.getRequiredTransaction().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())),
converter));
return null;
@@ -312,13 +316,14 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().georadius(key, within.getCenter().getX(),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().georadius(key, within.getCenter().getX(),
within.getCenter().getY(), within.getRadius().getValue(),
JedisConverters.toGeoUnit(within.getRadius().getMetric()), geoRadiusParam), converter));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().georadius(key, within.getCenter().getX(),
transaction(connection.newJedisResult(connection.getRequiredTransaction().georadius(key,
within.getCenter().getX(),
within.getCenter().getY(), within.getRadius().getValue(),
JedisConverters.toGeoUnit(within.getRadius().getMetric()), geoRadiusParam), converter));
return null;
@@ -350,12 +355,12 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(
connection.getPipeline().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
connection.getRequiredPipeline().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(
connection.getTransaction().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
connection.getRequiredTransaction().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
return null;
}
@@ -386,13 +391,14 @@ class JedisGeoCommands implements RedisGeoCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(
connection.getPipeline().georadiusByMember(key, member, radius.getValue(), geoUnit, geoRadiusParam),
connection.getRequiredPipeline().georadiusByMember(key, member, radius.getValue(), geoUnit, geoRadiusParam),
converter));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(
connection.getTransaction().georadiusByMember(key, member, radius.getValue(), geoUnit, geoRadiusParam),
connection.getRequiredTransaction().georadiusByMember(key, member, radius.getValue(), geoUnit,
geoRadiusParam),
converter));
return null;
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
@@ -29,19 +31,17 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.KeyBoundCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisHashCommands implements RedisHashCommands {
private final JedisConnection connection;
JedisHashCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -50,14 +50,18 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Boolean hSet(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hset(key, field, value),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hset(key, field, value),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hset(key, field, value),
transaction(connection.newJedisResult(connection.getRequiredTransaction().hset(key, field, value),
JedisConverters.longToBoolean()));
return null;
}
@@ -74,14 +78,18 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hsetnx(key, field, value),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hsetnx(key, field, value),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hsetnx(key, field, value),
transaction(connection.newJedisResult(connection.getRequiredTransaction().hsetnx(key, field, value),
JedisConverters.longToBoolean()));
return null;
}
@@ -98,13 +106,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Long hDel(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hdel(key, fields)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hdel(key, fields)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hdel(key, fields)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hdel(key, fields)));
return null;
}
return connection.getJedis().hdel(key, fields);
@@ -120,13 +131,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Boolean hExists(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hexists(key, field)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hexists(key, field)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hexists(key, field)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hexists(key, field)));
return null;
}
return connection.getJedis().hexists(key, field);
@@ -142,13 +156,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public byte[] hGet(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hget(key, field)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hget(key, field)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hget(key, field)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hget(key, field)));
return null;
}
return connection.getJedis().hget(key, field);
@@ -164,13 +181,15 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Map<byte[], byte[]> hGetAll(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hgetAll(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hgetAll(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hgetAll(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hgetAll(key)));
return null;
}
return connection.getJedis().hgetAll(key);
@@ -186,13 +205,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Long hIncrBy(byte[] key, byte[] field, long delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hincrBy(key, field, delta)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hincrBy(key, field, delta)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hincrBy(key, field, delta)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hincrBy(key, field, delta)));
return null;
}
return connection.getJedis().hincrBy(key, field, delta);
@@ -208,13 +230,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Double hIncrBy(byte[] key, byte[] field, double delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hincrByFloat(key, field, delta)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hincrByFloat(key, field, delta)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hincrByFloat(key, field, delta)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hincrByFloat(key, field, delta)));
return null;
}
return connection.getJedis().hincrByFloat(key, field, delta);
@@ -230,13 +255,15 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Set<byte[]> hKeys(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hkeys(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hkeys(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hkeys(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hkeys(key)));
return null;
}
return connection.getJedis().hkeys(key);
@@ -252,13 +279,15 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public Long hLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hlen(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hlen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hlen(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hlen(key)));
return null;
}
return connection.getJedis().hlen(key);
@@ -274,13 +303,16 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public List<byte[]> hMGet(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hmget(key, fields)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hmget(key, fields)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hmget(key, fields)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hmget(key, fields)));
return null;
}
return connection.getJedis().hmget(key, fields);
@@ -294,18 +326,21 @@ class JedisHashCommands implements RedisHashCommands {
* @see org.springframework.data.redis.connection.RedisHashCommands#hMSet(byte[], java.util.Map)
*/
@Override
public void hMSet(byte[] key, Map<byte[], byte[]> tuple) {
public void hMSet(byte[] key, Map<byte[], byte[]> hashes) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(hashes, "Hashes must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().hmset(key, tuple)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().hmset(key, hashes)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().hmset(key, tuple)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().hmset(key, hashes)));
return;
}
connection.getJedis().hmset(key, tuple);
connection.getJedis().hmset(key, hashes);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -318,13 +353,15 @@ class JedisHashCommands implements RedisHashCommands {
@Override
public List<byte[]> hVals(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().hvals(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().hvals(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().hvals(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().hvals(key)));
return null;
}
return connection.getJedis().hvals(key);
@@ -351,6 +388,8 @@ class JedisHashCommands implements RedisHashCommands {
*/
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, long cursorId, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new KeyBoundCursor<Entry<byte[], byte[]>>(key, cursorId, options) {
@Override
@@ -367,6 +406,7 @@ class JedisHashCommands implements RedisHashCommands {
return new ScanIteration<>(Long.valueOf(result.getStringCursor()), result.getResult());
}
@Override
protected void doClose() {
JedisHashCommands.this.connection.close();
};

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.RedisHyperLogLogCommands;
import org.springframework.data.redis.connection.jedis.JedisConnection.JedisResult;
import org.springframework.util.Assert;
@@ -24,13 +27,10 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisHyperLogLogCommands implements RedisHyperLogLogCommands {
private final JedisConnection connection;
JedisHyperLogLogCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -44,11 +44,11 @@ class JedisHyperLogLogCommands implements RedisHyperLogLogCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().pfadd(key, values)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pfadd(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pfadd(key, values)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().pfadd(key, values)));
return null;
}
return connection.getJedis().pfadd(key, values);
@@ -65,15 +65,15 @@ class JedisHyperLogLogCommands implements RedisHyperLogLogCommands {
public Long pfCount(byte[]... keys) {
Assert.notEmpty(keys, "PFCOUNT requires at least one non 'null' key.");
Assert.noNullElements(keys, "Keys for PFOUNT must not contain 'null'.");
Assert.noNullElements(keys, "Keys for PFCOUNT must not contain 'null'.");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().pfcount(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pfcount(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pfcount(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().pfcount(keys)));
return null;
}
return connection.getJedis().pfcount(keys);
@@ -89,13 +89,17 @@ class JedisHyperLogLogCommands implements RedisHyperLogLogCommands {
@Override
public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
Assert.notNull(destinationKey, "Destination key must not be null");
Assert.notNull(sourceKeys, "Source keys must not be null");
Assert.noNullElements(sourceKeys, "Keys for PFMERGE must not contain 'null'.");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().pfmerge(destinationKey, sourceKeys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pfmerge(destinationKey, sourceKeys)));
return;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pfmerge(destinationKey, sourceKeys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().pfmerge(destinationKey, sourceKeys)));
return;
}
connection.getJedis().pfmerge(destinationKey, sourceKeys);

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.SortingParams;
@@ -31,6 +33,7 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -38,13 +41,10 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisKeyCommands implements RedisKeyCommands {
private final JedisConnection connection;
JedisKeyCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -53,13 +53,15 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public Boolean exists(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().exists(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().exists(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().exists(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().exists(key)));
return null;
}
return connection.getJedis().exists(key);
@@ -75,13 +77,16 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public Long del(byte[]... keys) {
Assert.noNullElements(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().del(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().del(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().del(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().del(keys)));
return null;
}
return connection.getJedis().del(keys);
@@ -97,14 +102,17 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public DataType type(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().type(key), JedisConverters.stringToDataType()));
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().type(key), JedisConverters.stringToDataType()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().type(key), JedisConverters.stringToDataType()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().type(key),
JedisConverters.stringToDataType()));
return null;
}
return JedisConverters.toDataType(connection.getJedis().type(key));
@@ -120,13 +128,15 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public Set<byte[]> keys(byte[] pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().keys(pattern)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().keys(pattern)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().keys(pattern)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().keys(pattern)));
return null;
}
return connection.getJedis().keys(pattern);
@@ -139,6 +149,7 @@ class JedisKeyCommands implements RedisKeyCommands {
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#scan(org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<byte[]> scan(ScanOptions options) {
return scan(0, options != null ? options : ScanOptions.NONE);
}
@@ -182,11 +193,11 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().randomKeyBinary()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().randomKeyBinary()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().randomKeyBinary()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().randomKeyBinary()));
return null;
}
return connection.getJedis().randomBinaryKey();
@@ -200,18 +211,21 @@ class JedisKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
*/
@Override
public void rename(byte[] oldName, byte[] newName) {
public void rename(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().rename(oldName, newName)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().rename(sourceKey, targetKey)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().rename(oldName, newName)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().rename(sourceKey, targetKey)));
return;
}
connection.getJedis().rename(oldName, newName);
connection.getJedis().rename(sourceKey, targetKey);
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
@@ -222,20 +236,23 @@ class JedisKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(byte[] oldName, byte[] newName) {
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().renamenx(oldName, newName),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().renamenx(sourceKey, targetKey),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().renamenx(oldName, newName),
transaction(connection.newJedisResult(connection.getRequiredTransaction().renamenx(sourceKey, targetKey),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().renamenx(oldName, newName));
return JedisConverters.toBoolean(connection.getJedis().renamenx(sourceKey, targetKey));
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
@@ -256,12 +273,12 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().expire(key, (int) seconds),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().expire(key, (int) seconds),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().expire(key, (int) seconds),
transaction(connection.newJedisResult(connection.getRequiredTransaction().expire(key, (int) seconds),
JedisConverters.longToBoolean()));
return null;
}
@@ -271,32 +288,6 @@ class JedisKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#expireAt(byte[], long)
*/
@Override
public Boolean expireAt(byte[] key, long unixTime) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().expireAt(key, unixTime),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().expireAt(key, unixTime),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().expireAt(key, unixTime));
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pExpire(byte[], long)
@@ -308,12 +299,12 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getPipeline().pexpire(key, millis), JedisConverters.longToBoolean()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pexpire(key, millis),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pexpire(key, millis),
transaction(connection.newJedisResult(connection.getRequiredTransaction().pexpire(key, millis),
JedisConverters.longToBoolean()));
return null;
}
@@ -323,6 +314,32 @@ class JedisKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#expireAt(byte[], long)
*/
@Override
public Boolean expireAt(byte[] key, long unixTime) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().expireAt(key, unixTime),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().expireAt(key, unixTime),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().expireAt(key, unixTime));
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pExpireAt(byte[], long)
@@ -334,12 +351,12 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().pexpireAt(key, unixTimeInMillis),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pexpireAt(key, unixTimeInMillis),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pexpireAt(key, unixTimeInMillis),
transaction(connection.newJedisResult(connection.getRequiredTransaction().pexpireAt(key, unixTimeInMillis),
JedisConverters.longToBoolean()));
return null;
}
@@ -356,14 +373,17 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public Boolean persist(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().persist(key), JedisConverters.longToBoolean()));
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().persist(key), JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().persist(key), JedisConverters.longToBoolean()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().persist(key),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().persist(key));
@@ -379,15 +399,17 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public Boolean move(byte[] key, int dbIndex) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getPipeline().move(key, dbIndex), JedisConverters.longToBoolean()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().move(key, dbIndex),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().move(key, dbIndex), JedisConverters.longToBoolean()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().move(key, dbIndex),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().move(key, dbIndex));
@@ -407,11 +429,11 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().ttl(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().ttl(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().ttl(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().ttl(key)));
return null;
}
@@ -432,12 +454,13 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().ttl(key),
Converters.secondsToTimeUnit(timeUnit)));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().ttl(key),
Converters.secondsToTimeUnit(timeUnit)));
return null;
}
@@ -458,11 +481,11 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().pttl(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pttl(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pttl(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().pttl(key)));
return null;
}
@@ -483,12 +506,12 @@ class JedisKeyCommands implements RedisKeyCommands {
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getPipeline().pttl(key), Converters.millisecondsToTimeUnit(timeUnit)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().pttl(key),
Converters.millisecondsToTimeUnit(timeUnit)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().pttl(key),
transaction(connection.newJedisResult(connection.getRequiredTransaction().pttl(key),
Converters.millisecondsToTimeUnit(timeUnit)));
return null;
}
@@ -506,23 +529,25 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public List<byte[]> sort(byte[] key, SortParameters params) {
Assert.notNull(key, "Key must not be null!");
SortingParams sortParams = JedisConverters.toSortingParams(params);
try {
if (isPipelined()) {
if (sortParams != null) {
pipeline(connection.newJedisResult(connection.getPipeline().sort(key, sortParams)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sort(key, sortParams)));
} else {
pipeline(connection.newJedisResult(connection.getPipeline().sort(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sort(key)));
}
return null;
}
if (isQueueing()) {
if (sortParams != null) {
transaction(connection.newJedisResult(connection.getTransaction().sort(key, sortParams)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sort(key, sortParams)));
} else {
transaction(connection.newJedisResult(connection.getTransaction().sort(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sort(key)));
}
return null;
@@ -538,25 +563,27 @@ class JedisKeyCommands implements RedisKeyCommands {
* @see org.springframework.data.redis.connection.RedisKeyCommands#sort(byte[], org.springframework.data.redis.connection.SortParameters, byte[])
*/
@Override
public Long sort(byte[] key, SortParameters params, byte[] storeKey) {
public Long sort(byte[] key, @Nullable SortParameters params, byte[] storeKey) {
Assert.notNull(key, "Key must not be null!");
SortingParams sortParams = JedisConverters.toSortingParams(params);
try {
if (isPipelined()) {
if (sortParams != null) {
pipeline(connection.newJedisResult(connection.getPipeline().sort(key, sortParams, storeKey)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sort(key, sortParams, storeKey)));
} else {
pipeline(connection.newJedisResult(connection.getPipeline().sort(key, storeKey)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sort(key, storeKey)));
}
return null;
}
if (isQueueing()) {
if (sortParams != null) {
transaction(connection.newJedisResult(connection.getTransaction().sort(key, sortParams, storeKey)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sort(key, sortParams, storeKey)));
} else {
transaction(connection.newJedisResult(connection.getTransaction().sort(key, storeKey)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sort(key, storeKey)));
}
return null;
@@ -575,13 +602,15 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public byte[] dump(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().dump(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().dump(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().dump(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().dump(key)));
return null;
}
return connection.getJedis().dump(key);
@@ -597,17 +626,21 @@ class JedisKeyCommands implements RedisKeyCommands {
@Override
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(serializedValue, "Serialized value must not be null!");
if (ttlInMillis > Integer.MAX_VALUE) {
throw new IllegalArgumentException("TtlInMillis must be less than Integer.MAX_VALUE for restore in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().restore(key, (int) ttlInMillis, serializedValue)));
pipeline(connection
.newStatusResult(connection.getRequiredPipeline().restore(key, (int) ttlInMillis, serializedValue)));
return;
}
if (isQueueing()) {
transaction(
connection.newStatusResult(connection.getTransaction().restore(key, (int) ttlInMillis, serializedValue)));
transaction(connection
.newStatusResult(connection.getRequiredTransaction().restore(key, (int) ttlInMillis, serializedValue)));
return;
}
connection.getJedis().restore(key, (int) ttlInMillis, serializedValue);

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import redis.clients.jedis.Protocol;
import java.util.ArrayList;
@@ -22,19 +24,17 @@ import java.util.List;
import org.springframework.data.redis.connection.RedisListCommands;
import org.springframework.data.redis.connection.jedis.JedisConnection.JedisResult;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisListCommands implements RedisListCommands {
private final JedisConnection connection;
JedisListCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -43,13 +43,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long rPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().rpush(key, values)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().rpush(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().rpush(key, values)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().rpush(key, values)));
return null;
}
return connection.getJedis().rpush(key, values);
@@ -65,13 +67,17 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long lPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lpush(key, values)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lpush(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lpush(key, values)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lpush(key, values)));
return null;
}
return connection.getJedis().lpush(key, values);
@@ -86,13 +92,17 @@ class JedisListCommands implements RedisListCommands {
*/
@Override
public Long rPushX(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.newJedisResult(connection.getPipeline().rpushx(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().rpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().rpushx(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().rpushx(key, value)));
return null;
}
return connection.getJedis().rpushx(key, value);
@@ -108,13 +118,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long lPushX(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.newJedisResult(connection.getPipeline().lpushx(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lpushx(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lpushx(key, value)));
return null;
}
return connection.getJedis().lpushx(key, value);
@@ -130,13 +143,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long lLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().llen(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().llen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().llen(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().llen(key)));
return null;
}
return connection.getJedis().llen(key);
@@ -152,13 +167,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public List<byte[]> lRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lrange(key, start, end)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lrange(key, start, end)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lrange(key, start, end)));
return null;
}
return connection.getJedis().lrange(key, start, end);
@@ -174,13 +191,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public void lTrim(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().ltrim(key, start, end)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().ltrim(key, start, end)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().ltrim(key, start, end)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().ltrim(key, start, end)));
return;
}
connection.getJedis().ltrim(key, start, end);
@@ -196,13 +215,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public byte[] lIndex(byte[] key, long index) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lindex(key, index)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lindex(key, index)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lindex(key, index)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lindex(key, index)));
return null;
}
return connection.getJedis().lindex(key, index);
@@ -218,15 +239,17 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(
connection.getPipeline().linsert(key, JedisConverters.toListPosition(where), pivot, value)));
connection.getRequiredPipeline().linsert(key, JedisConverters.toListPosition(where), pivot, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(
connection.getTransaction().linsert(key, JedisConverters.toListPosition(where), pivot, value)));
connection.getRequiredTransaction().linsert(key, JedisConverters.toListPosition(where), pivot, value)));
return null;
}
return connection.getJedis().linsert(key, JedisConverters.toListPosition(where), pivot, value);
@@ -242,13 +265,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public void lSet(byte[] key, long index, 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.getPipeline().lset(key, index, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().lset(key, index, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().lset(key, index, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().lset(key, index, value)));
return;
}
connection.getJedis().lset(key, index, value);
@@ -264,13 +290,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public Long lRem(byte[] key, long count, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lrem(key, count, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lrem(key, count, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lrem(key, count, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lrem(key, count, value)));
return null;
}
return connection.getJedis().lrem(key, count, value);
@@ -286,13 +315,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public byte[] lPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lpop(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lpop(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lpop(key)));
return null;
}
return connection.getJedis().lpop(key);
@@ -308,13 +339,15 @@ class JedisListCommands implements RedisListCommands {
@Override
public byte[] rPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().rpop(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().rpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().rpop(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().rpop(key)));
return null;
}
return connection.getJedis().rpop(key);
@@ -331,13 +364,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public List<byte[]> bLPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().blpop(bXPopArgs(timeout, keys))));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().blpop(bXPopArgs(timeout, keys))));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().blpop(bXPopArgs(timeout, keys))));
transaction(connection.newJedisResult(connection.getRequiredTransaction().blpop(bXPopArgs(timeout, keys))));
return null;
}
return connection.getJedis().blpop(timeout, keys);
@@ -353,13 +389,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public List<byte[]> bRPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().brpop(bXPopArgs(timeout, keys))));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().brpop(bXPopArgs(timeout, keys))));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().brpop(bXPopArgs(timeout, keys))));
transaction(connection.newJedisResult(connection.getRequiredTransaction().brpop(bXPopArgs(timeout, keys))));
return null;
}
return connection.getJedis().brpop(timeout, keys);
@@ -375,13 +414,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().rpoplpush(srcKey, dstKey)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().rpoplpush(srcKey, dstKey)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().rpoplpush(srcKey, dstKey)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().rpoplpush(srcKey, dstKey)));
return null;
}
return connection.getJedis().rpoplpush(srcKey, dstKey);
@@ -397,13 +439,16 @@ class JedisListCommands implements RedisListCommands {
@Override
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().brpoplpush(srcKey, dstKey, timeout)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().brpoplpush(srcKey, dstKey, timeout)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().brpoplpush(srcKey, dstKey, timeout)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().brpoplpush(srcKey, dstKey, timeout)));
return null;
}
return connection.getJedis().brpoplpush(srcKey, dstKey, timeout);
@@ -414,8 +459,8 @@ class JedisListCommands implements RedisListCommands {
private byte[][] bXPopArgs(int timeout, byte[]... keys) {
final List<byte[]> args = new ArrayList<>();
for (final byte[] arg : keys) {
List<byte[]> args = new ArrayList<>();
for (byte[] arg : keys) {
args.add(arg);
}
args.add(Protocol.toByteArray(timeout));

View File

@@ -15,22 +15,23 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.data.redis.connection.RedisScriptingCommands;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.util.Assert;
/**
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisScriptingCommands implements RedisScriptingCommands {
private final JedisConnection connection;
JedisScriptingCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -38,12 +39,11 @@ class JedisScriptingCommands implements RedisScriptingCommands {
*/
@Override
public void scriptFlush() {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
connection.getJedis().scriptFlush();
} catch (Exception ex) {
@@ -57,12 +57,11 @@ class JedisScriptingCommands implements RedisScriptingCommands {
*/
@Override
public void scriptKill() {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
connection.getJedis().scriptKill();
} catch (Exception ex) {
@@ -76,12 +75,13 @@ class JedisScriptingCommands implements RedisScriptingCommands {
*/
@Override
public String scriptLoad(byte[] script) {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
Assert.notNull(script, "Script must not be null!");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
return JedisConverters.toString(connection.getJedis().scriptLoad(script));
} catch (Exception ex) {
@@ -95,12 +95,14 @@ class JedisScriptingCommands implements RedisScriptingCommands {
*/
@Override
public List<Boolean> scriptExists(String... scriptSha1) {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
Assert.notNull(scriptSha1, "Script digests must not be null!");
Assert.noNullElements(scriptSha1, "Script digests must not contain null elements!");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
return connection.getJedis().scriptExists(scriptSha1);
} catch (Exception ex) {
@@ -115,12 +117,13 @@ class JedisScriptingCommands implements RedisScriptingCommands {
@Override
@SuppressWarnings("unchecked")
public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
Assert.notNull(script, "Script must not be null!");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
return (T) new JedisScriptReturnConverter(returnType)
.convert(connection.getJedis().eval(script, JedisConverters.toBytes(numKeys), keysAndArgs));
@@ -146,12 +149,12 @@ class JedisScriptingCommands implements RedisScriptingCommands {
@SuppressWarnings("unchecked")
public <T> T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
if (isQueueing()) {
throw new UnsupportedOperationException();
}
if (isPipelined()) {
Assert.notNull(scriptSha1, "Script digest must not be null!");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException();
}
try {
return (T) new JedisScriptReturnConverter(returnType)
.convert(connection.getJedis().evalsha(scriptSha1, numKeys, keysAndArgs));

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.Jedis;
import java.io.IOException;
import java.util.List;
@@ -25,8 +27,6 @@ import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.util.Assert;
import redis.clients.jedis.Jedis;
/**
* @author Christoph Strobl
* @since 1.4
@@ -126,8 +126,8 @@ public class JedisSentinelConnection implements RedisSentinelConnection {
Assert.hasText(server.getHost(), "Host must not be 'null' for server to monitor.");
Assert.notNull(server.getPort(), "Port must not be 'null' for server to monitor.");
Assert.notNull(server.getQuorum(), "Quorum must not be 'null' for server to monitor.");
jedis.sentinelMonitor(server.getName(), server.getHost(), server.getPort().intValue(), server.getQuorum()
.intValue());
jedis.sentinelMonitor(server.getName(), server.getHost(), server.getPort().intValue(),
server.getQuorum().intValue());
}
/*
@@ -147,7 +147,7 @@ public class JedisSentinelConnection implements RedisSentinelConnection {
/**
* Do what ever is required to establish the connection to redis.
*
*
* @param jedis
*/
protected void doInit(Jedis jedis) {
@@ -156,7 +156,7 @@ public class JedisSentinelConnection implements RedisSentinelConnection {
@Override
public boolean isOpen() {
return jedis != null && jedis.isConnected();
return jedis.isConnected();
}
}

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Properties;
@@ -31,15 +34,12 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisServerCommands implements RedisServerCommands {
private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')";
private final JedisConnection connection;
JedisServerCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -47,13 +47,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void bgReWriteAof() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().bgrewriteaof()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().bgrewriteaof()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().bgrewriteaof()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().bgrewriteaof()));
return;
}
connection.getJedis().bgrewriteaof();
@@ -68,13 +69,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void bgSave() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().bgsave()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().bgsave()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().bgsave()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().bgsave()));
return;
}
connection.getJedis().bgsave();
@@ -89,13 +91,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public Long lastSave() {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().lastsave()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lastsave()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().lastsave()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().lastsave()));
return null;
}
return connection.getJedis().lastsave();
@@ -110,13 +113,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void save() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().save()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().save()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().save()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().save()));
return;
}
connection.getJedis().save();
@@ -131,13 +135,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public Long dbSize() {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().dbSize()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().dbSize()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().dbSize()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().dbSize()));
return null;
}
return connection.getJedis().dbSize();
@@ -152,13 +157,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void flushDb() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().flushDB()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().flushDB()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().flushDB()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().flushDB()));
return;
}
connection.getJedis().flushDB();
@@ -173,13 +179,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void flushAll() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().flushAll()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().flushAll()));
return;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().flushAll()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().flushAll()));
return;
}
connection.getJedis().flushAll();
@@ -194,13 +201,15 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public Properties info() {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().info(), JedisConverters.stringToProps()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().info(), JedisConverters.stringToProps()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().info(), JedisConverters.stringToProps()));
transaction(
connection.newJedisResult(connection.getRequiredTransaction().info(), JedisConverters.stringToProps()));
return null;
}
return JedisConverters.toProperties(connection.getJedis().info());
@@ -215,12 +224,13 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public Properties info(String section) {
if (isPipelined()) {
throw new UnsupportedOperationException();
}
if (isQueueing()) {
Assert.notNull(section, "Section must not be null!");
if (isPipelined() || isQueueing()) {
throw new UnsupportedOperationException();
}
try {
return JedisConverters.toProperties(connection.getJedis().info(section));
} catch (Exception ex) {
@@ -234,13 +244,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void shutdown() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().shutdown()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().shutdown()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().shutdown()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().shutdown()));
return;
}
connection.getJedis().shutdown();
@@ -269,19 +280,22 @@ class JedisServerCommands implements RedisServerCommands {
* @see org.springframework.data.redis.connection.RedisServerCommands#getConfig(java.lang.String)
*/
@Override
public Properties getConfig(String param) {
public Properties getConfig(String pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().configGet(param),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().configGet(pattern),
Converters.listToPropertiesConverter()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().configGet(param),
transaction(connection.newJedisResult(connection.getRequiredTransaction().configGet(pattern),
Converters.listToPropertiesConverter()));
return null;
}
return Converters.toProperties(connection.getJedis().configGet(param));
return Converters.toProperties(connection.getJedis().configGet(pattern));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
@@ -293,13 +307,17 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void setConfig(String param, String value) {
Assert.notNull(param, "Parameter must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().configSet(param, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().configSet(param, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().configSet(param, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().configSet(param, value)));
return;
}
connection.getJedis().configSet(param, value);
@@ -314,13 +332,14 @@ class JedisServerCommands implements RedisServerCommands {
*/
@Override
public void resetConfigStats() {
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().configResetStat()));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().configResetStat()));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().configResetStat()));
transaction(connection.newStatusResult(connection.getRequiredTransaction().configResetStat()));
return;
}
connection.getJedis().configResetStat();
@@ -337,14 +356,13 @@ class JedisServerCommands implements RedisServerCommands {
public Long time() {
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().time(), JedisConverters.toTimeConverter()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().time(), JedisConverters.toTimeConverter()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().time(), JedisConverters.toTimeConverter()));
transaction(
connection.newJedisResult(connection.getRequiredTransaction().time(), JedisConverters.toTimeConverter()));
return null;
}
return JedisConverters.toTimeConverter().convert(connection.getJedis().time());
@@ -380,6 +398,8 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void setClientName(byte[] name) {
Assert.notNull(name, "Name must not be null!");
if (isPipelined() || isQueueing()) {
throw new UnsupportedOperationException("'CLIENT SETNAME' is not suppored in transacton / pipeline mode.");
}
@@ -422,6 +442,7 @@ class JedisServerCommands implements RedisServerCommands {
public void slaveOf(String host, int port) {
Assert.hasText(host, "Host must not be null for 'SLAVEOF' command.");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SLAVEOF' cannot be called in pipline / transaction mode.");
}
@@ -442,6 +463,7 @@ class JedisServerCommands implements RedisServerCommands {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SLAVEOF' cannot be called in pipline / transaction mode.");
}
try {
this.connection.getJedis().slaveofNoOne();
} catch (Exception e) {
@@ -465,17 +487,20 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, @Nullable MigrateOption option, long timeout) {
final int timeoutToUse = timeout <= Integer.MAX_VALUE ? (int) timeout : Integer.MAX_VALUE;
Assert.notNull(key, "Key must not be null!");
Assert.notNull(target, "Target node must not be null!");
int timeoutToUse = timeout <= Integer.MAX_VALUE ? (int) timeout : Integer.MAX_VALUE;
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().migrate(JedisConverters.toBytes(target.getHost()),
target.getPort(), key, dbIndex, timeoutToUse)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline()
.migrate(JedisConverters.toBytes(target.getHost()), target.getPort(), key, dbIndex, timeoutToUse)));
return;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction()
transaction(connection.newJedisResult(connection.getRequiredTransaction()
.migrate(JedisConverters.toBytes(target.getHost()), target.getPort(), key, dbIndex, timeoutToUse)));
return;
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import redis.clients.jedis.ScanParams;
import java.util.ArrayList;
@@ -27,19 +29,17 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.KeyBoundCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisSetCommands implements RedisSetCommands {
private final JedisConnection connection;
JedisSetCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
@@ -47,13 +47,18 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sAdd(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sadd(key, values)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sadd(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sadd(key, values)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sadd(key, values)));
return null;
}
return connection.getJedis().sadd(key, values);
@@ -68,13 +73,16 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sCard(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().scard(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().scard(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().scard(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().scard(key)));
return null;
}
return connection.getJedis().scard(key);
@@ -89,13 +97,17 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sDiff(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sdiff(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sdiff(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sdiff(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sdiff(keys)));
return null;
}
return connection.getJedis().sdiff(keys);
@@ -110,13 +122,18 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sDiffStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sdiffstore(destKey, keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sdiffstore(destKey, keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sdiffstore(destKey, keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sdiffstore(destKey, keys)));
return null;
}
return connection.getJedis().sdiffstore(destKey, keys);
@@ -131,13 +148,17 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sInter(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sinter(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sinter(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sinter(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sinter(keys)));
return null;
}
return connection.getJedis().sinter(keys);
@@ -152,13 +173,18 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sInterStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sinterstore(destKey, keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sinterstore(destKey, keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sinterstore(destKey, keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sinterstore(destKey, keys)));
return null;
}
return connection.getJedis().sinterstore(destKey, keys);
@@ -173,13 +199,17 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Boolean sIsMember(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.newJedisResult(connection.getPipeline().sismember(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sismember(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sismember(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sismember(key, value)));
return null;
}
return connection.getJedis().sismember(key, value);
@@ -194,13 +224,16 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sMembers(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().smembers(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().smembers(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().smembers(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().smembers(key)));
return null;
}
return connection.getJedis().smembers(key);
@@ -215,14 +248,19 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().smove(srcKey, destKey, value),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().smove(srcKey, destKey, value),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().smove(srcKey, destKey, value),
transaction(connection.newJedisResult(connection.getRequiredTransaction().smove(srcKey, destKey, value),
JedisConverters.longToBoolean()));
return null;
}
@@ -238,13 +276,16 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public byte[] sPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().spop(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().spop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().spop(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().spop(key)));
return null;
}
return connection.getJedis().spop(key);
@@ -260,13 +301,15 @@ class JedisSetCommands implements RedisSetCommands {
@Override
public List<byte[]> sPop(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().spop(key, count), ArrayList::new));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().spop(key, count), ArrayList::new));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().spop(key, count), ArrayList::new));
transaction(connection.newJedisResult(connection.getRequiredTransaction().spop(key, count), ArrayList::new));
return null;
}
return new ArrayList<>(connection.getJedis().spop(key, count));
@@ -281,13 +324,16 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public byte[] sRandMember(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().srandmember(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().srandmember(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().srandmember(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().srandmember(key)));
return null;
}
return connection.getJedis().srandmember(key);
@@ -303,17 +349,19 @@ class JedisSetCommands implements RedisSetCommands {
@Override
public List<byte[]> sRandMember(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
if (count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().srandmember(key, (int) count)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().srandmember(key, (int) count)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().srandmember(key, (int) count)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().srandmember(key, (int) count)));
return null;
}
return connection.getJedis().srandmember(key, (int) count);
@@ -328,13 +376,18 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sRem(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().srem(key, values)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().srem(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().srem(key, values)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().srem(key, values)));
return null;
}
return connection.getJedis().srem(key, values);
@@ -349,13 +402,17 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sUnion(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sunion(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sunion(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sunion(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sunion(keys)));
return null;
}
return connection.getJedis().sunion(keys);
@@ -370,13 +427,18 @@ class JedisSetCommands implements RedisSetCommands {
*/
@Override
public Long sUnionStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().sunionstore(destKey, keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().sunionstore(destKey, keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().sunionstore(destKey, keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().sunionstore(destKey, keys)));
return null;
}
return connection.getJedis().sunionstore(destKey, keys);
@@ -403,6 +465,8 @@ class JedisSetCommands implements RedisSetCommands {
*/
public Cursor<byte[]> sScan(byte[] key, long cursorId, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new KeyBoundCursor<byte[]>(key, cursorId, options) {
@Override

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.redis.connection.jedis;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -30,24 +33,27 @@ import org.springframework.util.ObjectUtils;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class JedisStringCommands implements RedisStringCommands {
private final JedisConnection connection;
JedisStringCommands(JedisConnection connection) {
this.connection = connection;
}
private final @NonNull JedisConnection connection;
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#get(byte[])
*/
@Override
public byte[] get(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().get(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().get(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().get(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().get(key)));
return null;
}
@@ -57,35 +63,48 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getSet(byte[], byte[])
*/
@Override
public byte[] getSet(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.newJedisResult(connection.getPipeline().getSet(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().getSet(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().getSet(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().getSet(key, value)));
return null;
}
return connection.getJedis().getSet(key, value);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mGet(byte[][])
*/
@Override
public List<byte[]> mGet(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().mget(keys)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().mget(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().mget(keys)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().mget(keys)));
return null;
}
return connection.getJedis().mget(keys);
@@ -94,16 +113,23 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[])
*/
@Override
public void 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.getPipeline().set(key, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().set(key, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value)));
return;
}
connection.getJedis().set(key, value);
@@ -112,9 +138,15 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @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) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
Assert.notNull(expiration, "Expiration must not be null!");
Assert.notNull(option, "Option must not be null!");
@@ -130,12 +162,12 @@ class JedisStringCommands implements RedisStringCommands {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().set(key, value, nxxx)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().set(key, value, nxxx)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().set(key, value, nxxx)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().set(key, value, nxxx)));
return;
}
@@ -169,7 +201,7 @@ class JedisStringCommands implements RedisStringCommands {
}
pipeline(connection.newStatusResult(
connection.getPipeline().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
connection.getRequiredPipeline().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
return;
}
if (isQueueing()) {
@@ -180,7 +212,7 @@ class JedisStringCommands implements RedisStringCommands {
}
transaction(connection.newStatusResult(
connection.getTransaction().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
connection.getRequiredTransaction().set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
return;
}
@@ -193,18 +225,25 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setNX(byte[], byte[])
*/
@Override
public Boolean setNX(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.newJedisResult(connection.getPipeline().setnx(key, value), JedisConverters.longToBoolean()));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().setnx(key, value),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().setnx(key, value), JedisConverters.longToBoolean()));
transaction(connection.newJedisResult(connection.getRequiredTransaction().setnx(key, value),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().setnx(key, value));
@@ -214,19 +253,27 @@ class JedisStringCommands implements RedisStringCommands {
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setEx(byte[], long, byte[])
*/
@Override
public void setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
if (seconds > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Time must be less than Integer.MAX_VALUE for setEx in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().setex(key, (int) seconds, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().setex(key, (int) seconds, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().setex(key, (int) seconds, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().setex(key, (int) seconds, value)));
return;
}
connection.getJedis().setex(key, (int) seconds, value);
@@ -235,16 +282,23 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
public void 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.getPipeline().psetex(key, milliseconds, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().psetex(key, milliseconds, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().psetex(key, milliseconds, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().psetex(key, milliseconds, value)));
return;
}
connection.getJedis().psetex(key, milliseconds, value);
@@ -253,16 +307,24 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
*/
@Override
public void mSet(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().mset(JedisConverters.toByteArrays(tuples))));
pipeline(
connection.newStatusResult(connection.getRequiredPipeline().mset(JedisConverters.toByteArrays(tuples))));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().mset(JedisConverters.toByteArrays(tuples))));
transaction(
connection.newStatusResult(connection.getRequiredTransaction().mset(JedisConverters.toByteArrays(tuples))));
return;
}
connection.getJedis().mset(JedisConverters.toByteArrays(tuples));
@@ -271,18 +333,26 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mSetNX(java.util.Map)
*/
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
pipeline(
connection.newJedisResult(connection.getRequiredPipeline().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
transaction(
connection.newJedisResult(connection.getRequiredTransaction().msetnx(JedisConverters.toByteArrays(tuples)),
JedisConverters.longToBoolean()));
return null;
}
return JedisConverters.toBoolean(connection.getJedis().msetnx(JedisConverters.toByteArrays(tuples)));
@@ -291,35 +361,46 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incr(byte[])
*/
@Override
public Long incr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().incr(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().incr(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().incr(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().incr(key)));
return null;
}
return connection.getJedis().incr(key);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incrBy(byte[], long)
*/
@Override
public Long incrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().incrBy(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().incrBy(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().incrBy(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().incrBy(key, value)));
return null;
}
return connection.getJedis().incrBy(key, value);
@@ -329,16 +410,22 @@ class JedisStringCommands implements RedisStringCommands {
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incrBy(byte[], double)
*/
@Override
public Double incrBy(byte[] key, double value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().incrByFloat(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().incrByFloat(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().incrByFloat(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().incrByFloat(key, value)));
return null;
}
return connection.getJedis().incrByFloat(key, value);
@@ -347,16 +434,22 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#decr(byte[])
*/
@Override
public Long decr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().decr(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().decr(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().decr(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().decr(key)));
return null;
}
return connection.getJedis().decr(key);
@@ -366,16 +459,22 @@ class JedisStringCommands implements RedisStringCommands {
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#decrBy(byte[], long)
*/
@Override
public Long decrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().decrBy(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().decrBy(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().decrBy(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().decrBy(key, value)));
return null;
}
return connection.getJedis().decrBy(key, value);
@@ -384,16 +483,23 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#append(byte[], byte[])
*/
@Override
public Long append(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.newJedisResult(connection.getPipeline().append(key, value)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().append(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().append(key, value)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().append(key, value)));
return null;
}
return connection.getJedis().append(key, value);
@@ -402,21 +508,27 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getRange(byte[], long, long)
*/
@Override
public byte[] getRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
if (start > Integer.MAX_VALUE || end > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Start and end must be less than Integer.MAX_VALUE for getRange in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().substr(key, (int) start, (int) end),
pipeline(connection.newJedisResult(connection.getRequiredPipeline().substr(key, (int) start, (int) end),
JedisConverters.stringToBytes()));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().substr(key, (int) start, (int) end),
transaction(connection.newJedisResult(connection.getRequiredTransaction().substr(key, (int) start, (int) end),
JedisConverters.stringToBytes()));
return null;
}
@@ -426,34 +538,47 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setRange(byte[], byte[], long)
*/
@Override
public void setRange(byte[] key, byte[] value, long start) {
public void setRange(byte[] key, byte[] value, long offset) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newStatusResult(connection.getPipeline().setrange(key, start, value)));
pipeline(connection.newStatusResult(connection.getRequiredPipeline().setrange(key, offset, value)));
return;
}
if (isQueueing()) {
transaction(connection.newStatusResult(connection.getTransaction().setrange(key, start, value)));
transaction(connection.newStatusResult(connection.getRequiredTransaction().setrange(key, offset, value)));
return;
}
connection.getJedis().setrange(key, start, value);
connection.getJedis().setrange(key, offset, value);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getBit(byte[], long)
*/
@Override
public Boolean getBit(byte[] key, long offset) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().getbit(key, offset)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().getbit(key, offset)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().getbit(key, offset)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().getbit(key, offset)));
return null;
}
// compatibility check for Jedis 2.0.0
@@ -469,18 +594,25 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setBit(byte[], long, boolean)
*/
@Override
public Boolean setBit(byte[] key, long offset, boolean value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().setbit(key, offset, JedisConverters.toBit(value))));
pipeline(connection
.newJedisResult(connection.getRequiredPipeline().setbit(key, offset, JedisConverters.toBit(value))));
return null;
}
if (isQueueing()) {
transaction(
connection.newJedisResult(connection.getTransaction().setbit(key, offset, JedisConverters.toBit(value))));
transaction(connection
.newJedisResult(connection.getRequiredTransaction().setbit(key, offset, JedisConverters.toBit(value))));
return null;
}
return connection.getJedis().setbit(key, offset, JedisConverters.toBit(value));
@@ -490,16 +622,22 @@ class JedisStringCommands implements RedisStringCommands {
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[])
*/
@Override
public Long bitCount(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().bitcount(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().bitcount(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().bitcount(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().bitcount(key)));
return null;
}
return connection.getJedis().bitcount(key);
@@ -508,39 +646,53 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[], long, long)
*/
@Override
public Long bitCount(byte[] key, long begin, long end) {
public Long bitCount(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().bitcount(key, begin, end)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().bitcount(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().bitcount(key, begin, end)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().bitcount(key, start, end)));
return null;
}
return connection.getJedis().bitcount(key, begin, end);
return connection.getJedis().bitcount(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitOp(org.springframework.data.redis.connection.RedisStringCommands.BitOperation, byte[], byte[][])
*/
@Override
public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
Assert.notNull(op, "BitOperation must not be null!");
Assert.notNull(destination, "Destination key must not be null!");
if (op == BitOperation.NOT && keys.length > 1) {
throw new UnsupportedOperationException("Bitop NOT should only be performed against one key");
}
try {
if (isPipelined()) {
pipeline(
connection.newJedisResult(connection.getPipeline().bitop(JedisConverters.toBitOp(op), destination, keys)));
pipeline(connection
.newJedisResult(connection.getRequiredPipeline().bitop(JedisConverters.toBitOp(op), destination, keys)));
return null;
}
if (isQueueing()) {
transaction(connection
.newJedisResult(connection.getTransaction().bitop(JedisConverters.toBitOp(op), destination, keys)));
.newJedisResult(connection.getRequiredTransaction().bitop(JedisConverters.toBitOp(op), destination, keys)));
return null;
}
return connection.getJedis().bitop(JedisConverters.toBitOp(op), destination, keys);
@@ -549,16 +701,22 @@ class JedisStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#strLen(byte[])
*/
@Override
public Long strLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getPipeline().strlen(key)));
pipeline(connection.newJedisResult(connection.getRequiredPipeline().strlen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getTransaction().strlen(key)));
transaction(connection.newJedisResult(connection.getRequiredTransaction().strlen(key)));
return null;
}
return connection.getJedis().strlen(key);

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Copyright 2011-2017 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
*
*
* http://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.
@@ -15,21 +15,23 @@
*/
package org.springframework.data.redis.connection.jedis;
import redis.clients.jedis.BinaryJedisPubSub;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.util.AbstractSubscription;
import redis.clients.jedis.BinaryJedisPubSub;
import org.springframework.lang.Nullable;
/**
* Jedis specific subscription.
*
*
* @author Costin Leau
*/
class JedisSubscription extends AbstractSubscription {
private final BinaryJedisPubSub jedisPubSub;
JedisSubscription(MessageListener listener, BinaryJedisPubSub jedisPubSub, byte[][] channels, byte[][] patterns) {
JedisSubscription(MessageListener listener, BinaryJedisPubSub jedisPubSub, @Nullable byte[][] channels,
@Nullable byte[][] patterns) {
super(listener, channels, patterns);
this.jedisPubSub = jedisPubSub;
}

View File

@@ -54,7 +54,7 @@ import org.springframework.util.Assert;
/**
* Helper class featuring methods for Jedis connection handling, providing support for exception translation. Deprecated
* in favor of {@link JedisConverters}
*
*
* @author Costin Leau
* @author Jennifer Hickey
*/
@@ -68,7 +68,7 @@ public abstract class JedisUtils {
/**
* Converts the given, native Jedis exception to Spring's DAO hierarchy.
*
*
* @param ex Jedis exception
* @return converted exception
*/
@@ -86,7 +86,7 @@ public abstract class JedisUtils {
/**
* Converts the given, native, runtime Jedis exception to Spring's DAO hierarchy.
*
*
* @param ex Jedis runtime/unchecked exception
* @return converted exception
*/
@@ -256,8 +256,8 @@ public abstract class JedisUtils {
}
static byte[][] bXPopArgs(int timeout, byte[]... keys) {
final List<byte[]> args = new ArrayList<>();
for (final byte[] arg : keys) {
List<byte[]> args = new ArrayList<>();
for (byte[] arg : keys) {
args.add(arg);
}
args.add(Protocol.toByteArray(timeout));

View File

@@ -2,4 +2,5 @@
* Connection package for <a href="http://github.com/xetorthio/jedis">Jedis</a> library.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.connection.jedis;

View File

@@ -247,11 +247,11 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#getClusterSlaves(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public Set<RedisClusterNode> clusterGetSlaves(final RedisClusterNode master) {
public Set<RedisClusterNode> clusterGetSlaves(RedisClusterNode master) {
Assert.notNull(master, "Master must not be null!");
final RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);
RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(master);
return clusterCommandExecutor
.executeCommandOnSingleNode((LettuceClusterCommandCallback<Set<RedisClusterNode>>) client -> LettuceConverters
@@ -305,7 +305,7 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#addSlots(org.springframework.data.redis.connection.RedisClusterNode, int[])
*/
@Override
public void clusterAddSlots(RedisClusterNode node, final int... slots) {
public void clusterAddSlots(RedisClusterNode node, int... slots) {
clusterCommandExecutor.executeCommandOnSingleNode(
(LettuceClusterCommandCallback<String>) client -> client.clusterAddSlots(slots), node);
@@ -329,7 +329,7 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#deleteSlots(org.springframework.data.redis.connection.RedisClusterNode, int[])
*/
@Override
public void clusterDeleteSlots(RedisClusterNode node, final int... slots) {
public void clusterDeleteSlots(RedisClusterNode node, int... slots) {
clusterCommandExecutor.executeCommandOnSingleNode(
(LettuceClusterCommandCallback<String>) client -> client.clusterDelSlots(slots), node);
}
@@ -351,10 +351,10 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterForget(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterForget(final RedisClusterNode node) {
public void clusterForget(RedisClusterNode node) {
List<RedisClusterNode> nodes = new ArrayList<>(clusterGetNodes());
final RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
RedisClusterNode nodeToRemove = topologyProvider.getTopology().lookup(node);
nodes.remove(nodeToRemove);
this.clusterCommandExecutor.executeCommandAsyncOnNodes(
@@ -366,7 +366,7 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterMeet(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterMeet(final RedisClusterNode node) {
public void clusterMeet(RedisClusterNode node) {
Assert.notNull(node, "Cluster node must not be null for CLUSTER MEET command!");
Assert.hasText(node.getHost(), "Node to meet cluster must have a host!");
@@ -381,13 +381,13 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterSetSlot(org.springframework.data.redis.connection.RedisClusterNode, int, org.springframework.data.redis.connection.RedisClusterCommands.AddSlots)
*/
@Override
public void clusterSetSlot(final RedisClusterNode node, final int slot, final AddSlots mode) {
public void clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode) {
Assert.notNull(node, "Node must not be null.");
Assert.notNull(mode, "AddSlots mode must not be null.");
final RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
final String nodeId = nodeToUse.getId();
RedisClusterNode nodeToUse = topologyProvider.getTopology().lookup(node);
String nodeId = nodeToUse.getId();
clusterCommandExecutor.executeCommandOnSingleNode((LettuceClusterCommandCallback<String>) client -> {
switch (mode) {
@@ -438,9 +438,9 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterReplicate(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisClusterNode)
*/
@Override
public void clusterReplicate(final RedisClusterNode master, RedisClusterNode slave) {
public void clusterReplicate(RedisClusterNode master, RedisClusterNode slave) {
final RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);
RedisClusterNode masterNode = topologyProvider.getTopology().lookup(master);
clusterCommandExecutor.executeCommandOnSingleNode(
(LettuceClusterCommandCallback<String>) client -> client.clusterReplicate(masterNode.getId()), slave);
}
@@ -479,7 +479,7 @@ public class LettuceClusterConnection extends LettuceConnection implements Defau
* @see org.springframework.data.redis.connection.RedisClusterConnection#keys(org.springframework.data.redis.connection.RedisClusterNode, byte[])
*/
@Override
public Set<byte[]> keys(RedisClusterNode node, final byte[] pattern) {
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
return doGetClusterKeyCommands().keys(node, pattern);
}

View File

@@ -28,6 +28,7 @@ import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.LettuceClusterCommandCallback;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -88,7 +89,7 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#keys(byte[])
*/
@Override
public Set<byte[]> keys(final byte[] pattern) {
public Set<byte[]> keys(byte[] pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
@@ -109,19 +110,22 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#rename(byte[], byte[])
*/
@Override
public void rename(byte[] oldName, byte[] newName) {
public void rename(byte[] sourceKey, byte[] targetKey) {
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldName, newName)) {
super.rename(oldName, newName);
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
super.rename(sourceKey, targetKey);
return;
}
byte[] value = dump(oldName);
byte[] value = dump(sourceKey);
if (value != null && value.length > 0) {
restore(newName, 0, value);
del(oldName);
restore(targetKey, 0, value);
del(sourceKey);
}
}
@@ -130,18 +134,21 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(byte[] oldName, byte[] newName) {
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldName, newName)) {
return super.renameNX(oldName, newName);
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
return super.renameNX(sourceKey, targetKey);
}
byte[] value = dump(oldName);
byte[] value = dump(sourceKey);
if (value != null && value.length > 0 && !exists(newName)) {
if (value != null && value.length > 0 && !exists(targetKey)) {
restore(newName, 0, value);
del(oldName);
restore(targetKey, 0, value);
del(sourceKey);
return Boolean.TRUE;
}
return Boolean.FALSE;
@@ -156,23 +163,11 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
throw new UnsupportedOperationException("MOVE not supported in CLUSTER mode!");
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#del(byte[][])
*/
@Override
public Long del(byte[]... keys) {
Assert.noNullElements(keys, "Keys must not be null or contain null key!");
// Routing for mget is handled by lettuce.
return super.del(keys);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterConnection#randomKey(org.springframework.data.redis.connection.RedisClusterNode)
*/
@Nullable
public byte[] randomKey(RedisClusterNode node) {
return connection.getClusterCommandExecutor()
@@ -184,7 +179,10 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterConnection#keys(org.springframework.data.redis.connection.RedisClusterNode, byte[])
*/
public Set<byte[]> keys(RedisClusterNode node, final byte[] pattern) {
@Nullable
public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
return LettuceConverters.toBytesSet(connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((LettuceClusterCommandCallback<List<byte[]>>) client -> client.keys(pattern), node)
@@ -198,6 +196,8 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
@Override
public Long sort(byte[] key, SortParameters params, byte[] storeKey) {
Assert.notNull(key, "Key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) {
return super.sort(key, params, storeKey);
}
@@ -220,5 +220,4 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
}
return 0L;
}
}

View File

@@ -23,6 +23,7 @@ import java.util.List;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.LettuceMultiKeyClusterCommandCallback;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@@ -45,7 +46,10 @@ class LettuceClusterListCommands extends LettuceListCommands {
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#bLPop(int, byte[][])
*/
@Override
public List<byte[]> bLPop(final int timeout, byte[]... keys) {
public List<byte[]> bLPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.bLPop(timeout, keys);
@@ -69,7 +73,10 @@ class LettuceClusterListCommands extends LettuceListCommands {
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#bRPop(int, byte[][])
*/
@Override
public List<byte[]> bRPop(final int timeout, byte[]... keys) {
public List<byte[]> bRPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.bRPop(timeout, keys);
@@ -95,6 +102,9 @@ class LettuceClusterListCommands extends LettuceListCommands {
@Override
public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, dstKey)) {
return super.rPopLPush(srcKey, dstKey);
}
@@ -111,6 +121,9 @@ class LettuceClusterListCommands extends LettuceListCommands {
@Override
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, dstKey)) {
return super.bRPopLPush(timeout, srcKey, dstKey);
}

View File

@@ -185,7 +185,9 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#info(java.lang.String)
*/
@Override
public Properties info(final String section) {
public Properties info(String section) {
Assert.hasText(section, "Section must not be null or empty!");
Properties infos = new Properties();
List<NodeResult<Properties>> nodeResults = executeCommandOnAllNodes(
@@ -205,7 +207,10 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#info(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String)
*/
@Override
public Properties info(RedisClusterNode node, final String section) {
public Properties info(RedisClusterNode node, String section) {
Assert.hasText(section, "Section must not be null or empty!");
return LettuceConverters.toProperties(executeCommandOnSingleNode(client -> client.info(section), node).getValue());
}
@@ -227,7 +232,9 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#getConfig(java.lang.String)
*/
@Override
public Properties getConfig(final String pattern) {
public Properties getConfig(String pattern) {
Assert.hasText(pattern, "Pattern must not be null or empty!");
List<NodeResult<Map<String, String>>> mapResult = executeCommandOnAllNodes(client -> client.configGet(pattern))
.getResults();
@@ -248,7 +255,10 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#getConfig(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String)
*/
@Override
public Properties getConfig(RedisClusterNode node, final String pattern) {
public Properties getConfig(RedisClusterNode node, String pattern) {
Assert.hasText(pattern, "Pattern must not be null or empty!");
return executeCommandOnSingleNode(client -> Converters.toProperties(client.configGet(pattern)), node).getValue();
}
@@ -257,7 +267,11 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#setConfig(java.lang.String, java.lang.String)
*/
@Override
public void setConfig(final String param, final String value) {
public void setConfig(String param, String value) {
Assert.hasText(param, "Parameter must not be null or empty!");
Assert.hasText(value, "Value must not be null or empty!");
executeCommandOnAllNodes(client -> client.configSet(param, value));
}
@@ -266,7 +280,11 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#setConfig(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String, java.lang.String)
*/
@Override
public void setConfig(RedisClusterNode node, final String param, final String value) {
public void setConfig(RedisClusterNode node, String param, String value) {
Assert.hasText(param, "Parameter must not be null or empty!");
Assert.hasText(value, "Value must not be null or empty!");
executeCommandOnSingleNode(client -> client.configSet(param, value), node);
}

View File

@@ -26,6 +26,7 @@ import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.lettuce.LettuceClusterConnection.LettuceMultiKeyClusterCommandCallback;
import org.springframework.data.redis.connection.util.ByteArraySet;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
@@ -49,6 +50,10 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(value, "Value must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, destKey)) {
return super.sMove(srcKey, destKey, value);
}
@@ -68,6 +73,9 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Set<byte[]> sInter(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.sInter(keys);
}
@@ -105,6 +113,10 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Long sInterStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -125,6 +137,9 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Set<byte[]> sUnion(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.sUnion(keys);
}
@@ -153,6 +168,10 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Long sUnionStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
@@ -173,6 +192,9 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Set<byte[]> sDiff(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.sDiff(keys);
}
@@ -204,6 +226,10 @@ class LettuceClusterSetCommands extends LettuceSetCommands {
@Override
public Long sDiffStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {

View File

@@ -18,6 +18,7 @@ package org.springframework.data.redis.connection.lettuce;
import java.util.Map;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
@@ -37,6 +38,8 @@ class LettuceClusterStringCommands extends LettuceStringCommands {
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
if (ClusterSlotHashUtil.isSameSlotForAllKeys(tuples.keySet().toArray(new byte[tuples.keySet().size()][]))) {
return super.mSetNX(tuples);
}

View File

@@ -95,7 +95,7 @@ public class LettuceConnection extends AbstractRedisConnection {
private int dbIndex;
private final LettuceConnectionProvider connectionProvider;
private final StatefulConnection<byte[], byte[]> asyncSharedConn;
private final @Nullable StatefulConnection<byte[], byte[]> asyncSharedConn;
private @Nullable StatefulConnection<byte[], byte[]> asyncDedicatedConn;
private final long timeout;
@@ -105,7 +105,7 @@ public class LettuceConnection extends AbstractRedisConnection {
private boolean isMulti = false;
private boolean isPipelined = false;
private @Nullable List<LettuceResult> ppline;
private Queue<FutureResult<?>> txResults = new LinkedList<>();
private final Queue<FutureResult<?>> txResults = new LinkedList<>();
private volatile @Nullable LettuceSubscription subscription;
/** flag indicating whether the connection needs to be dropped or not */
private boolean convertPipelineAndTxResults = true;
@@ -129,7 +129,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
return resultHolder.getOutput().get();
} catch (Exception e) {
throw EXCEPTION_TRANSLATION.translate(e);
throw LettuceConnection.this.convertLettuceAccessException(e);
}
}
}
@@ -239,7 +239,8 @@ public class LettuceConnection extends AbstractRedisConnection {
* @param timeout The connection timeout (in milliseconds)
* @param client The {@link RedisClient} to use when making pub/sub, blocking, and tx connections
*/
public LettuceConnection(StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout, RedisClient client) {
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
RedisClient client) {
this(sharedConnection, timeout, client, null);
}
@@ -255,8 +256,8 @@ public class LettuceConnection extends AbstractRedisConnection {
* {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)}
*/
@Deprecated
public LettuceConnection(StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout, RedisClient client,
LettucePool pool) {
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
RedisClient client, @Nullable LettucePool pool) {
this(sharedConnection, timeout, client, pool, 0);
}
@@ -273,8 +274,8 @@ public class LettuceConnection extends AbstractRedisConnection {
* {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)}
*/
@Deprecated
public LettuceConnection(StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
AbstractRedisClient client, LettucePool pool, int defaultDbIndex) {
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
@Nullable AbstractRedisClient client, @Nullable LettucePool pool, int defaultDbIndex) {
if (pool != null) {
this.connectionProvider = new LettucePoolConnectionProvider(pool);
@@ -402,6 +403,7 @@ public class LettuceConnection extends AbstractRedisConnection {
return new LettuceZSetCommands(this);
}
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object await(RedisFuture<?> cmd) {
@@ -425,8 +427,9 @@ public class LettuceConnection extends AbstractRedisConnection {
* @param args Possible command arguments (may be {@literal null})
* @return execution result.
*/
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object execute(String command, CommandOutput commandOutputTypeHint, byte[]... args) {
public Object execute(String command, @Nullable CommandOutput commandOutputTypeHint, byte[]... args) {
Assert.hasText(command, "a valid command needs to be specified");
try {
@@ -461,6 +464,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void close() throws DataAccessException {
super.close();
@@ -489,22 +493,27 @@ public class LettuceConnection extends AbstractRedisConnection {
this.dbIndex = defaultDbIndex;
}
@Override
public boolean isClosed() {
return isClosed && !isSubscribed();
}
@Override
public RedisClusterAsyncCommands<byte[], byte[]> getNativeConnection() {
return (subscription != null ? subscription.pubsub.async() : getAsyncConnection());
}
@Override
public boolean isQueueing() {
return isMulti;
}
@Override
public boolean isPipelined() {
return isPipelined;
}
@Override
public void openPipeline() {
if (!isPipelined) {
isPipelined = true;
@@ -512,6 +521,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public List<Object> closePipeline() {
if (isPipelined) {
@@ -593,6 +603,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public String ping() {
try {
if (isPipelined()) {
@@ -609,6 +620,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void discard() {
isMulti = false;
try {
@@ -624,6 +636,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Object> exec() {
isMulti = false;
@@ -632,7 +645,7 @@ public class LettuceConnection extends AbstractRedisConnection {
RedisFuture<TransactionResult> exec = ((RedisAsyncCommands) getAsyncDedicatedConnection()).exec();
LettuceTransactionResultConverter resultConverter = new LettuceTransactionResultConverter(
new LinkedList<FutureResult<?>>(txResults), LettuceConverters.exceptionConverter());
new LinkedList<>(txResults), LettuceConverters.exceptionConverter());
pipeline(new LettuceResult(exec,
source -> resultConverter.convert(LettuceConverters.transactionResultUnwrapper().convert(source))));
@@ -651,6 +664,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void multi() {
if (isQueueing()) {
return;
@@ -667,6 +681,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void select(int dbIndex) {
if (asyncSharedConn != null) {
@@ -689,6 +704,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void unwatch() {
try {
if (isPipelined()) {
@@ -705,6 +721,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void watch(byte[]... keys) {
if (isQueueing()) {
throw new UnsupportedOperationException();
@@ -728,6 +745,7 @@ public class LettuceConnection extends AbstractRedisConnection {
// Pub/Sub functionality
//
@Override
public Long publish(byte[] channel, byte[] message) {
try {
if (isPipelined()) {
@@ -744,14 +762,17 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public Subscription getSubscription() {
return subscription;
}
@Override
public boolean isSubscribed() {
return (subscription != null && subscription.isAlive());
}
@Override
public void pSubscribe(MessageListener listener, byte[]... patterns) {
checkSubscription();
@@ -769,6 +790,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
@Override
public void subscribe(MessageListener listener, byte[]... channels) {
checkSubscription();
@@ -918,7 +940,9 @@ public class LettuceConnection extends AbstractRedisConnection {
return io.lettuce.core.ScanCursor.of(Long.toString(cursorId));
}
ScanArgs getScanArgs(ScanOptions options) {
@Nullable
ScanArgs getScanArgs(@Nullable ScanOptions options) {
if (options == null) {
return null;
}
@@ -943,7 +967,7 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
private void validateCommand(CommandType cmd, byte[]... args) {
private void validateCommand(CommandType cmd, @Nullable byte[]... args) {
RedisCommand redisCommand = RedisCommand.failsafeCommandLookup(cmd.name());
if (!RedisCommand.UNKNOWN.equals(redisCommand) && redisCommand.requiresArguments()) {
@@ -958,10 +982,6 @@ public class LettuceConnection extends AbstractRedisConnection {
@Override
protected boolean isActive(RedisNode node) {
if (node == null) {
return false;
}
StatefulRedisSentinelConnection<String, String> connection = null;
try {
connection = getConnection(node);
@@ -992,8 +1012,8 @@ public class LettuceConnection extends AbstractRedisConnection {
@SuppressWarnings("unchecked")
private StatefulRedisSentinelConnection<String, String> getConnection(RedisNode sentinel) {
return (StatefulRedisSentinelConnection) ((TargetAware) connectionProvider)
.getConnection(StatefulRedisSentinelConnection.class, getRedisURI(sentinel));
return ((TargetAware) connectionProvider).getConnection(StatefulRedisSentinelConnection.class,
getRedisURI(sentinel));
}
LettuceConnectionProvider getConnectionProvider() {

View File

@@ -46,7 +46,6 @@ public interface LettuceConnectionProvider {
* @return the requested connection. Must be {@link #release(StatefulConnection) released} if the connection is no
* longer in use.
*/
@SuppressWarnings("rawtypes")
<T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType);
/**
@@ -72,7 +71,6 @@ public interface LettuceConnectionProvider {
* @param redisURI must not be {@literal null}.
* @return the requested connection.
*/
@SuppressWarnings("rawtypes")
<T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType, RedisURI redisURI);
}
}

View File

@@ -33,12 +33,17 @@ import org.springframework.data.redis.RedisSystemException;
/**
* Converts Lettuce Exceptions to {@link DataAccessException}s
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Mark Paluch
*/
public class LettuceExceptionConverter implements Converter<Exception, DataAccessException> {
/*
* (non-Javadoc)
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
*/
public DataAccessException convert(Exception ex) {
if (ex instanceof ExecutionException || ex instanceof RedisCommandExecutionException) {

View File

@@ -20,6 +20,8 @@ import io.lettuce.core.GeoCoordinates;
import io.lettuce.core.GeoWithin;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.Collection;
@@ -40,19 +42,18 @@ import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.connection.convert.ListConverter;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceResult;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceTxResult;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceGeoCommands implements RedisGeoCommands {
private final LettuceConnection connection;
public LettuceGeoCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -80,33 +81,6 @@ class LettuceGeoCommands implements RedisGeoCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
*/
@Override
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(location, "Location must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().geoadd(key, location.getPoint().getX(),
location.getPoint().getY(), location.getName())));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(
getConnection().geoadd(key, location.getPoint().getX(), location.getPoint().getY(), location.getName())));
return null;
}
return getConnection().geoadd(key, location.getPoint().getX(), location.getPoint().getY(), location.getName());
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
@@ -149,6 +123,7 @@ class LettuceGeoCommands implements RedisGeoCommands {
return geoAdd(key, values);
}
@Nullable
private Long geoAdd(byte[] key, Collection<Object> values) {
try {

View File

@@ -19,6 +19,8 @@ import io.lettuce.core.MapScanCursor;
import io.lettuce.core.ScanArgs;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Map;
@@ -33,18 +35,17 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.KeyBoundCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceHashCommands implements RedisHashCommands {
private final LettuceConnection connection;
public LettuceHashCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -52,6 +53,11 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Boolean hSet(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hset(key, field, value)));
@@ -73,6 +79,11 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hsetnx(key, field, value)));
@@ -94,6 +105,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Long hDel(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hdel(key, fields)));
@@ -115,6 +130,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Boolean hExists(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hexists(key, field)));
@@ -136,6 +155,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public byte[] hGet(byte[] key, byte[] field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hget(key, field)));
@@ -157,6 +180,9 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Map<byte[], byte[]> hGetAll(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hgetall(key)));
@@ -178,6 +204,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Long hIncrBy(byte[] key, byte[] field, long delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hincrby(key, field, delta)));
@@ -199,6 +229,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Double hIncrBy(byte[] key, byte[] field, double delta) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hincrbyfloat(key, field, delta)));
@@ -220,6 +254,9 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Set<byte[]> hKeys(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hkeys(key), LettuceConverters.bytesListToBytesSet()));
@@ -241,6 +278,9 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public Long hLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hlen(key)));
@@ -262,6 +302,10 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public List<byte[]> hMGet(byte[] key, byte[]... fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hmget(key, fields),
@@ -284,17 +328,21 @@ class LettuceHashCommands implements RedisHashCommands {
* @see org.springframework.data.redis.connection.RedisHashCommands#hMSet(byte[], java.util.Map)
*/
@Override
public void hMSet(byte[] key, Map<byte[], byte[]> tuple) {
public void hMSet(byte[] key, Map<byte[], byte[]> hashes) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(hashes, "Hashes must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().hmset(key, tuple)));
pipeline(connection.newLettuceStatusResult(getAsyncConnection().hmset(key, hashes)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().hmset(key, tuple)));
transaction(connection.newLettuceTxStatusResult(getConnection().hmset(key, hashes)));
return;
}
getConnection().hmset(key, tuple);
getConnection().hmset(key, hashes);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -306,6 +354,9 @@ class LettuceHashCommands implements RedisHashCommands {
*/
@Override
public List<byte[]> hVals(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().hvals(key)));
@@ -338,6 +389,8 @@ class LettuceHashCommands implements RedisHashCommands {
*/
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, long cursorId, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new KeyBoundCursor<Entry<byte[], byte[]>>(key, cursorId, options) {
@Override
@@ -357,6 +410,7 @@ class LettuceHashCommands implements RedisHashCommands {
return new ScanIteration<>(Long.valueOf(nextCursorId), values.entrySet());
}
@Override
protected void doClose() {
LettuceHashCommands.this.connection.close();
}

View File

@@ -19,6 +19,8 @@ import io.lettuce.core.api.async.RedisHLLAsyncCommands;
import io.lettuce.core.api.sync.RedisHLLCommands;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisHyperLogLogCommands;
@@ -28,15 +30,13 @@ import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceHyperLogLogCommands implements RedisHyperLogLogCommands {
private final LettuceConnection connection;
public LettuceHyperLogLogCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -77,6 +77,7 @@ class LettuceHyperLogLogCommands implements RedisHyperLogLogCommands {
Assert.notEmpty(keys, "PFCOUNT requires at least one non 'null' key.");
Assert.noNullElements(keys, "Keys for PFCOUNT must not contain 'null'.");
try {
if (isPipelined()) {
RedisHLLAsyncCommands<byte[], byte[]> asyncConnection = getAsyncConnection();
@@ -104,8 +105,9 @@ class LettuceHyperLogLogCommands implements RedisHyperLogLogCommands {
@Override
public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
Assert.notEmpty(sourceKeys, "PFMERGE requires at least one non 'null' source key.");
Assert.noNullElements(sourceKeys, "source key for PFMERGE must not contain 'null'.");
Assert.notNull(destinationKey, "Destination key must not be null");
Assert.notNull(sourceKeys, "Source keys must not be null");
Assert.noNullElements(sourceKeys, "Keys for PFMERGE must not contain 'null'.");
try {
if (isPipelined()) {

View File

@@ -20,6 +20,8 @@ import io.lettuce.core.ScanArgs;
import io.lettuce.core.SortArgs;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Set;
@@ -40,80 +42,13 @@ import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceKeyCommands implements RedisKeyCommands {
private final LettuceConnection connection;
public LettuceKeyCommands(LettuceConnection connection) {
this.connection = connection;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#dump(byte[])
*/
@Override
public byte[] dump(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().dump(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().dump(key)));
return null;
}
return getConnection().dump(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#restore(byte[], long, byte[])
*/
@Override
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().restore(key, ttlInMillis, serializedValue)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().restore(key, ttlInMillis, serializedValue)));
return;
}
getConnection().restore(key, ttlInMillis, serializedValue);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#keys(byte[])
*/
@Override
public Set<byte[]> keys(byte[] pattern) {
try {
if (isPipelined()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().keys(pattern), LettuceConverters.bytesListToBytesSet()));
return null;
}
if (isQueueing()) {
transaction(
connection.newLettuceTxResult(getConnection().keys(pattern), LettuceConverters.bytesListToBytesSet()));
return null;
}
return LettuceConverters.toBytesSet(getConnection().keys(pattern));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -121,6 +56,9 @@ class LettuceKeyCommands implements RedisKeyCommands {
*/
@Override
public Boolean exists(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().exists(new byte[][] { key }),
@@ -138,12 +76,216 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#del(byte[][])
*/
@Override
public Long del(byte[]... keys) {
Assert.noNullElements(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().del(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().del(keys)));
return null;
}
return getConnection().del(keys);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#type(byte[])
*/
@Override
public DataType type(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().type(key), LettuceConverters.stringToDataType()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().type(key), LettuceConverters.stringToDataType()));
return null;
}
return LettuceConverters.toDataType(getConnection().type(key));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#keys(byte[])
*/
@Override
public Set<byte[]> keys(byte[] pattern) {
Assert.notNull(pattern, "Pattern must not be null!");
try {
if (isPipelined()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().keys(pattern), LettuceConverters.bytesListToBytesSet()));
return null;
}
if (isQueueing()) {
transaction(
connection.newLettuceTxResult(getConnection().keys(pattern), LettuceConverters.bytesListToBytesSet()));
return null;
}
return LettuceConverters.toBytesSet(getConnection().keys(pattern));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/**
* @since 1.4
* @return
*/
public Cursor<byte[]> scan() {
return scan(0, ScanOptions.NONE);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#scan(org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<byte[]> scan(ScanOptions options) {
return scan(0, options != null ? options : ScanOptions.NONE);
}
/**
* @since 1.4
* @param cursorId
* @param options
* @return
*/
public Cursor<byte[]> scan(long cursorId, ScanOptions options) {
return new ScanCursor<byte[]>(cursorId, options) {
@SuppressWarnings("unchecked")
@Override
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
}
io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId);
ScanArgs scanArgs = connection.getScanArgs(options);
KeyScanCursor<byte[]> keyScanCursor = getConnection().scan(scanCursor, scanArgs);
String nextCursorId = keyScanCursor.getCursor();
List<byte[]> keys = keyScanCursor.getKeys();
return new ScanIteration<>(Long.valueOf(nextCursorId), (keys));
}
@Override
protected void doClose() {
LettuceKeyCommands.this.connection.close();
}
}.open();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#randomKey()
*/
@Override
public byte[] randomKey() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().randomkey()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().randomkey()));
return null;
}
return getConnection().randomkey();
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
*/
@Override
public void rename(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().rename(sourceKey, targetKey)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().rename(sourceKey, targetKey)));
return;
}
getConnection().rename(sourceKey, targetKey);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(targetKey, "Target key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().renamenx(sourceKey, targetKey)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().renamenx(sourceKey, targetKey)));
return null;
}
return (getConnection().renamenx(sourceKey, targetKey));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#expire(byte[], long)
*/
@Override
public Boolean expire(byte[] key, long seconds) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().expire(key, seconds)));
@@ -159,33 +301,15 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#expireAt(byte[], long)
*/
@Override
public Boolean expireAt(byte[] key, long unixTime) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().expireat(key, unixTime)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().expireat(key, unixTime)));
return null;
}
return getConnection().expireat(key, unixTime);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pExpire(byte[], long)
*/
@Override
public Boolean pExpire(byte[] key, long millis) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().pexpire(key, millis)));
@@ -201,12 +325,39 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#expireAt(byte[], long)
*/
@Override
public Boolean expireAt(byte[] key, long unixTime) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().expireat(key, unixTime)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().expireat(key, unixTime)));
return null;
}
return getConnection().expireat(key, unixTime);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pExpireAt(byte[], long)
*/
@Override
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().pexpireat(key, unixTimeInMillis)));
@@ -222,6 +373,104 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#persist(byte[])
*/
@Override
public Boolean persist(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().persist(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().persist(key)));
return null;
}
return getConnection().persist(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#move(byte[], int)
*/
@Override
public Boolean move(byte[] key, int dbIndex) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().move(key, dbIndex)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().move(key, dbIndex)));
return null;
}
return getConnection().move(key, dbIndex);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[])
*/
@Override
public Long ttl(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().ttl(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().ttl(key)));
return null;
}
return getConnection().ttl(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[], java.util.concurrent.TimeUnit)
*/
@Override
public Long ttl(byte[] key, TimeUnit timeUnit) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
return null;
}
return Converters.secondsToTimeUnit(getConnection().ttl(key), timeUnit);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[])
@@ -274,27 +523,6 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#del(byte[][])
*/
@Override
public Long del(byte[]... keys) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().del(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().del(keys)));
return null;
}
return getConnection().del(keys);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#sort(byte[], org.springframework.data.redis.connection.SortParameters)
@@ -302,6 +530,8 @@ class LettuceKeyCommands implements RedisKeyCommands {
@Override
public List<byte[]> sort(byte[] key, SortParameters params) {
Assert.notNull(key, "Key must not be null!");
SortArgs args = LettuceConverters.toSortArgs(params);
try {
@@ -326,6 +556,8 @@ class LettuceKeyCommands implements RedisKeyCommands {
@Override
public Long sort(byte[] key, SortParameters params, byte[] sortKey) {
Assert.notNull(key, "Key must not be null!");
SortArgs args = LettuceConverters.toSortArgs(params);
try {
@@ -345,129 +577,23 @@ class LettuceKeyCommands implements RedisKeyCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#persist(byte[])
* @see org.springframework.data.redis.connection.RedisKeyCommands#dump(byte[])
*/
@Override
public Boolean persist(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().persist(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().persist(key)));
return null;
}
return getConnection().persist(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#move(byte[], int)
*/
@Override
public Boolean move(byte[] key, int dbIndex) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().move(key, dbIndex)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().move(key, dbIndex)));
return null;
}
return getConnection().move(key, dbIndex);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#randomKey()
*/
@Override
public byte[] randomKey() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().randomkey()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().randomkey()));
return null;
}
return getConnection().randomkey();
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
*/
@Override
public void rename(byte[] oldName, byte[] newName) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().rename(oldName, newName)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().rename(oldName, newName)));
return;
}
getConnection().rename(oldName, newName);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
*/
@Override
public Boolean renameNX(byte[] oldName, byte[] newName) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().renamenx(oldName, newName)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().renamenx(oldName, newName)));
return null;
}
return (getConnection().renamenx(oldName, newName));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[])
*/
@Override
public Long ttl(byte[] key) {
public byte[] dump(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().ttl(key)));
pipeline(connection.newLettuceResult(getAsyncConnection().dump(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().ttl(key)));
transaction(connection.newLettuceTxResult(getConnection().dump(key)));
return null;
}
return getConnection().ttl(key);
return getConnection().dump(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -475,104 +601,29 @@ class LettuceKeyCommands implements RedisKeyCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[], java.util.concurrent.TimeUnit)
* @see org.springframework.data.redis.connection.RedisKeyCommands#restore(byte[], long, byte[])
*/
@Override
public Long ttl(byte[] key, TimeUnit timeUnit) {
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(serializedValue, "Serialized value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
return null;
pipeline(connection.newLettuceStatusResult(getAsyncConnection().restore(key, ttlInMillis, serializedValue)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().ttl(key), Converters.secondsToTimeUnit(timeUnit)));
return null;
transaction(connection.newLettuceTxStatusResult(getConnection().restore(key, ttlInMillis, serializedValue)));
return;
}
return Converters.secondsToTimeUnit(getConnection().ttl(key), timeUnit);
getConnection().restore(key, ttlInMillis, serializedValue);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#type(byte[])
*/
@Override
public DataType type(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().type(key), LettuceConverters.stringToDataType()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().type(key), LettuceConverters.stringToDataType()));
return null;
}
return LettuceConverters.toDataType(getConnection().type(key));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/**
* @since 1.4
* @return
*/
public Cursor<byte[]> scan() {
return scan(0, ScanOptions.NONE);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#scan(org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<byte[]> scan(ScanOptions options) {
return scan(0, options != null ? options : ScanOptions.NONE);
}
/**
* @since 1.4
* @param cursorId
* @param options
* @return
*/
public Cursor<byte[]> scan(long cursorId, ScanOptions options) {
return new ScanCursor<byte[]>(cursorId, options) {
@SuppressWarnings("unchecked")
@Override
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
}
io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId);
ScanArgs scanArgs = connection.getScanArgs(options);
KeyScanCursor<byte[]> keyScanCursor = getConnection().scan(scanCursor, scanArgs);
String nextCursorId = keyScanCursor.getCursor();
List<byte[]> keys = keyScanCursor.getKeys();
return new ScanIteration<>(Long.valueOf(nextCursorId), (keys));
}
protected void doClose() {
LettuceKeyCommands.this.connection.close();
}
}.open();
}
private boolean isPipelined() {
return connection.isPipelined();
}

View File

@@ -17,6 +17,8 @@ package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
@@ -24,39 +26,17 @@ import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisListCommands;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceResult;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceTxResult;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceListCommands implements RedisListCommands {
private final LettuceConnection connection;
public LettuceListCommands(LettuceConnection connection) {
this.connection = connection;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPush(byte[], byte[][])
*/
@Override
public Long lPush(byte[] key, byte[]... values) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lpush(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpush(key, values)));
return null;
}
return getConnection().lpush(key, values);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -64,6 +44,9 @@ class LettuceListCommands implements RedisListCommands {
*/
@Override
public Long rPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().rpush(key, values)));
@@ -79,12 +62,312 @@ class LettuceListCommands implements RedisListCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPush(byte[], byte[][])
*/
@Override
public Long lPush(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lpush(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpush(key, values)));
return null;
}
return getConnection().lpush(key, values);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#rPushX(byte[], byte[])
*/
@Override
public Long rPushX(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.newLettuceResult(getAsyncConnection().rpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().rpushx(key, value)));
return null;
}
return getConnection().rpushx(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPushX(byte[], byte[])
*/
@Override
public Long lPushX(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.newLettuceResult(getAsyncConnection().lpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpushx(key, value)));
return null;
}
return getConnection().lpushx(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lLen(byte[])
*/
@Override
public Long lLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().llen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().llen(key)));
return null;
}
return getConnection().llen(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lRange(byte[], long, long)
*/
@Override
public List<byte[]> lRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lrange(key, start, end)));
return null;
}
return getConnection().lrange(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lTrim(byte[], long, long)
*/
@Override
public void lTrim(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().ltrim(key, start, end)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().ltrim(key, start, end)));
return;
}
getConnection().ltrim(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lIndex(byte[], long)
*/
@Override
public byte[] lIndex(byte[] key, long index) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lindex(key, index)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lindex(key, index)));
return null;
}
return getConnection().lindex(key, index);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lInsert(byte[], org.springframework.data.redis.connection.RedisListCommands.Position, byte[], byte[])
*/
@Override
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection
.newLettuceResult(getAsyncConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
return null;
}
if (isQueueing()) {
transaction(connection
.newLettuceTxResult(getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
return null;
}
return getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lSet(byte[], long, byte[])
*/
@Override
public void lSet(byte[] key, long index, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().lset(key, index, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().lset(key, index, value)));
return;
}
getConnection().lset(key, index, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lRem(byte[], long, byte[])
*/
@Override
public Long lRem(byte[] key, long count, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lrem(key, count, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lrem(key, count, value)));
return null;
}
return getConnection().lrem(key, count, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[])
*/
@Override
public byte[] lPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpop(key)));
return null;
}
return getConnection().lpop(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[])
*/
@Override
public byte[] rPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().rpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().rpop(key)));
return null;
}
return getConnection().rpop(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#bLPop(int, byte[][])
*/
@Override
public List<byte[]> bLPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(connection.getAsyncDedicatedConnection().blpop(timeout, keys),
@@ -108,6 +391,10 @@ class LettuceListCommands implements RedisListCommands {
*/
@Override
public List<byte[]> bRPop(int timeout, byte[]... keys) {
Assert.notNull(keys, "Key must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(connection.getAsyncDedicatedConnection().brpop(timeout, keys),
@@ -125,203 +412,16 @@ class LettuceListCommands implements RedisListCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lIndex(byte[], long)
*/
@Override
public byte[] lIndex(byte[] key, long index) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lindex(key, index)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lindex(key, index)));
return null;
}
return getConnection().lindex(key, index);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lInsert(byte[], org.springframework.data.redis.connection.RedisListCommands.Position, byte[], byte[])
*/
@Override
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection
.newLettuceResult(getAsyncConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
return null;
}
if (isQueueing()) {
transaction(connection
.newLettuceTxResult(getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
return null;
}
return getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lLen(byte[])
*/
@Override
public Long lLen(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().llen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().llen(key)));
return null;
}
return getConnection().llen(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[])
*/
@Override
public byte[] lPop(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpop(key)));
return null;
}
return getConnection().lpop(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lRange(byte[], long, long)
*/
@Override
public List<byte[]> lRange(byte[] key, long start, long end) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lrange(key, start, end)));
return null;
}
return getConnection().lrange(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lRem(byte[], long, byte[])
*/
@Override
public Long lRem(byte[] key, long count, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lrem(key, count, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lrem(key, count, value)));
return null;
}
return getConnection().lrem(key, count, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lSet(byte[], long, byte[])
*/
@Override
public void lSet(byte[] key, long index, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().lset(key, index, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().lset(key, index, value)));
return;
}
getConnection().lset(key, index, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lTrim(byte[], long, long)
*/
@Override
public void lTrim(byte[] key, long start, long end) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().ltrim(key, start, end)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().ltrim(key, start, end)));
return;
}
getConnection().ltrim(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[])
*/
@Override
public byte[] rPop(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().rpop(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().rpop(key)));
return null;
}
return getConnection().rpop(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#rPopLPush(byte[], byte[])
*/
@Override
public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().rpoplpush(srcKey, dstKey)));
@@ -343,6 +443,10 @@ class LettuceListCommands implements RedisListCommands {
*/
@Override
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(dstKey, "Destination key must not be null!");
try {
if (isPipelined()) {
pipeline(
@@ -360,48 +464,6 @@ class LettuceListCommands implements RedisListCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#lPushX(byte[], byte[])
*/
@Override
public Long lPushX(byte[] key, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().lpushx(key, value)));
return null;
}
return getConnection().lpushx(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisListCommands#rPushX(byte[], byte[])
*/
@Override
public Long rPushX(byte[] key, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().rpushx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().rpushx(key, value)));
return null;
}
return getConnection().rpushx(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
private boolean isPipelined() {
return connection.isPipelined();
}

View File

@@ -164,7 +164,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<Properties> info(String section) {
Assert.hasText(section, "Section must not be null nor empty!");
Assert.hasText(section, "Section must not be null or empty!");
return Flux.merge(executeOnAllNodes(redisClusterNode -> info(redisClusterNode, section)))
.collect(PropertiesCollector.INSTANCE);
@@ -177,7 +177,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<Properties> info(RedisClusterNode node, String section) {
Assert.hasText(section, "Section must not be null nor empty!");
Assert.hasText(section, "Section must not be null or empty!");
return connection.execute(node, c -> c.info(section)) //
.map(LettuceConverters::toProperties).next();
@@ -190,7 +190,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<Properties> getConfig(String pattern) {
Assert.hasText(pattern, "Pattern must not be null nor empty!");
Assert.hasText(pattern, "Pattern must not be null or empty!");
return Flux.merge(executeOnAllNodes(node -> getConfig(node, pattern))) //
.collect(PropertiesCollector.INSTANCE);
@@ -203,7 +203,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<Properties> getConfig(RedisClusterNode node, String pattern) {
Assert.hasText(pattern, "Pattern must not be null nor empty!");
Assert.hasText(pattern, "Pattern must not be null or empty!");
return connection.execute(node, c -> c.configGet(pattern)) //
.map(LettuceConverters::toProperties) //
@@ -226,8 +226,8 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<String> setConfig(RedisClusterNode node, String param, String value) {
Assert.hasText(param, "Param must not be null nor empty!");
Assert.hasText(value, "Value must not be null nor empty!");
Assert.hasText(param, "Parameter must not be null or empty!");
Assert.hasText(value, "Value must not be null or empty!");
return connection.execute(node, c -> c.configSet(param, value)).next();
}

View File

@@ -90,7 +90,7 @@ class LettuceReactiveScriptingCommands implements ReactiveScriptingCommands {
@Override
public Flux<Boolean> scriptExists(List<String> scriptShas) {
Assert.notEmpty(scriptShas, "Script SHAs must not be empty!");
Assert.notEmpty(scriptShas, "Script digests must not be empty!");
return connection.execute(cmd -> cmd.scriptExists(scriptShas.toArray(new String[scriptShas.size()])));
}
@@ -123,7 +123,7 @@ class LettuceReactiveScriptingCommands implements ReactiveScriptingCommands {
@Override
public <T> Flux<T> evalSha(String scriptSha, ReturnType returnType, int numKeys, ByteBuffer... keysAndArgs) {
Assert.notNull(scriptSha, "Script SHA1 must not be null!");
Assert.notNull(scriptSha, "Script digest must not be null!");
Assert.notNull(returnType, "ReturnType must not be null!");
Assert.notNull(keysAndArgs, "Keys and args must not be null!");

View File

@@ -133,7 +133,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<Properties> info(String section) {
Assert.hasText(section, "Section must not be null nor empty!");
Assert.hasText(section, "Section must not be null or empty!");
return connection.execute(c -> c.info(section)) //
.map(LettuceConverters::toProperties) //
@@ -147,7 +147,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<Properties> getConfig(String pattern) {
Assert.hasText(pattern, "Pattern must not be null nor empty!");
Assert.hasText(pattern, "Pattern must not be null or empty!");
return connection.execute(c -> c.configGet(pattern)) //
.map(LettuceConverters::toProperties).next();
@@ -160,8 +160,8 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<String> setConfig(String param, String value) {
Assert.hasText(param, "Param must not be null nor empty!");
Assert.hasText(value, "Value must not be null nor empty!");
Assert.hasText(param, "Parameter must not be null or empty!");
Assert.hasText(value, "Value must not be null or empty!");
return connection.execute(c -> c.configSet(param, value)).next();
}
@@ -195,7 +195,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<String> killClient(String host, int port) {
Assert.notNull(host, "Host must not be null nor empty!");
Assert.notNull(host, "Host must not be null or empty!");
return connection.execute(c -> c.clientKill(String.format("%s:%s", host, port))).next();
}
@@ -207,7 +207,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<String> setClientName(String name) {
Assert.hasText(name, "Name must not be null nor empty!");
Assert.hasText(name, "Name must not be null or empty!");
return connection.execute(c -> c.clientSetname(ByteBuffer.wrap(LettuceConverters.toBytes(name)))).next();
}

View File

@@ -27,6 +27,7 @@ import org.springframework.data.redis.connection.RedisScriptingCommands;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceResult;
import org.springframework.data.redis.connection.lettuce.LettuceConnection.LettuceTxResult;
import org.springframework.util.Assert;
/**
* @author Mark Paluch
@@ -46,6 +47,7 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public void scriptFlush() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().scriptFlush()));
@@ -67,18 +69,16 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public void scriptKill() {
if (isQueueing()) {
throw new UnsupportedOperationException("Script kill not permitted in a transaction");
}
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().scriptKill()));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().scriptKill()));
return;
}
getConnection().scriptKill();
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
@@ -91,6 +91,9 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public String scriptLoad(byte[] script) {
Assert.notNull(script, "Script must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().scriptLoad(script)));
@@ -112,6 +115,10 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public List<Boolean> scriptExists(String... scriptSha1) {
Assert.notNull(scriptSha1, "Script digests must not be null!");
Assert.noNullElements(scriptSha1, "Script digests must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().scriptExists(scriptSha1)));
@@ -133,6 +140,9 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
Assert.notNull(script, "Script must not be null!");
try {
byte[][] keys = extractScriptKeys(numKeys, keysAndArgs);
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
@@ -162,6 +172,9 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public <T> T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
Assert.notNull(scriptSha1, "Script digest must not be null!");
try {
byte[][] keys = extractScriptKeys(numKeys, keysAndArgs);
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
@@ -191,6 +204,9 @@ class LettuceScriptingCommands implements RedisScriptingCommands {
*/
@Override
public <T> T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
Assert.notNull(scriptSha1, "Script digest must not be null!");
return evalSha(LettuceConverters.toString(scriptSha1), returnType, numKeys, keysAndArgs);
}

View File

@@ -17,6 +17,8 @@ package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Properties;
@@ -35,13 +37,10 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceServerCommands implements RedisServerCommands {
private final LettuceConnection connection;
LettuceServerCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -49,6 +48,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void bgReWriteAof() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().bgrewriteaof()));
@@ -70,6 +70,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void bgSave() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().bgsave()));
@@ -91,6 +92,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public Long lastSave() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().lastsave(), LettuceConverters.dateToLong()));
@@ -112,6 +114,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void save() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().save()));
@@ -133,6 +136,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public Long dbSize() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().dbsize()));
@@ -154,6 +158,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void flushDb() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().flushdb()));
@@ -175,6 +180,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void flushAll() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().flushall()));
@@ -196,6 +202,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public Properties info() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().info(), LettuceConverters.stringToProps()));
@@ -217,6 +224,9 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public Properties info(String section) {
Assert.hasText(section, "Section must not be null or empty!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().info(section), LettuceConverters.stringToProps()));
@@ -238,6 +248,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void shutdown() {
try {
if (isPipelined()) {
getAsyncConnection().shutdown(true);
@@ -278,19 +289,22 @@ class LettuceServerCommands implements RedisServerCommands {
* @see org.springframework.data.redis.connection.RedisServerCommands#getConfig(java.lang.String)
*/
@Override
public Properties getConfig(String param) {
public Properties getConfig(String pattern) {
Assert.hasText(pattern, "Pattern must not be null or empty!");
try {
if (isPipelined()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().configGet(param), Converters.mapToPropertiesConverter()));
pipeline(connection.newLettuceResult(getAsyncConnection().configGet(pattern),
Converters.mapToPropertiesConverter()));
return null;
}
if (isQueueing()) {
transaction(
connection.newLettuceTxResult(getConnection().configGet(param), Converters.mapToPropertiesConverter()));
connection.newLettuceTxResult(getConnection().configGet(pattern), Converters.mapToPropertiesConverter()));
return null;
}
return Converters.toProperties(getConnection().configGet(param));
return Converters.toProperties(getConnection().configGet(pattern));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -302,6 +316,10 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void setConfig(String param, String value) {
Assert.hasText(param, "Parameter must not be null or empty!");
Assert.hasText(value, "Value must not be null or empty!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().configSet(param, value)));
@@ -323,6 +341,7 @@ class LettuceServerCommands implements RedisServerCommands {
*/
@Override
public void resetConfigStats() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().configResetstat()));
@@ -346,7 +365,6 @@ class LettuceServerCommands implements RedisServerCommands {
public Long time() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().time(), LettuceConverters.toTimeConverter()));
return null;
@@ -355,7 +373,6 @@ class LettuceServerCommands implements RedisServerCommands {
transaction(connection.newLettuceTxResult(getConnection().time(), LettuceConverters.toTimeConverter()));
return null;
}
return LettuceConverters.toTimeConverter().convert(getConnection().time());
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
@@ -390,6 +407,8 @@ class LettuceServerCommands implements RedisServerCommands {
@Override
public void setClientName(byte[] name) {
Assert.notNull(name, "Name must not be null!");
if (isQueueing()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().clientSetname(name)));
return;
@@ -410,7 +429,6 @@ class LettuceServerCommands implements RedisServerCommands {
public String getClientName() {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().clientGetname(), LettuceConverters.bytesToString()));
return null;
@@ -419,7 +437,6 @@ class LettuceServerCommands implements RedisServerCommands {
transaction(connection.newLettuceTxResult(getConnection().clientGetname(), LettuceConverters.bytesToString()));
return null;
}
return LettuceConverters.toString(getConnection().clientGetname());
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
@@ -453,6 +470,7 @@ class LettuceServerCommands implements RedisServerCommands {
public void slaveOf(String host, int port) {
Assert.hasText(host, "Host must not be null for 'SLAVEOF' command.");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().slaveof(host, port)));
@@ -506,6 +524,9 @@ class LettuceServerCommands implements RedisServerCommands {
@Override
public void migrate(byte[] key, RedisNode target, int dbIndex, @Nullable MigrateOption option, long timeout) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(target, "Target node must not be null!");
try {
if (isPipelined()) {
pipeline(connection

View File

@@ -19,6 +19,8 @@ import io.lettuce.core.ScanArgs;
import io.lettuce.core.ValueScanCursor;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@@ -33,19 +35,17 @@ import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.KeyBoundCursor;
import org.springframework.data.redis.core.ScanIteration;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.util.Assert;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceSetCommands implements RedisSetCommands {
private final LettuceConnection connection;
LettuceSetCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -53,6 +53,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sAdd(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sadd(key, values)));
@@ -74,6 +79,9 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sCard(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().scard(key)));
@@ -95,6 +103,10 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sDiff(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sdiff(keys)));
@@ -116,6 +128,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sDiffStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sdiffstore(destKey, keys)));
@@ -137,6 +154,10 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sInter(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sinter(keys)));
@@ -158,6 +179,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sInterStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sinterstore(destKey, keys)));
@@ -179,6 +205,10 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Boolean sIsMember(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.newLettuceResult(getAsyncConnection().sismember(key, value)));
@@ -200,6 +230,9 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sMembers(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().smembers(key)));
@@ -221,6 +254,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) {
Assert.notNull(srcKey, "Source key must not be null!");
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().smove(srcKey, destKey, value)));
@@ -242,6 +280,9 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public byte[] sPop(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().spop(key)));
@@ -263,10 +304,12 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public List<byte[]> sPop(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().spop(key, count),
ArrayList::new));
pipeline(connection.newLettuceResult(getAsyncConnection().spop(key, count), ArrayList::new));
return null;
}
if (isQueueing()) {
@@ -286,6 +329,9 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public byte[] sRandMember(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().srandmember(key)));
@@ -307,6 +353,9 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public List<byte[]> sRandMember(byte[] key, long count) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().srandmember(key, count)));
@@ -329,6 +378,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sRem(byte[] key, byte[]... values) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().srem(key, values)));
@@ -350,6 +404,10 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Set<byte[]> sUnion(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sunion(keys)));
@@ -371,6 +429,11 @@ class LettuceSetCommands implements RedisSetCommands {
*/
@Override
public Long sUnionStore(byte[] destKey, byte[]... keys) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(keys, "Source keys must not be null!");
Assert.noNullElements(keys, "Source keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().sunionstore(destKey, keys)));
@@ -404,6 +467,8 @@ class LettuceSetCommands implements RedisSetCommands {
*/
public Cursor<byte[]> sScan(byte[] key, long cursorId, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new KeyBoundCursor<byte[]>(key, cursorId, options) {
@Override

View File

@@ -17,6 +17,8 @@ package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Map;
@@ -34,15 +36,20 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceStringCommands implements RedisStringCommands {
private final LettuceConnection connection;
LettuceStringCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#get(byte[])
*/
@Override
public byte[] get(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().get(key)));
@@ -58,7 +65,69 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getSet(byte[], byte[])
*/
@Override
public byte[] getSet(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.newLettuceResult(getAsyncConnection().getset(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().getset(key, value)));
return null;
}
return getConnection().getset(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mGet(byte[][])
*/
@Override
public List<byte[]> mGet(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
Assert.noNullElements(keys, "Keys must not contain null elements!");
try {
if (isPipelined()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().mget(keys), LettuceConverters.keyValueListUnwrapper()));
return null;
}
if (isQueueing()) {
transaction(
connection.newLettuceTxResult(getConnection().mget(keys), LettuceConverters.keyValueListUnwrapper()));
return null;
}
return LettuceConverters.<byte[], byte[]> keyValueListUnwrapper().convert(getConnection().mget(keys));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[])
*/
@Override
public void 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.newLettuceStatusResult(getAsyncConnection().set(key, value)));
@@ -81,6 +150,8 @@ class LettuceStringCommands implements RedisStringCommands {
@Override
public void 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!");
Assert.notNull(expiration, "Expiration must not be null!");
Assert.notNull(option, "Option must not be null!");
@@ -101,112 +172,66 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
public byte[] getSet(byte[] key, byte[] value) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setNX(byte[], byte[])
*/
@Override
public Boolean setNX(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.newLettuceResult(getAsyncConnection().getset(key, value)));
pipeline(connection.newLettuceResult(getAsyncConnection().setnx(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().getset(key, value)));
transaction(connection.newLettuceTxResult(getConnection().setnx(key, value)));
return null;
}
return getConnection().getset(key, value);
return getConnection().setnx(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long append(byte[] key, byte[] value) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setEx(byte[], long, byte[])
*/
@Override
public void setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().append(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().append(key, value)));
return null;
}
return getConnection().append(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public List<byte[]> mGet(byte[]... keys) {
try {
if (isPipelined()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().mget(keys), LettuceConverters.keyValueListUnwrapper()));
return null;
}
if (isQueueing()) {
transaction(
connection.newLettuceTxResult(getConnection().mget(keys), LettuceConverters.keyValueListUnwrapper()));
return null;
}
return LettuceConverters.<byte[], byte[]> keyValueListUnwrapper().convert(getConnection().mget(keys));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public void mSet(Map<byte[], byte[]> tuples) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().mset(tuples)));
pipeline(connection.newLettuceStatusResult(getAsyncConnection().setex(key, seconds, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().mset(tuples)));
transaction(connection.newLettuceTxStatusResult(getConnection().setex(key, seconds, value)));
return;
}
getConnection().mset(tuples);
getConnection().setex(key, seconds, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().msetnx(tuples)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().msetnx(tuples)));
return null;
}
return getConnection().msetnx(tuples);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public void setEx(byte[] key, long time, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().setex(key, time, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().setex(key, time, value)));
return;
}
getConnection().setex(key, time, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/**
* @since 1.3
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[])
*/
@Override
public void 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.newLettuceStatusResult(getAsyncConnection().psetex(key, milliseconds, value)));
@@ -222,71 +247,63 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
public Boolean setNX(byte[] key, byte[] value) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mSet(java.util.Map)
*/
@Override
public void mSet(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().setnx(key, value)));
return null;
pipeline(connection.newLettuceStatusResult(getAsyncConnection().mset(tuples)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().setnx(key, value)));
return null;
transaction(connection.newLettuceTxStatusResult(getConnection().mset(tuples)));
return;
}
return getConnection().setnx(key, value);
getConnection().mset(tuples);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public byte[] getRange(byte[] key, long start, long end) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#mSetNX(java.util.Map)
*/
@Override
public Boolean mSetNX(Map<byte[], byte[]> tuples) {
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().getrange(key, start, end)));
pipeline(connection.newLettuceResult(getAsyncConnection().msetnx(tuples)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().getrange(key, start, end)));
transaction(connection.newLettuceTxResult(getConnection().msetnx(tuples)));
return null;
}
return getConnection().getrange(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long decr(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().decr(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().decr(key)));
return null;
}
return getConnection().decr(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long decrBy(byte[] key, long value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().decrby(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().decrby(key, value)));
return null;
}
return getConnection().decrby(key, value);
return getConnection().msetnx(tuples);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incr(byte[])
*/
@Override
public Long incr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().incr(key)));
@@ -302,7 +319,15 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incrBy(byte[], long)
*/
@Override
public Long incrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().incrby(key, value)));
@@ -318,7 +343,15 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#incrBy(byte[], double)
*/
@Override
public Double incrBy(byte[] key, double value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().incrbyfloat(key, value)));
@@ -334,7 +367,137 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#decr(byte[])
*/
@Override
public Long decr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().decr(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().decr(key)));
return null;
}
return getConnection().decr(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#decrBy(byte[], long)
*/
@Override
public Long decrBy(byte[] key, long value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().decrby(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().decrby(key, value)));
return null;
}
return getConnection().decrby(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#append(byte[], byte[])
*/
@Override
public Long append(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.newLettuceResult(getAsyncConnection().append(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().append(key, value)));
return null;
}
return getConnection().append(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getRange(byte[], long, long)
*/
@Override
public byte[] getRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().getrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().getrange(key, start, end)));
return null;
}
return getConnection().getrange(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setRange(byte[], byte[], long)
*/
@Override
public void setRange(byte[] key, byte[] value, long offset) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().setrange(key, offset, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().setrange(key, offset, value)));
return;
}
getConnection().setrange(key, offset, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#getBit(byte[], long)
*/
@Override
public Boolean getBit(byte[] key, long offset) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(
@@ -352,7 +515,15 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#setBit(byte[], long, boolean)
*/
@Override
public Boolean setBit(byte[] key, long offset, boolean value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().setbit(key, offset, LettuceConverters.toInt(value)),
@@ -371,39 +542,15 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
public void setRange(byte[] key, byte[] value, long start) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceStatusResult(getAsyncConnection().setrange(key, start, value)));
return;
}
if (isQueueing()) {
transaction(connection.newLettuceTxStatusResult(getConnection().setrange(key, start, value)));
return;
}
getConnection().setrange(key, start, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long strLen(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().strlen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().strlen(key)));
return null;
}
return getConnection().strlen(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[])
*/
@Override
public Long bitCount(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().bitcount(key)));
@@ -419,23 +566,43 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
public Long bitCount(byte[] key, long begin, long end) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitCount(byte[], long, long)
*/
@Override
public Long bitCount(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().bitcount(key, begin, end)));
pipeline(connection.newLettuceResult(getAsyncConnection().bitcount(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().bitcount(key, begin, end)));
transaction(connection.newLettuceTxResult(getConnection().bitcount(key, start, end)));
return null;
}
return getConnection().bitcount(key, begin, end);
return getConnection().bitcount(key, start, end);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#bitOp(org.springframework.data.redis.connection.RedisStringCommands.BitOperation, byte[], byte[][])
*/
@Override
public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
Assert.notNull(op, "BitOperation must not be null!");
Assert.notNull(destination, "Destination key must not be null!");
if (op == BitOperation.NOT && keys.length > 1) {
throw new UnsupportedOperationException("Bitop NOT should only be performed against one key");
}
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(asyncBitOp(op, destination, keys)));
@@ -489,6 +656,30 @@ class LettuceStringCommands implements RedisStringCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#strLen(byte[])
*/
@Override
public Long strLen(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().strlen(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().strlen(key)));
return null;
}
return getConnection().strlen(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
private boolean isPipelined() {
return connection.isPipelined();
}

View File

@@ -21,6 +21,8 @@ import io.lettuce.core.ScoredValueScanCursor;
import io.lettuce.core.ZStoreArgs;
import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Set;
@@ -40,13 +42,10 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @since 2.0
*/
@RequiredArgsConstructor
class LettuceZSetCommands implements RedisZSetCommands {
private final LettuceConnection connection;
LettuceZSetCommands(LettuceConnection connection) {
this.connection = connection;
}
private final @NonNull LettuceConnection connection;
/*
* (non-Javadoc)
@@ -54,6 +53,10 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Boolean zAdd(byte[] key, double score, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zadd(key, score, value),
@@ -77,6 +80,10 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Long zAdd(byte[] key, Set<Tuple> tuples) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(tuples, "Tuples must not be null!");
try {
if (isPipelined()) {
pipeline(
@@ -96,44 +103,25 @@ class LettuceZSetCommands implements RedisZSetCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCard(byte[])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRem(byte[], byte[][])
*/
@Override
public Long zCard(byte[] key) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zcard(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zcard(key)));
return null;
}
return getConnection().zcard(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long zRem(byte[] key, byte[]... values) {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Long zCount(byte[] key, Range range) {
Assert.notNull(range, "Range for ZCOUNT must not be null!");
Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zcount(key, LettuceConverters.toRange(range))));
pipeline(connection.newLettuceResult(getAsyncConnection().zrem(key, values)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zcount(key, LettuceConverters.toRange(range))));
transaction(connection.newLettuceTxResult(getConnection().zrem(key, values)));
return null;
}
return getConnection().zcount(key, LettuceConverters.toRange(range));
return getConnection().zrem(key, values);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -145,6 +133,10 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zincrby(key, increment, value)));
@@ -162,23 +154,24 @@ class LettuceZSetCommands implements RedisZSetCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRank(byte[], byte[])
*/
@Override
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
public Long zRank(byte[] key, byte[] value) {
ZStoreArgs storeArgs = zStoreArgs(aggregate, weights);
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zinterstore(destKey, storeArgs, sets)));
pipeline(connection.newLettuceResult(getAsyncConnection().zrank(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zinterstore(destKey, storeArgs, sets)));
transaction(connection.newLettuceTxResult(getConnection().zrank(key, value)));
return null;
}
return getConnection().zinterstore(destKey, storeArgs, sets);
return getConnection().zrank(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -186,20 +179,23 @@ class LettuceZSetCommands implements RedisZSetCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], byte[][])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRank(byte[], byte[])
*/
@Override
public Long zInterStore(byte[] destKey, byte[]... sets) {
public Long zRevRank(byte[] key, byte[] value) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zinterstore(destKey, sets)));
pipeline(connection.newLettuceResult(getAsyncConnection().zrevrank(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zinterstore(destKey, sets)));
transaction(connection.newLettuceTxResult(getConnection().zrevrank(key, value)));
return null;
}
return getConnection().zinterstore(destKey, sets);
return getConnection().zrevrank(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -211,6 +207,9 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Set<byte[]> zRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrange(key, start, end),
@@ -234,6 +233,9 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrangeWithScores(key, start, end),
@@ -251,50 +253,6 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
Assert.notNull(limit, "Limit must not be null!");
try {
if (isPipelined()) {
if (limit.isUnlimited()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, LettuceConverters.toRange(range)),
LettuceConverters.bytesListToBytesSet()));
} else {
pipeline(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, LettuceConverters.toRange(range),
LettuceConverters.toLimit(limit)), LettuceConverters.bytesListToBytesSet()));
}
return null;
}
if (isQueueing()) {
if (limit.isUnlimited()) {
transaction(
connection.newLettuceTxResult(getConnection().zrangebyscore(key, LettuceConverters.toRange(range)),
LettuceConverters.bytesListToBytesSet()));
} else {
transaction(connection.newLettuceTxResult(
getConnection().zrangebyscore(key, LettuceConverters.toRange(range), LettuceConverters.toLimit(limit)),
LettuceConverters.bytesListToBytesSet()));
}
return null;
}
if (limit.isUnlimited()) {
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, LettuceConverters.toRange(range)));
}
return LettuceConverters.toBytesSet(
getConnection().zrangebyscore(key, LettuceConverters.toRange(range), LettuceConverters.toLimit(limit)));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
@@ -302,6 +260,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!");
Assert.notNull(limit, "Limit must not be null!");
@@ -341,12 +300,41 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRange(byte[], long, long)
*/
@Override
public Set<byte[]> zRevRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrevrange(key, start, end),
LettuceConverters.bytesListToBytesSet()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zrevrange(key, start, end),
LettuceConverters.bytesListToBytesSet()));
return null;
}
return LettuceConverters.toBytesSet(getConnection().zrevrange(key, start, end));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeWithScores(byte[], long, long)
*/
@Override
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrevrangeWithScores(key, start, end),
@@ -371,6 +359,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
Assert.notNull(limit, "Limit must not be null!");
@@ -416,6 +405,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYSCOREWITHSCORES must not be null!");
Assert.notNull(limit, "Limit must not be null!");
@@ -432,6 +422,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
return null;
}
if (isQueueing()) {
if (limit.isUnlimited()) {
transaction(connection.newLettuceTxResult(
@@ -457,20 +448,23 @@ class LettuceZSetCommands implements RedisZSetCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRank(byte[], byte[])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Long zRank(byte[] key, byte[] value) {
public Long zCount(byte[] key, Range range) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrank(key, value)));
pipeline(connection.newLettuceResult(getAsyncConnection().zcount(key, LettuceConverters.toRange(range))));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zrank(key, value)));
transaction(connection.newLettuceTxResult(getConnection().zcount(key, LettuceConverters.toRange(range))));
return null;
}
return getConnection().zrank(key, value);
return getConnection().zcount(key, LettuceConverters.toRange(range));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -478,20 +472,48 @@ class LettuceZSetCommands implements RedisZSetCommands {
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRem(byte[], byte[][])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCard(byte[])
*/
@Override
public Long zRem(byte[] key, byte[]... values) {
public Long zCard(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrem(key, values)));
pipeline(connection.newLettuceResult(getAsyncConnection().zcard(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zrem(key, values)));
transaction(connection.newLettuceTxResult(getConnection().zcard(key)));
return null;
}
return getConnection().zrem(key, values);
return getConnection().zcard(key);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScore(byte[], byte[])
*/
@Override
public Double zScore(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.newLettuceResult(getAsyncConnection().zscore(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zscore(key, value)));
return null;
}
return getConnection().zscore(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
@@ -503,6 +525,9 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Long zRemRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zremrangebyrank(key, start, end)));
@@ -525,6 +550,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREMRANGEBYSCORE must not be null!");
try {
@@ -544,77 +570,17 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRange(byte[], long, long)
*/
@Override
public Set<byte[]> zRevRange(byte[] key, long start, long end) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrevrange(key, start, end),
LettuceConverters.bytesListToBytesSet()));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zrevrange(key, start, end),
LettuceConverters.bytesListToBytesSet()));
return null;
}
return LettuceConverters.toBytesSet(getConnection().zrevrange(key, start, end));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRank(byte[], byte[])
*/
@Override
public Long zRevRank(byte[] key, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrevrank(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zrevrank(key, value)));
return null;
}
return getConnection().zrevrank(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScore(byte[], byte[])
*/
@Override
public Double zScore(byte[] key, byte[] value) {
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zscore(key, value)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zscore(key, value)));
return null;
}
return getConnection().zscore(key, value);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][])
*/
@Override
public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
ZStoreArgs storeArgs = zStoreArgs(aggregate, weights);
try {
@@ -638,6 +604,11 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
@Override
public Long zUnionStore(byte[] destKey, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zunionstore(destKey, sets)));
@@ -653,6 +624,60 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][])
*/
@Override
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
ZStoreArgs storeArgs = zStoreArgs(aggregate, weights);
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zinterstore(destKey, storeArgs, sets)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zinterstore(destKey, storeArgs, sets)));
return null;
}
return getConnection().zinterstore(destKey, storeArgs, sets);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], byte[][])
*/
@Override
public Long zInterStore(byte[] destKey, byte[]... sets) {
Assert.notNull(destKey, "Destination key must not be null!");
Assert.notNull(sets, "Source sets must not be null!");
Assert.noNullElements(sets, "Source sets must not contain null elements!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zinterstore(destKey, sets)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceTxResult(getConnection().zinterstore(destKey, sets)));
return null;
}
return getConnection().zinterstore(destKey, sets);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions)
@@ -671,6 +696,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
*/
public Cursor<Tuple> zScan(byte[] key, long cursorId, ScanOptions options) {
Assert.notNull(key, "Key must not be null!");
return new KeyBoundCursor<Tuple>(key, cursorId, options) {
@Override
@@ -692,6 +719,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
return new ScanIteration<>(Long.valueOf(nextCursorId), values);
}
@Override
protected void doClose() {
LettuceZSetCommands.this.connection.close();
}
@@ -706,6 +734,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, min, max),
@@ -730,6 +760,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, min, max, offset, count),
@@ -747,6 +779,51 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
Assert.notNull(limit, "Limit must not be null!");
try {
if (isPipelined()) {
if (limit.isUnlimited()) {
pipeline(
connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, LettuceConverters.toRange(range)),
LettuceConverters.bytesListToBytesSet()));
} else {
pipeline(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, LettuceConverters.toRange(range),
LettuceConverters.toLimit(limit)), LettuceConverters.bytesListToBytesSet()));
}
return null;
}
if (isQueueing()) {
if (limit.isUnlimited()) {
transaction(
connection.newLettuceTxResult(getConnection().zrangebyscore(key, LettuceConverters.toRange(range)),
LettuceConverters.bytesListToBytesSet()));
} else {
transaction(connection.newLettuceTxResult(
getConnection().zrangebyscore(key, LettuceConverters.toRange(range), LettuceConverters.toLimit(limit)),
LettuceConverters.bytesListToBytesSet()));
}
return null;
}
if (limit.isUnlimited()) {
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, LettuceConverters.toRange(range)));
}
return LettuceConverters.toBytesSet(
getConnection().zrangebyscore(key, LettuceConverters.toRange(range), LettuceConverters.toLimit(limit)));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
@@ -754,7 +831,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
Assert.notNull(range, "Range cannot be null for ZRANGEBYLEX.");
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
Assert.notNull(limit, "Limit must not be null!");
try {

View File

@@ -21,6 +21,7 @@ import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider.TargetAware;
@@ -29,23 +30,20 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionProvid
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class StandaloneConnectionProvider implements LettuceConnectionProvider, TargetAware {
private final RedisClient client;
private final RedisCodec<?, ?> codec;
StandaloneConnectionProvider(RedisClient client, RedisCodec<?, ?> codec) {
this.client = client;
this.codec = codec;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider#getConnection(java.lang.Class)
*/
@SuppressWarnings("null")
@Override
public <T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType) {
if (connectionType.equals(StatefulRedisSentinelConnection.class)) {
return connectionType.cast(client.connectSentinel());
}
@@ -65,6 +63,7 @@ class StandaloneConnectionProvider implements LettuceConnectionProvider, TargetA
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider.TargetAware#getConnection(java.lang.Class, io.lettuce.core.RedisURI)
*/
@SuppressWarnings("null")
@Override
public <T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType, RedisURI redisURI) {

View File

@@ -2,4 +2,5 @@
* Connection package for <a href="https://lettuce.io">Lettuce</a> Redis client.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.connection.lettuce;

View File

@@ -1,9 +1,9 @@
/**
* Connection package providing low-level abstractions for interacting with
* the various Redis 'drivers'/libraries.
*
* <p>Performs exception translation between the underlying library exceptions to Spring's DAO hierarchy.
* Connection package providing low-level abstractions for interacting with the various Redis 'drivers'/libraries.
* <p>
* Performs exception translation between the underlying library exceptions to Spring's DAO hierarchy.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.connection;

View File

@@ -2,5 +2,6 @@
* Internal utility package for encoding/decoding Strings to byte[] (using Base64) library.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
package org.springframework.data.redis.connection.util;

View File

@@ -60,6 +60,7 @@ abstract class AbstractOperations<K, V> {
return deserializeValue(result);
}
@Nullable
protected abstract byte[] inRedis(byte[] rawKey, RedisConnection connection);
}
@@ -286,7 +287,7 @@ abstract class AbstractOperations<K, V> {
@SuppressWarnings("unchecked")
<HK, HV> Map<HK, HV> deserializeHashMap(@Nullable Map<byte[], byte[]> entries) {
// connection in pipeline/multi mode
if (entries == null) {
return null;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 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
*
*
* http://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.
@@ -21,7 +21,7 @@ import org.springframework.lang.Nullable;
/**
* Value (or String in Redis terminology) operations bound to a certain key.
*
*
* @author Costin Leau
* @author Mark Paluch
*/
@@ -58,7 +58,7 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
/**
* Get the value of the bound key.
*
* @return {@literal null} when used in pipeline / transaction.ø
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/get">Redis Documentation: GET</a>
*/
@Nullable
@@ -67,7 +67,7 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
/**
* Set {@code value} of the bound key and return its old value.
*
* @return {@literal null} when used in pipeline / transaction.ø
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/getset">Redis Documentation: GETSET</a>
*/
@Nullable
@@ -108,6 +108,7 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
*
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/getrange">Redis Documentation: GETRANGE</a>
*/
@Nullable

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -44,26 +46,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveGeoOperations<K, V> implements ReactiveGeoOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Create new instance of {@link DefaultReactiveGeoOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveGeoOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/*
* (non-Javadoc)

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -38,26 +40,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations<H, HK, HV> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<H, ?> serializationContext;
/**
* Creates new instance of {@link DefaultReactiveHashOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveHashOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<H, ?> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<H, ?> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveHashOperations#delete(java.lang.Object, java.lang.Object[])

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -33,26 +35,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveHyperLogLogOperations<K, V> implements ReactiveHyperLogLogOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Creates new instance of {@link DefaultReactiveHyperLogLogOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveHyperLogLogOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveHyperLogLogOperations#add(java.lang.Object, java.lang.Object[])

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -39,26 +41,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveListOperations<K, V> implements ReactiveListOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Create new instance of {@link DefaultReactiveListOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveListOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveListOperations#range(java.lang.Object, long, long)

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -37,26 +39,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveSetOperations<K, V> implements ReactiveSetOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Creates new {@link DefaultReactiveSetOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveSetOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#add(java.lang.Object, java.lang.Object[])

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -41,26 +43,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Creates new {@link DefaultReactiveValueOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveValueOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveValueOperations#set(java.lang.Object, java.lang.Object)

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -43,26 +45,11 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @since 2.0
*/
@RequiredArgsConstructor
class DefaultReactiveZSetOperations<K, V> implements ReactiveZSetOperations<K, V> {
private final ReactiveRedisTemplate<?, ?> template;
private final RedisSerializationContext<K, V> serializationContext;
/**
* Creates new {@link DefaultReactiveZSetOperations}.
*
* @param template must not be {@literal null}.
* @param serializationContext must not be {@literal null}.
*/
DefaultReactiveZSetOperations(ReactiveRedisTemplate<?, ?> template,
RedisSerializationContext<K, V> serializationContext) {
Assert.notNull(template, "ReactiveRedisTemplate must not be null!");
Assert.notNull(serializationContext, "RedisSerializationContext must not be null!");
this.template = template;
this.serializationContext = serializationContext;
}
private final @NonNull ReactiveRedisTemplate<?, ?> template;
private final @NonNull RedisSerializationContext<K, V> serializationContext;
/* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveZSetOperations#add(java.lang.Object, java.lang.Object, double)

View File

@@ -153,7 +153,7 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
*/
@Override
public Set<V> rangeByLex(K key, Range range) {
return rangeByLex(key, range, null);
return rangeByLex(key, range, Limit.unlimited());
}
/*

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 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
*
*
* http://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.
@@ -19,7 +19,7 @@ import java.beans.PropertyEditorSupport;
/**
* PropertyEditor allowing for easy injection of {@link HashOperations} from {@link RedisOperations}.
*
*
* @author Costin Leau
*/
class HashOperationsEditor extends PropertyEditorSupport {
@@ -28,7 +28,7 @@ class HashOperationsEditor extends PropertyEditorSupport {
if (value instanceof RedisOperations) {
super.setValue(((RedisOperations) value).opsForHash());
} else {
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
@@ -23,32 +23,34 @@ public interface HyperLogLogOperations<K, V> {
/**
* Adds the given {@literal values} to the {@literal key}.
*
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return 1 of at least one of the values was added to the key; 0 otherwise.
* @return 1 of at least one of the values was added to the key; 0 otherwise. {@literal null} when used in pipeline /
* transaction.
*/
Long add(K key, V... values);
/**
* Gets the current number of elements within the {@literal key}.
*
*
* @param keys must not be {@literal null} or {@literal empty}.
* @return
* @return {@literal null} when used in pipeline / transaction.
*/
Long size(K... keys);
/**
* Merges all values of given {@literal sourceKeys} into {@literal destination} key.
*
*
* @param destination key of HyperLogLog to move source keys into.
* @param sourceKeys must not be {@literal null} or {@literal empty}.
* @return {@literal null} when used in pipeline / transaction.
*/
Long union(K destination, K... sourceKeys);
/**
* Removes the given {@literal key}.
*
*
* @param key must not be {@literal null}.
*/
void delete(K key);

View File

@@ -26,6 +26,7 @@ import org.springframework.data.redis.core.convert.RedisConverter;
import org.springframework.data.redis.core.convert.RemoveIndexedData;
import org.springframework.data.redis.core.convert.SimpleIndexedPropertyValue;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -87,11 +88,12 @@ class IndexWriter {
* @param key must not be {@literal null}.
* @param indexValues can be {@literal null}.
*/
public void deleteAndUpdateIndexes(Object key, Iterable<IndexedData> indexValues) {
public void deleteAndUpdateIndexes(Object key, @Nullable Iterable<IndexedData> indexValues) {
createOrUpdateIndexes(key, indexValues, IndexWriteMode.UPDATE);
}
private void createOrUpdateIndexes(Object key, Iterable<IndexedData> indexValues, IndexWriteMode writeMode) {
private void createOrUpdateIndexes(Object key, @Nullable Iterable<IndexedData> indexValues,
IndexWriteMode writeMode) {
Assert.notNull(key, "Key must not be null!");
if (indexValues == null) {
@@ -104,7 +106,7 @@ class IndexWriter {
if (indexValues.iterator().hasNext()) {
IndexedData data = indexValues.iterator().next();
if (data != null && data.getKeyspace() != null) {
if (data != null) {
removeKeyFromIndexes(data.getKeyspace(), binKey);
}
}
@@ -240,7 +242,7 @@ class IndexWriter {
}
}
private byte[] toBytes(Object source) {
private byte[] toBytes(@Nullable Object source) {
if (source == null) {
return new byte[] {};

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
* @param <T>
@@ -26,11 +28,11 @@ public abstract class KeyBoundCursor<T> extends ScanCursor<T> {
/**
* Crates new {@link ScanCursor}
*
*
* @param cursorId
* @param options Defaulted to {@link ScanOptions#NONE} if nulled.
*/
public KeyBoundCursor(byte[] key, long cursorId, ScanOptions options) {
public KeyBoundCursor(byte[] key, long cursorId, @Nullable ScanOptions options) {
super(cursorId, options != null ? options : ScanOptions.NONE);
this.key = key;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 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
*
*
* http://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.
@@ -19,9 +19,11 @@ import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.lang.Nullable;
/**
* Redis list specific operations.
*
*
* @author Costin Leau
* @author David Liu
* @author Thomas Darimont
@@ -36,9 +38,10 @@ public interface ListOperations<K, V> {
* @param key must not be {@literal null}.
* @param start
* @param end
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lrange">Redis Documentation: LRANGE</a>
*/
@Nullable
List<V> range(K key, long start, long end);
/**
@@ -55,9 +58,10 @@ public interface ListOperations<K, V> {
* Get the size of list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/llen">Redis Documentation: LLEN</a>
*/
@Nullable
Long size(K key);
/**
@@ -65,9 +69,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lpush">Redis Documentation: LPUSH</a>
*/
@Nullable
Long leftPush(K key, V value);
/**
@@ -75,9 +80,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param values
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lpush">Redis Documentation: LPUSH</a>
*/
@Nullable
Long leftPushAll(K key, V... values);
/**
@@ -85,10 +91,11 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return
* @return {@literal null} when used in pipeline / transaction.
* @since 1.5
* @see <a href="http://redis.io/commands/lpush">Redis Documentation: LPUSH</a>
*/
@Nullable
Long leftPushAll(K key, Collection<V> values);
/**
@@ -96,9 +103,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lpushx">Redis Documentation: LPUSHX</a>
*/
@Nullable
Long leftPushIfPresent(K key, V value);
/**
@@ -106,9 +114,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lpush">Redis Documentation: LPUSH</a>
*/
@Nullable
Long leftPush(K key, V pivot, V value);
/**
@@ -116,9 +125,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/rpush">Redis Documentation: RPUSH</a>
*/
@Nullable
Long rightPush(K key, V value);
/**
@@ -126,9 +136,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param values
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/rpush">Redis Documentation: RPUSH</a>
*/
@Nullable
Long rightPushAll(K key, V... values);
/**
@@ -136,10 +147,11 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param values
* @return
* @return {@literal null} when used in pipeline / transaction.
* @since 1.5
* @see <a href="http://redis.io/commands/rpush">Redis Documentation: RPUSH</a>
*/
@Nullable
Long rightPushAll(K key, Collection<V> values);
/**
@@ -147,9 +159,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/rpushx">Redis Documentation: RPUSHX</a>
*/
@Nullable
Long rightPushIfPresent(K key, V value);
/**
@@ -157,9 +170,10 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lpush">Redis Documentation: RPUSH</a>
*/
@Nullable
Long rightPush(K key, V pivot, V value);
/**
@@ -178,9 +192,10 @@ public interface ListOperations<K, V> {
* @param key must not be {@literal null}.
* @param count
* @param value
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lrem">Redis Documentation: LREM</a>
*/
@Nullable
Long remove(K key, long count, Object value);
/**
@@ -188,18 +203,20 @@ public interface ListOperations<K, V> {
*
* @param key must not be {@literal null}.
* @param index
* @return
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/lindex">Redis Documentation: LINDEX</a>
*/
@Nullable
V index(K key, long index);
/**
* Removes and returns first element in list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/lpop">Redis Documentation: LPOP</a>
*/
@Nullable
V leftPop(K key);
/**
@@ -209,18 +226,20 @@ public interface ListOperations<K, V> {
* @param key must not be {@literal null}.
* @param timeout
* @param unit must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/blpop">Redis Documentation: BLPOP</a>
*/
@Nullable
V leftPop(K key, long timeout, TimeUnit unit);
/**
* Removes and returns last element in list stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/rpop">Redis Documentation: RPOP</a>
*/
@Nullable
V rightPop(K key);
/**
@@ -230,9 +249,10 @@ public interface ListOperations<K, V> {
* @param key must not be {@literal null}.
* @param timeout
* @param unit must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/brpop">Redis Documentation: BRPOP</a>
*/
@Nullable
V rightPop(K key, long timeout, TimeUnit unit);
/**
@@ -240,9 +260,10 @@ public interface ListOperations<K, V> {
*
* @param sourceKey must not be {@literal null}.
* @param destinationKey must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/rpoplpush">Redis Documentation: RPOPLPUSH</a>
*/
@Nullable
V rightPopAndLeftPush(K sourceKey, K destinationKey);
/**
@@ -253,9 +274,10 @@ public interface ListOperations<K, V> {
* @param destinationKey must not be {@literal null}.
* @param timeout
* @param unit must not be {@literal null}.
* @return
* @return can be {@literal null}.
* @see <a href="http://redis.io/commands/brpoplpush">Redis Documentation: BRPOPLPUSH</a>
*/
@Nullable
V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit);
RedisOperations<K, V> getOperations();

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 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
*
*
* http://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.
@@ -19,7 +19,7 @@ import java.beans.PropertyEditorSupport;
/**
* PropertyEditor allowing for easy injection of {@link ListOperations} from {@link RedisOperations}.
*
*
* @author Costin Leau
*/
class ListOperationsEditor extends PropertyEditorSupport {
@@ -28,7 +28,7 @@ class ListOperationsEditor extends PropertyEditorSupport {
if (value instanceof RedisOperations) {
super.setValue(((RedisOperations) value).opsForList());
} else {
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
}
}
}

Some files were not shown because too many files have changed in this diff Show More