DATAREDIS-567 - Remove Support for SRP and JRedis.

This commit is contained in:
Christoph Strobl
2016-06-23 08:48:56 +02:00
committed by Mark Paluch
parent 186b6dd457
commit f6411b3811
53 changed files with 89 additions and 9335 deletions

23
pom.xml
View File

@@ -23,8 +23,6 @@
<pool>2.2</pool>
<lettuce>4.2.2.Final</lettuce>
<jedis>2.9.0</jedis>
<srp>0.7</srp>
<jredis>06052013</jredis>
<multithreadedtc>1.01</multithreadedtc>
</properties>
@@ -85,27 +83,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jredis</groupId>
<artifactId>jredis-core-api</artifactId>
<version>${jredis}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jredis</groupId>
<artifactId>jredis-core-ri</artifactId>
<version>${jredis}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.spullara.redis</groupId>
<artifactId>client</artifactId>
<version>${srp}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>

View File

@@ -48,7 +48,7 @@ public class RedisTxContextConfiguration {
}
@Bean
public RedisConnectionFactory redisConnectionFactory( // jedis, lettuce, srp,... );
public RedisConnectionFactory redisConnectionFactory( // jedis || lettuce);
@Bean
public DataSource dataSource() throws SQLException { // ... }

View File

@@ -12,7 +12,7 @@ Spring Data Redis provides easy configuration and access to Redis from Spring ap
[[redis:requirements]]
== Redis Requirements
Spring Redis requires Redis 2.6 or above and Java SE 6.0 or above . In terms of language bindings (or connectors), Spring Redis integrates with http://github.com/xetorthio/jedis[Jedis], http://github.com/alphazero/jredis[JRedis] (Deprecated since 1.7), http://github.com/spullara/redis-protocol[SRP] (Deprecated since 1.7) and http://github.com/wg/lettuce[Lettuce], four popular open source Java libraries for Redis. If you are aware of any other connector that we should be integrating with please send us feedback.
Spring Redis requires Redis 2.6 or above and Java SE 6.0 or above . In terms of language bindings (or connectors), Spring Redis integrates with http://github.com/xetorthio/jedis[Jedis] and http://github.com/mp911de/lettuce[Lettuce], four popular open source Java libraries for Redis. If you are aware of any other connector that we should be integrating with please send us feedback.
[[redis:architecture]]
== Redis Support High Level View
@@ -75,69 +75,6 @@ For production use however, one might want to tweak the settings such as the hos
</beans>
----
[[redis:connectors:jredis]]
=== Configuring JRedis connector (Deprecated since 1.7)
http://github.com/alphazero/jredis[JRedis] is another popular, open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.jredis` package.
A typical JRedis configuration can looks like this:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jredisConnectionFactory" class="org.springframework.data.redis.connection.jredis.JredisConnectionFactory" p:host-name="server" p:port="6379"/>
</beans>
----
The configuration is quite similar to Jedis, with one notable exception. By default, the `JedisConnectionFactory` pools connections. In order to use a connection pool with JRedis, configure the `JredisConnectionFactory` with an instance of `JredisPool`. For example:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jredisConnectionFactory" class="org.springframework.data.redis.connection.jredis.JredisConnectionFactory">
<constructor-arg>
<bean class="org.springframework.data.redis.connection.jredis.DefaultJredisPool">
<constructor-arg value="localhost" />
<constructor-arg value="6379" />
</bean>
</constructor-arg>
</bean>
</beans>
----
[[redis:connectors:srp]]
=== Configuring SRP connector (Deprecated since 1.7)
https://github.com/spullara/redis-protocol[SRP] (an acronym for Sam's Redis Protocol) is the third open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.srp` package.
By now, its configuration is probably easy to guess:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="srpConnectionFactory" class="org.springframework.data.redis.connection.srp.SrpConnectionFactory" p:host-name="server" p:port="6379"/>
</beans>
----
Needless to say, the configuration is quite similar to that of the other connectors.
[[redis:connectors:lettuce]]
=== Configuring Lettuce connector

View File

@@ -16,9 +16,7 @@
package org.springframework.data.redis.connection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* Utilities for examining a {@link RedisConnection}
@@ -29,16 +27,7 @@ import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
public abstract class ConnectionUtils {
public static boolean isAsync(RedisConnectionFactory connectionFactory) {
return (connectionFactory instanceof LettuceConnectionFactory)
|| (connectionFactory instanceof SrpConnectionFactory);
}
public static boolean isSrp(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof SrpConnectionFactory;
}
public static boolean isJredis(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof JredisConnectionFactory;
return (connectionFactory instanceof LettuceConnectionFactory);
}
public static boolean isLettuce(RedisConnectionFactory connectionFactory) {

View File

@@ -1,222 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import org.jredis.ClientRuntimeException;
import org.jredis.JRedis;
import org.jredis.connector.Connection;
import org.jredis.connector.Connection.Socket.Property;
import org.jredis.connector.ConnectionSpec;
import org.jredis.ri.alphazero.JRedisClient;
import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.Pool;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Connection factory using creating <a href="http://github.com/alphazero/jredis">JRedis</a> based connections.
*
* @author Costin Leau
* @author Jennifer Hickey
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
public class JredisConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
private ConnectionSpec connectionSpec;
private String hostName = "localhost";
private int port = DEFAULT_REDIS_PORT;
private String password = null;
private int timeout;
private int dbIndex = DEFAULT_REDIS_DB;
private Pool<JRedis> pool;
private static final int DEFAULT_REDIS_PORT = 6379;
private static final int DEFAULT_REDIS_DB = 0;
private static final byte[] DEFAULT_REDIS_PASSWORD = null;
/**
* Constructs a new <code>JredisConnectionFactory</code> instance.
*/
public JredisConnectionFactory() {}
/**
* Constructs a new <code>JredisConnectionFactory</code> instance. Will override the other connection parameters
* passed to the factory.
*
* @param connectionSpec already configured connection.
*/
public JredisConnectionFactory(ConnectionSpec connectionSpec) {
this.connectionSpec = connectionSpec;
}
public JredisConnectionFactory(Pool<JRedis> pool) {
this.pool = pool;
}
public void afterPropertiesSet() {
if (connectionSpec == null && pool == null) {
Assert.hasText(hostName);
connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, dbIndex, DEFAULT_REDIS_PASSWORD);
connectionSpec.setConnectionFlag(Connection.Flag.RELIABLE, false);
if (StringUtils.hasLength(password)) {
connectionSpec.setCredentials(password);
}
if (timeout > 0) {
connectionSpec.setSocketProperty(Property.SO_TIMEOUT, timeout);
}
}
}
public void destroy() throws Exception {
if (pool != null) {
pool.destroy();
pool = null;
}
}
public RedisConnection getConnection() {
JredisConnection connection;
if (pool != null) {
connection = new JredisConnection(pool.getResource(), pool);
} else {
connection = new JredisConnection(new JRedisClient(connectionSpec), null);
}
return postProcessConnection(connection);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getClusterConnection()
*/
@Override
public RedisClusterConnection getClusterConnection() {
throw new UnsupportedOperationException("Jredis does not support Redis Cluster.");
}
/**
* Post process a newly retrieved connection. Useful for decorating or executing initialization commands on a new
* connection. This implementation simply returns the connection.
*
* @param connection
* @return processed connection
*/
protected RedisConnection postProcessConnection(JredisConnection connection) {
return connection;
}
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof ClientRuntimeException) {
return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex);
}
return null;
}
/**
* Returns the Redis host name of this factory.
*
* @return Returns the hostName
*/
public String getHostName() {
return hostName;
}
/**
* Sets the Redis host name for this factory.
*
* @param hostName The hostName to set.
*/
public void setHostName(String hostName) {
this.hostName = hostName;
}
/**
* Returns the Redis port.
*
* @return Returns the port
*/
public int getPort() {
return port;
}
/**
* Sets the Redis port.
*
* @param port The port to set.
*/
public void setPort(int port) {
this.port = port;
}
/**
* Returns the password used for authenticating with the Redis server.
*
* @return password for authentication
*/
public String getPassword() {
return password;
}
/**
* Sets the password used for authenticating with the Redis server.
*
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the index of the database.
*
* @return Returns the database index
*/
public int getDatabase() {
return dbIndex;
}
/**
* Sets the index of the database used by this connection factory. Can be between 0 (default) and 15.
*
* @param index database index
*/
public void setDatabase(int index) {
Assert.isTrue(index >= 0, "invalid DB index (a positive index required)");
this.dbIndex = index;
}
/**
* {@link JredisConnection} does not support pipeline or transactions
*/
public boolean getConvertPipelineAndTxResults() {
return false;
}
@Override
public RedisSentinelConnection getSentinelConnection() {
throw new UnsupportedOperationException();
}
}

View File

@@ -1,190 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.jredis.JRedis;
import org.jredis.connector.Connection;
import org.jredis.connector.Connection.Socket.Property;
import org.jredis.connector.ConnectionSpec;
import org.jredis.ri.alphazero.JRedisClient;
import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
import org.springframework.data.redis.connection.Pool;
import org.springframework.data.redis.connection.PoolException;
import org.springframework.util.StringUtils;
/**
* JRedis implementation of {@link Pool}
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
public class JredisPool implements Pool<JRedis> {
private final GenericObjectPool<JRedis> internalPool;
/**
* Uses the {@link Config} and {@link ConnectionSpec} defaults for configuring the connection pool
*
* @param hostName The Redis host
* @param port The Redis port
*/
public JredisPool(String hostName, int port) {
this(hostName, port, 0, null, 0, new GenericObjectPoolConfig());
}
/**
* Uses the {@link ConnectionSpec} defaults for configuring the connection pool
*
* @param hostName The Redis host
* @param port The Redis port
* @param poolConfig The pool {@link Config}
*/
public JredisPool(String hostName, int port, GenericObjectPoolConfig poolConfig) {
this(hostName, port, 0, null, 0, poolConfig);
}
/**
* Uses the {@link Config} defaults for configuring the connection pool
*
* @param connectionSpec The {@link ConnectionSpec} for connecting to Redis
*/
public JredisPool(ConnectionSpec connectionSpec) {
this.internalPool = new GenericObjectPool<JRedis>(new JredisFactory(connectionSpec), new GenericObjectPoolConfig());
}
/**
* @param connectionSpec The {@link ConnectionSpec} for connecting to Redis
* @param poolConfig The pool {@link Config}
*/
public JredisPool(ConnectionSpec connectionSpec, GenericObjectPoolConfig poolConfig) {
this.internalPool = new GenericObjectPool<JRedis>(new JredisFactory(connectionSpec), poolConfig);
}
/**
* Uses the {@link Config} defaults for configuring the connection pool
*
* @param hostName The Redis host
* @param port The Redis port
* @param dbIndex The index of the database all connections should use. The database will only be selected on initial
* creation of the pooled {@link JRedis} instances. Since calling select directly on {@link JRedis} is not
* supported, it is assumed that connections can be re-used without subsequent selects.
* @param password The password used for authenticating with the Redis server or null if no password required
* @param timeout The socket timeout or 0 to use the default socket timeout
*/
public JredisPool(String hostName, int port, int dbIndex, String password, int timeout) {
this(hostName, port, dbIndex, password, timeout, new GenericObjectPoolConfig());
}
/**
* @param hostName The Redis host
* @param port The Redis port
* @param dbIndex The index of the database all connections should use
* @param password The password used for authenticating with the Redis server or null if no password required
* @param timeout The socket timeout or 0 to use the default socket timeout
* @param poolConfig The pool {@link Config}
*/
public JredisPool(String hostName, int port, int dbIndex, String password, int timeout,
GenericObjectPoolConfig poolConfig) {
ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, dbIndex, null);
connectionSpec.setConnectionFlag(Connection.Flag.RELIABLE, false);
if (StringUtils.hasLength(password)) {
connectionSpec.setCredentials(password);
}
if (timeout > 0) {
connectionSpec.setSocketProperty(Property.SO_TIMEOUT, timeout);
}
this.internalPool = new GenericObjectPool<JRedis>(new JredisFactory(connectionSpec), poolConfig);
}
public JRedis getResource() {
try {
return internalPool.borrowObject();
} catch (Exception e) {
throw new PoolException("Could not get a resource from the pool", e);
}
}
public void returnBrokenResource(final JRedis resource) {
try {
internalPool.invalidateObject(resource);
} catch (Exception e) {
throw new PoolException("Could not invalidate the broken resource", e);
}
}
public void returnResource(final JRedis resource) {
try {
internalPool.returnObject(resource);
} catch (Exception e) {
throw new PoolException("Could not return the resource to the pool", e);
}
}
public void destroy() {
try {
internalPool.close();
} catch (Exception e) {
throw new PoolException("Could not destroy the pool", e);
}
}
private static class JredisFactory extends BasePooledObjectFactory<JRedis> {
private final ConnectionSpec connectionSpec;
public JredisFactory(ConnectionSpec connectionSpec) {
super();
this.connectionSpec = connectionSpec;
}
@Override
public void destroyObject(final PooledObject<JRedis> obj) throws Exception {
try {
obj.getObject().quit();
} catch (Exception e) {
// Errors may happen if returning a broken resource
}
}
@Override
public boolean validateObject(final PooledObject<JRedis> obj) {
try {
obj.getObject().ping();
return true;
} catch (Exception e) {
return false;
}
}
@Override
public JRedis create() throws Exception {
return new JRedisClient(connectionSpec);
}
@Override
public PooledObject<JRedis> wrap(JRedis obj) {
return new DefaultPooledObject<JRedis>(obj);
}
}
}

View File

@@ -1,131 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import java.util.Map;
import java.util.Properties;
import org.jredis.ClientRuntimeException;
import org.jredis.RedisException;
import org.jredis.RedisType;
import org.jredis.Sort;
import org.jredis.connector.NotConnectedException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.SortParameters.Range;
/**
* Helper class featuring methods for JRedis connection handling, providing support for exception translation.
*
* @author Costin Leau
* @author Jennifer Hickey
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
public abstract class JredisUtils {
/**
* Converts the given, native JRedis exception to Spring's DAO hierarchy.
*
* @param ex JRedis exception
* @return converted exception
*/
public static DataAccessException convertJredisAccessException(RedisException ex) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
/**
* Converts the given, native JRedis exception to Spring's DAO hierarchy.
*
* @param ex JRedis exception
* @return converted exception
*/
public static DataAccessException convertJredisAccessException(ClientRuntimeException ex) {
if (ex instanceof NotConnectedException) {
return new RedisConnectionFailureException(ex.getMessage(), ex);
}
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
static DataType convertDataType(RedisType type) {
switch (type) {
case NONE:
return DataType.NONE;
case string:
return DataType.STRING;
case list:
return DataType.LIST;
case set:
return DataType.SET;
// case zset:
// return DataType.ZSET;
case hash:
return DataType.HASH;
}
return null;
}
static Sort applySortingParams(Sort jredisSort, SortParameters params, byte[] storeKey) {
if (params != null) {
byte[] byPattern = params.getByPattern();
if (byPattern != null) {
jredisSort.BY(byPattern);
}
byte[][] getPattern = params.getGetPattern();
if (getPattern != null && getPattern.length > 0) {
for (byte[] bs : getPattern) {
jredisSort.GET(bs);
}
}
Range limit = params.getLimit();
if (limit != null) {
jredisSort.LIMIT(limit.getStart(), limit.getCount());
}
Order order = params.getOrder();
if (order != null && order.equals(Order.DESC)) {
jredisSort.DESC();
}
Boolean isAlpha = params.isAlphabetic();
if (isAlpha != null && isAlpha) {
jredisSort.ALPHA();
}
}
if (storeKey != null) {
jredisSort.STORE(storeKey);
}
return jredisSort;
}
static Properties info(Map<String, String> map) {
Properties info = new Properties();
info.putAll(map);
return info;
}
static Long toLong(Boolean source) {
return source ? 1l : 0l;
}
}

View File

@@ -1,6 +0,0 @@
/**
* Connection package for <a href="http://github.com/alphazero/jredis">JRedis</a> library.
* @deprecated since 1.7. Will be removed in subsequent version.
*/
package org.springframework.data.redis.connection.jredis;

View File

@@ -1,180 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ExceptionTranslationStrategy;
import org.springframework.data.redis.PassThroughExceptionTranslationStrategy;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConnection;
/**
* Connection factory creating <a href="http://github.com/spullara/redis-protocol">Redis Protocol</a> based connections.
*
* @author Costin Leau
* @author Thomas Darimont
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
public class SrpConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new PassThroughExceptionTranslationStrategy(
SrpConverters.exceptionConverter());
private String hostName = "localhost";
private int port = 6379;
private BlockingQueue<SrpConnection> trackedConnections = new ArrayBlockingQueue<SrpConnection>(50);
private boolean convertPipelineAndTxResults = true;
private String password;
/**
* Constructs a new <code>SRedisConnectionFactory</code> instance with default settings.
*/
public SrpConnectionFactory() {}
/**
* Constructs a new <code>SRedisConnectionFactory</code> instance with default settings.
*/
public SrpConnectionFactory(String host, int port) {
this.hostName = host;
this.port = port;
}
public void afterPropertiesSet() {}
public void destroy() {
SrpConnection con;
do {
con = trackedConnections.poll();
if (con != null && !con.isClosed()) {
try {
con.close();
} catch (Exception ex) {
// ignore
}
}
} while (con != null);
}
public RedisConnection getConnection() {
SrpConnection connection = password != null ? new SrpConnection(hostName, port, password, trackedConnections)
: new SrpConnection(hostName, port, trackedConnections);
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
return connection;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getClusterConnection()
*/
@Override
public RedisClusterConnection getClusterConnection() {
throw new UnsupportedOperationException("Srp does not support Redis Cluster.");
}
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return EXCEPTION_TRANSLATION.translate(ex);
}
/**
* Returns the current host.
*
* @return the host
*/
public String getHostName() {
return hostName;
}
/**
* Sets the host.
*
* @param host the host to set
*/
public void setHostName(String host) {
this.hostName = host;
}
/**
* Returns the current port.
*
* @return the port
*/
public int getPort() {
return port;
}
/**
* Sets the port.
*
* @param port the port to set
*/
public void setPort(int port) {
this.port = port;
}
/**
* Returns the password used for authenticating with the Redis server.
*
* @return password for authentication
*/
public String getPassword() {
return password;
}
/**
* Sets the password used for authenticating with the Redis server.
*
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Specifies if pipelined results should be converted to the expected data type. If false, results of
* {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} will be of the type returned by the SRP
* driver
*
* @return Whether or not to convert pipeline and tx results
*/
public boolean getConvertPipelineAndTxResults() {
return convertPipelineAndTxResults;
}
/**
* Specifies if pipelined results should be converted to the expected data type. If false, results of
* {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} will be of the type returned by the SRP
* driver
*
* @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results
*/
public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) {
this.convertPipelineAndTxResults = convertPipelineAndTxResults;
}
@Override
public RedisSentinelConnection getSentinelConnection() {
throw new UnsupportedOperationException();
}
}

View File

@@ -1,458 +0,0 @@
/*
* Copyright 2013-2015 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.convert.LongToBooleanConverter;
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import redis.client.RedisException;
import redis.reply.IntegerReply;
import redis.reply.Reply;
import com.google.common.base.Charsets;
/**
* SRP type converters
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Thomas Darimont
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
@SuppressWarnings("rawtypes")
abstract public class SrpConverters extends Converters {
private static final byte[] BEFORE = "BEFORE".getBytes(Charsets.UTF_8);
private static final byte[] AFTER = "AFTER".getBytes(Charsets.UTF_8);
private static final Converter<Reply[], List<byte[]>> REPLIES_TO_BYTES_LIST;
private static final Converter<Reply[], Set<byte[]>> REPLIES_TO_BYTES_SET;
private static final Converter<Reply[], Set<Tuple>> REPLIES_TO_TUPLE_SET;
private static final Converter<Reply[], Map<byte[], byte[]>> REPLIES_TO_BYTES_MAP;
private static final Converter<Reply[], List<Boolean>> REPLIES_TO_BOOLEAN_LIST;
private static final Converter<Reply[], List<String>> REPLIES_TO_STRING_LIST;
private static final Converter<Reply, String> REPLY_TO_STRING;
private static final Converter<byte[], Properties> BYTES_TO_PROPERTIES;
private static final Converter<byte[], String> BYTES_TO_STRING;
private static final Converter<byte[], Double> BYTES_TO_DOUBLE;
private static final Converter<Reply[], Long> REPLIES_TO_TIME_AS_LONG;
private static final Converter<Reply, List<RedisClientInfo>> REPLY_T0_LIST_OF_CLIENT_INFO;
private static final Converter<String[], List<RedisClientInfo>> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter();
private static final Converter<byte[], List<RedisClientInfo>> BYTEARRAY_T0_LIST_OF_CLIENT_INFO;
private static final Converter<IntegerReply, Boolean> INTEGER_REPLY_TO_BOOLEAN;
private static final Converter<Long, Boolean> LONG_TO_BOOLEAN = new LongToBooleanConverter();
private static final Converter<Exception, DataAccessException> EXCEPTION_CONVERTER;
static {
REPLIES_TO_BYTES_LIST = new Converter<Reply[], List<byte[]>>() {
public List<byte[]> convert(Reply[] replies) {
if (replies == null) {
return null;
}
List<byte[]> list = new ArrayList<byte[]>(replies.length);
for (Reply reply : replies) {
Object data = reply.data();
if (data == null) {
list.add(null);
} else if (data instanceof byte[])
list.add((byte[]) data);
else
throw new IllegalArgumentException("array contains more then just nulls and bytes -> " + data);
}
return list;
}
};
REPLIES_TO_BYTES_SET = new Converter<Reply[], Set<byte[]>>() {
public Set<byte[]> convert(Reply[] source) {
return source != null ? new LinkedHashSet<byte[]>(SrpConverters.toBytesList(source)) : null;
}
};
BYTES_TO_PROPERTIES = new Converter<byte[], Properties>() {
public Properties convert(byte[] source) {
return source != null ? SrpConverters.toProperties(new String(source, Charsets.UTF_8)) : null;
}
};
BYTES_TO_DOUBLE = new Converter<byte[], Double>() {
public Double convert(byte[] bytes) {
return (bytes == null || bytes.length == 0 ? null : Double.valueOf(new String(bytes, Charsets.UTF_8)));
}
};
REPLIES_TO_TIME_AS_LONG = new Converter<Reply[], Long>() {
@Override
public Long convert(Reply[] reply) {
Assert.notEmpty(reply, "Received invalid result from server. Expected 2 items in collection.");
Assert.isTrue(reply.length == 2, "Received invalid nr of arguments from redis server. Expected 2 received "
+ reply.length);
List<String> serverTimeInformation = REPLIES_TO_STRING_LIST.convert(reply);
return Converters.toTimeMillis(serverTimeInformation.get(0), serverTimeInformation.get(1));
}
};
REPLIES_TO_TUPLE_SET = new Converter<Reply[], Set<Tuple>>() {
public Set<Tuple> convert(Reply[] byteArrays) {
if (byteArrays == null) {
return null;
}
Set<Tuple> tuples = new LinkedHashSet<Tuple>(byteArrays.length / 2 + 1);
for (int i = 0; i < byteArrays.length; i++) {
byte[] value = (byte[]) byteArrays[i].data();
i++;
Double score = SrpConverters.toDouble((byte[]) byteArrays[i].data());
tuples.add(new DefaultTuple(value, score));
}
return tuples;
}
};
REPLIES_TO_BYTES_MAP = new Converter<Reply[], Map<byte[], byte[]>>() {
public Map<byte[], byte[]> convert(Reply[] byteArrays) {
if (byteArrays == null) {
return null;
}
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>(byteArrays.length / 2);
for (int i = 0; i < byteArrays.length; i++) {
map.put((byte[]) byteArrays[i++].data(), (byte[]) byteArrays[i].data());
}
return map;
}
};
BYTES_TO_STRING = new Converter<byte[], String>() {
public String convert(byte[] data) {
return data != null ? new String((byte[]) data, Charsets.UTF_8) : null;
}
};
REPLIES_TO_BOOLEAN_LIST = new Converter<Reply[], List<Boolean>>() {
public List<Boolean> convert(Reply[] source) {
if (source == null) {
return null;
}
List<Boolean> results = new ArrayList<Boolean>();
for (Reply r : source) {
results.add(SrpConverters.toBoolean(((IntegerReply) r).data()));
}
return results;
}
};
REPLIES_TO_STRING_LIST = new Converter<Reply[], List<String>>() {
public List<String> convert(Reply[] source) {
if (source == null) {
return null;
}
List<String> results = new ArrayList<String>();
for (Reply r : source) {
results.add(SrpConverters.toString((byte[]) r.data()));
}
return results;
}
};
REPLY_TO_STRING = new Converter<Reply, String>() {
@Override
public String convert(Reply source) {
if (source == null) {
return null;
}
return SrpConverters.toString((byte[]) source.data());
}
};
REPLY_T0_LIST_OF_CLIENT_INFO = new Converter<Reply, List<RedisClientInfo>>() {
@Override
public List<RedisClientInfo> convert(Reply source) {
if (source == null || source.data() == null) {
return Collections.emptyList();
}
Assert.isInstanceOf(byte[].class, source.data(), "Expected data to be an instace of byte [].");
return BYTEARRAY_T0_LIST_OF_CLIENT_INFO.convert((byte[]) source.data());
}
};
BYTEARRAY_T0_LIST_OF_CLIENT_INFO = new Converter<byte[], List<RedisClientInfo>>() {
@Override
public List<RedisClientInfo> convert(byte[] source) {
if (source == null || source.length == 0) {
return Collections.emptyList();
}
String s = SrpConverters.toString(source);
return STRING_TO_LIST_OF_CLIENT_INFO.convert(s.split("\\r?\\n"));
}
};
INTEGER_REPLY_TO_BOOLEAN = new Converter<IntegerReply, Boolean>() {
@Override
public Boolean convert(IntegerReply source) {
if (source == null || source.data() == null) {
return false;
}
return source.data() == 1;
}
};
EXCEPTION_CONVERTER = new Converter<Exception, DataAccessException>() {
@Override
public DataAccessException convert(Exception ex) {
if (ex instanceof RedisException) {
return new RedisSystemException("redis exception", ex);
}
if (ex instanceof IOException) {
return new RedisConnectionFailureException("Redis connection failed", (IOException) ex);
}
return null;
}
};
}
public static Converter<Reply[], List<byte[]>> repliesToBytesList() {
return REPLIES_TO_BYTES_LIST;
}
public static Converter<Reply[], Set<byte[]>> repliesToBytesSet() {
return REPLIES_TO_BYTES_SET;
}
public static Converter<byte[], Properties> bytesToProperties() {
return BYTES_TO_PROPERTIES;
}
public static Converter<byte[], Double> bytesToDouble() {
return BYTES_TO_DOUBLE;
}
public static Converter<Reply[], Set<Tuple>> repliesToTupleSet() {
return REPLIES_TO_TUPLE_SET;
}
public static Converter<Reply[], Map<byte[], byte[]>> repliesToBytesMap() {
return REPLIES_TO_BYTES_MAP;
}
public static Converter<byte[], String> bytesToString() {
return BYTES_TO_STRING;
}
public static Converter<Reply, String> replyToString() {
return REPLY_TO_STRING;
}
public static Converter<Reply[], List<Boolean>> repliesToBooleanList() {
return REPLIES_TO_BOOLEAN_LIST;
}
public static Converter<Reply[], List<String>> repliesToStringList() {
return REPLIES_TO_STRING_LIST;
}
public static Converter<Reply[], Long> repliesToTimeAsLong() {
return REPLIES_TO_TIME_AS_LONG;
}
/**
* @return
* @since 1.3
*/
public static List<RedisClientInfo> toListOfRedisClientInformation(Reply reply) {
return REPLY_T0_LIST_OF_CLIENT_INFO.convert(reply);
}
/**
* @return
* @since 1.3
*/
public static Converter<Long, Boolean> longToBooleanConverter() {
return LONG_TO_BOOLEAN;
}
public static List<byte[]> toBytesList(Reply[] source) {
return REPLIES_TO_BYTES_LIST.convert(source);
}
public static Set<byte[]> toBytesSet(Reply[] source) {
return REPLIES_TO_BYTES_SET.convert(source);
}
public static Properties toProperties(byte[] source) {
return BYTES_TO_PROPERTIES.convert(source);
}
public static Double toDouble(byte[] source) {
return BYTES_TO_DOUBLE.convert(source);
}
public static Set<Tuple> toTupleSet(Reply[] source) {
return REPLIES_TO_TUPLE_SET.convert(source);
}
public static Map<byte[], byte[]> toBytesMap(Reply[] source) {
return REPLIES_TO_BYTES_MAP.convert(source);
}
public static String toString(Reply source) {
return REPLY_TO_STRING.convert(source);
}
public static String toString(byte[] source) {
return BYTES_TO_STRING.convert(source);
}
public static List<Boolean> toBooleanList(Reply[] source) {
return REPLIES_TO_BOOLEAN_LIST.convert(source);
}
public static List<String> toStringList(Reply[] source) {
return REPLIES_TO_STRING_LIST.convert(source);
}
/**
* Converts given {@link Reply}s to {@link Long}.
*
* @param source Array holding time values in seconds and microseconds.
* @return
*/
public static Long toTimeAsLong(Reply[] source) {
return REPLIES_TO_TIME_AS_LONG.convert(source);
}
public static byte[] toBytes(BitOperation op) {
Assert.notNull(op, "The bit operation is required");
return op.name().toUpperCase().getBytes(Charsets.UTF_8);
}
public static byte[][] toByteArrays(Map<byte[], byte[]> source) {
byte[][] result = new byte[source.size() * 2][];
int index = 0;
for (Map.Entry<byte[], byte[]> entry : source.entrySet()) {
result[index++] = entry.getKey();
result[index++] = entry.getValue();
}
return result;
}
public static byte[] toBytes(Position source) {
Assert.notNull("list positions are mandatory");
return (Position.AFTER.equals(source) ? AFTER : BEFORE);
}
public static List<String> toStringList(String source) {
return Collections.singletonList(source);
}
/**
* @since 1.3
* @return
*/
public static Converter<byte[], List<RedisClientInfo>> replyToListOfRedisClientInfo() {
return BYTEARRAY_T0_LIST_OF_CLIENT_INFO;
}
/**
* Convert an {@link IntegerReply} to a {@link Boolean} by inspecting {@link IntegerReply#data()}.
*
* @since 1.3
* @param reply
* @return
*/
public static Boolean toBoolean(IntegerReply reply) {
return INTEGER_REPLY_TO_BOOLEAN.convert(reply);
}
public static Converter<Exception, DataAccessException> exceptionConverter() {
return EXCEPTION_CONVERTER;
}
/**
* Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite
* {@literal ZRANGEBYLEX}.
*
* @param boundary
* @param defaultValue
* @return
* @since 1.6
*/
public static byte[] boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return defaultValue;
}
return boundaryToBytes(boundary, new byte[] {}, "(".getBytes(Charsets.UTF_8));
}
public static byte[] toBytes(String source) {
return source.getBytes(Charsets.UTF_8);
}
private static byte[] boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) {
byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix;
byte[] value = null;
if (boundary.getValue() instanceof byte[]) {
value = (byte[]) boundary.getValue();
} else {
value = toBytes(boundary.getValue().toString());
}
ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length);
buffer.put(prefix);
buffer.put(value);
return buffer.array();
}
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.springframework.data.redis.connection.DefaultMessage;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.util.Assert;
import redis.client.ReplyListener;
/**
* MessageListener wrapper around SRP {@link ReplyListener}.
*
* @author Costin Leau
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
class SrpMessageListener implements ReplyListener {
private final MessageListener listener;
SrpMessageListener(MessageListener listener) {
Assert.notNull(listener, "message listener is required");
this.listener = listener;
}
public void message(byte[] channel, byte[] message) {
listener.onMessage(new DefaultMessage(channel, message), null);
}
public void pmessage(byte[] pattern, byte[] channel, byte[] message) {
listener.onMessage(new DefaultMessage(channel, message), pattern);
}
public void psubscribed(byte[] arg0, int arg1) {}
public void punsubscribed(byte[] arg0, int arg1) {}
public void subscribed(byte[] arg0, int arg1) {}
public void unsubscribed(byte[] arg0, int arg1) {}
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2013-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.util.ArrayList;
import java.util.List;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.redis.connection.ReturnType;
import redis.reply.Reply;
/**
* Converts the value returned by SRP script eval to the expected {@link ReturnType}
*
* @author Jennifer Hickey
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
public class SrpScriptReturnConverter implements Converter<Object, Object> {
private ReturnType returnType;
public SrpScriptReturnConverter(ReturnType returnType) {
this.returnType = returnType;
}
public Object convert(Object source) {
if (returnType == ReturnType.MULTI) {
Reply<?>[] replies = (Reply[]) source;
List<Object> results = new ArrayList<Object>();
for (Reply<?> reply : replies) {
results.add(reply.data());
}
return results;
}
if (returnType == ReturnType.BOOLEAN) {
// Lua false comes back as a null bulk reply
if (source == null) {
return Boolean.FALSE;
}
return ((Long) source == 1);
}
return source;
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.util.AbstractSubscription;
import redis.client.RedisClient;
import redis.client.ReplyListener;
/**
* Message subscription on top of SRP.
*
* @author Costin Leau
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
class SrpSubscription extends AbstractSubscription {
private final RedisClient client;
private final ReplyListener listener;
SrpSubscription(MessageListener listener, RedisClient client) {
super(listener);
this.client = client;
this.listener = new SrpMessageListener(listener);
client.addListener(this.listener);
}
protected void doClose() {
if (!getChannels().isEmpty()) {
client.unsubscribe((Object[]) null);
}
if (!getPatterns().isEmpty()) {
client.punsubscribe((Object[]) null);
}
client.removeListener(this.listener);
}
protected void doPsubscribe(byte[]... patterns) {
client.psubscribe((Object[]) patterns);
}
protected void doPUnsubscribe(boolean all, byte[]... patterns) {
if (all) {
client.punsubscribe((Object[]) null);
} else {
client.punsubscribe((Object[]) patterns);
}
}
protected void doSubscribe(byte[]... channels) {
client.subscribe((Object[]) channels);
}
protected void doUnsubscribe(boolean all, byte[]... channels) {
if (all) {
client.unsubscribe((Object[]) null);
} else {
client.unsubscribe((Object[]) channels);
}
}
}

View File

@@ -1,334 +0,0 @@
/*
* Copyright 2011-2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import com.google.common.base.Charsets;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.util.Assert;
import redis.client.RedisException;
import redis.reply.BulkReply;
import redis.reply.IntegerReply;
import redis.reply.MultiBulkReply;
import redis.reply.Reply;
import redis.reply.StatusReply;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Helper class featuring methods for SRedis connection handling, providing support for exception translation.
* Deprecated. Use {@link SrpConverters} instead.
*
* @author Costin Leau
* @author Jennifer Hickey
* @deprecated since 1.7. Will be removed in subsequent version.
*/
@Deprecated
abstract class SrpUtils {
private static final byte[] ONE = new byte[] { '1' };
private static final byte[] ZERO = new byte[] { '0' };
private static final byte[] BEFORE = "BEFORE".getBytes(Charsets.UTF_8);
private static final byte[] AFTER = "AFTER".getBytes(Charsets.UTF_8);
static final byte[] WITHSCORES = "WITHSCORES".getBytes(Charsets.UTF_8);
private static final byte[] SPACE = " ".getBytes(Charsets.UTF_8);
private static final byte[] BY = "BY".getBytes(Charsets.UTF_8);
private static final byte[] GET = "GET".getBytes(Charsets.UTF_8);
private static final byte[] ALPHA = "ALPHA".getBytes(Charsets.UTF_8);
private static final byte[] STORE = "STORE".getBytes(Charsets.UTF_8);
static DataAccessException convertSRedisAccessException(RuntimeException ex) {
if (ex instanceof RedisException) {
return new RedisSystemException("redis exception", ex);
}
return null;
}
static Properties info(BulkReply reply) {
Properties info = new Properties();
// use the same charset as the library
StringReader stringReader = new StringReader(new String(reply.data(), Charsets.UTF_8));
try {
info.load(stringReader);
} catch (Exception ex) {
throw new RedisSystemException("Cannot read Redis info", ex);
} finally {
stringReader.close();
}
return info;
}
@SuppressWarnings("rawtypes")
static List<byte[]> toBytesList(Reply[] replies) {
if (replies == null) {
return null;
}
List<byte[]> list = new ArrayList<byte[]>(replies.length);
for (Reply reply : replies) {
Object data = reply.data();
if (data == null) {
list.add(null);
} else if (data instanceof byte[])
list.add((byte[]) data);
else
throw new IllegalArgumentException("array contains more then just nulls and bytes -> " + data);
}
return list;
}
static List<String> asStatusList(Reply[] replies) {
List<String> statuses = new ArrayList<String>();
for (Reply reply : replies) {
statuses.add(((StatusReply) reply).data());
}
return statuses;
}
static <T> List<T> toList(T[] byteArrays) {
return Arrays.asList(byteArrays);
}
@SuppressWarnings("rawtypes")
static Set<byte[]> toSet(Reply[] byteArrays) {
return new LinkedHashSet<byte[]>(toBytesList(byteArrays));
}
static byte[][] convert(Map<byte[], byte[]> hgetAll) {
byte[][] result = new byte[hgetAll.size() * 2][];
int index = 0;
for (Map.Entry<byte[], byte[]> entry : hgetAll.entrySet()) {
result[index++] = entry.getKey();
result[index++] = entry.getValue();
}
return result;
}
static byte[] asBit(boolean value) {
return (value ? ONE : ZERO);
}
static byte[] convertPosition(Position where) {
Assert.notNull("list positions are mandatory");
return (Position.AFTER.equals(where) ? AFTER : BEFORE);
}
static Double toDouble(byte[] bytes) {
return (bytes == null || bytes.length == 0 ? null : Double.valueOf(new String(bytes, Charsets.UTF_8)));
}
static Long toLong(Object[] bytes) {
return (bytes == null || bytes.length == 0 ? null : Long.valueOf(new String((byte[]) bytes[0], Charsets.UTF_8)));
}
static Set<Tuple> convertTuple(MultiBulkReply zrange) {
return convertTuple(zrange.data());
}
@SuppressWarnings("rawtypes")
static Set<Tuple> convertTuple(Reply[] byteArrays) {
Set<Tuple> tuples = new LinkedHashSet<Tuple>(byteArrays.length / 2 + 1);
for (int i = 0; i < byteArrays.length; i++) {
byte[] value = (byte[]) byteArrays[i].data();
i++;
Double score = toDouble((byte[]) byteArrays[i].data());
tuples.add(new DefaultTuple(value, score));
}
return tuples;
}
static Object[] convert(int timeout, byte[]... keys) {
int length = (keys != null ? keys.length + 1 : 1);
Object[] args = new Object[length];
if (keys != null) {
for (int i = 0; i < keys.length; i++) {
args[i] = keys[i];
}
}
args[length - 1] = String.valueOf(timeout).getBytes();
return args;
}
@SuppressWarnings("rawtypes")
static Map<byte[], byte[]> toMap(Reply[] byteArrays) {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>(byteArrays.length / 2);
for (int i = 0; i < byteArrays.length; i++) {
map.put((byte[]) byteArrays[i++].data(), (byte[]) byteArrays[i].data());
}
return map;
}
static Boolean asBoolean(IntegerReply reply) {
if (reply == null) {
return null;
}
return (Long.valueOf(1).equals(reply.data()));
}
static byte[] limit(long offset, long count) {
return ("LIMIT " + offset + " " + count).getBytes(Charsets.UTF_8);
}
static Object[] limitParams(long offset, long count) {
return new Object[] { "LIMIT".getBytes(Charsets.UTF_8), String.valueOf(offset).getBytes(Charsets.UTF_8),
String.valueOf(count).getBytes(Charsets.UTF_8) };
}
static byte[] sort(SortParameters params) {
return sort(params, null);
}
static byte[] sort(SortParameters params, byte[] sortKey) {
List<byte[]> arrays = new ArrayList<byte[]>();
Object[] sortParams = sortParams(params, sortKey);
for (Object param : sortParams) {
arrays.add((byte[]) param);
arrays.add(SPACE);
}
arrays.remove(arrays.size() - 1);
// concatenate array
int size = 0;
for (Object bs : arrays) {
size += ((byte[]) bs).length;
}
byte[] result = new byte[size];
int index = 0;
for (byte[] bs : arrays) {
System.arraycopy(bs, 0, result, index, bs.length);
index += bs.length;
}
return result;
}
static Object[] sortParams(SortParameters params) {
return sortParams(params, null);
}
static Object[] sortParams(SortParameters params, byte[] sortKey) {
List<byte[]> arrays = new ArrayList<byte[]>();
if (params != null) {
if (params.getByPattern() != null) {
arrays.add(BY);
arrays.add(params.getByPattern());
}
if (params.getLimit() != null) {
arrays.add(limit(params.getLimit().getStart(), params.getLimit().getCount()));
}
if (params.getGetPattern() != null) {
byte[][] pattern = params.getGetPattern();
for (byte[] bs : pattern) {
arrays.add(GET);
arrays.add(bs);
}
}
if (params.getOrder() != null) {
arrays.add(params.getOrder().name().getBytes(Charsets.UTF_8));
}
Boolean isAlpha = params.isAlphabetic();
if (isAlpha != null && isAlpha) {
arrays.add(ALPHA);
}
}
if (sortKey != null) {
arrays.add(STORE);
arrays.add(sortKey);
}
return arrays.toArray();
}
static byte[] bitOp(BitOperation op) {
Assert.notNull(op, "The bit operation is required");
return op.name().toUpperCase().getBytes(Charsets.UTF_8);
}
static String asShasum(Reply reply) {
Object data = reply.data();
return (data instanceof String ? (String) data : new String((byte[]) data, Charsets.UTF_8));
}
static List<Boolean> asBooleanList(Reply reply) {
if (!(reply instanceof MultiBulkReply)) {
throw new IllegalArgumentException();
}
List<Boolean> results = new ArrayList<Boolean>();
for (Reply r : ((MultiBulkReply) reply).data()) {
results.add(SrpUtils.asBoolean((IntegerReply) r));
}
return results;
}
static List<Long> asIntegerList(Reply[] replies) {
List<Long> results = new ArrayList<Long>();
for (Reply reply : replies) {
results.add(((IntegerReply) reply).data());
}
return results;
}
static List<Object> asList(MultiBulkReply genericReply) {
Reply[] replies = genericReply.data();
List<Object> results = new ArrayList<Object>();
for (Reply reply : replies) {
results.add(reply.data());
}
return results;
}
static Object convertScriptReturn(ReturnType returnType, Reply reply) {
if (reply instanceof MultiBulkReply) {
return SrpUtils.asList((MultiBulkReply) reply);
}
if (returnType == ReturnType.BOOLEAN) {
// Lua false comes back as a null bulk reply
if (reply.data() == null) {
return Boolean.FALSE;
}
return ((Long) reply.data() == 1);
}
return reply.data();
}
}

View File

@@ -1,6 +0,0 @@
/**
* Connection package for <a href="https://github.com/spullara/redis-protocol">spullara Redis Protocol</a> library.
* @deprecated since 1.7. Will be removed in subsequent version.
*/
package org.springframework.data.redis.connection.srp;

View File

@@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jredis.Redis;
import org.springframework.util.StringUtils;
/**

View File

@@ -1,844 +0,0 @@
/*
* Copyright 2011-2015 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsInstanceOf;
import org.jredis.JRedis;
import org.jredis.protocol.BulkResponse;
import org.jredis.ri.alphazero.protocol.SyncProtocol.SyncMultiBulkResponse;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link JredisConnection}
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration
public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
@After
public void tearDown() {
try {
connection.flushAll();
connection.close();
} catch (DataAccessException e) {
// Jredis closes a connection on Exception (which some tests
// intentionally throw)
// Attempting to close the connection again will result in error
System.out.println("Connection already closed");
}
connection = null;
}
@Ignore("Pub/Sub not supported")
public void testPubSubWithPatterns() {}
@Ignore("Pub/Sub not supported")
public void testPubSubWithNamedChannels() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSet() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNx() {}
@Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset")
public void testMSetNxFailure() {}
@Ignore("JRedis casts to int")
public void testIncrDecrByLong() {}
@Ignore("Ping returns status response instead of value response")
public void testExecuteNoArgs() {}
@Test
public void testConnectionClosesWhenNotPooled() {
connection.close();
try {
connection.ping();
fail("Expected RedisConnectionFailureException trying to use a closed connection");
} catch (RedisConnectionFailureException e) {}
}
@Test
public void testConnectionStaysOpenWhenPooled() {
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
RedisConnection conn2 = factory2.getConnection();
conn2.close();
conn2.ping();
}
@Test
public void testConnectionNotReturnedOnException() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setMaxWaitMillis(1);
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort(), config));
RedisConnection conn2 = factory2.getConnection();
((JRedis) conn2.getNativeConnection()).quit();
try {
conn2.ping();
fail("Expected RedisConnectionFailureException trying to use a closed connection");
} catch (RedisConnectionFailureException e) {}
conn2.close();
// Verify we get a new connection from the pool and not the broken one
RedisConnection conn3 = factory2.getConnection();
conn3.ping();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiExec() throws Exception {
super.testMultiExec();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiAlreadyInTx() throws Exception {
super.testMultiAlreadyInTx();
}
@Test(expected = UnsupportedOperationException.class)
public void testMultiDiscard() throws Exception {
super.testMultiDiscard();
}
@Test(expected = UnsupportedOperationException.class)
public void testWatch() throws Exception {
super.testWatch();
}
@Test(expected = UnsupportedOperationException.class)
public void testUnwatch() throws Exception {
super.testUnwatch();
}
@Test(expected = UnsupportedOperationException.class)
public void testErrorInTx() {
super.testErrorInTx();
}
@Test(expected = UnsupportedOperationException.class)
public void testExecWithoutMulti() {
super.testExecWithoutMulti();
}
@Test(expected = UnsupportedOperationException.class)
public void testBLPop() {
super.testBLPop();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPop() {
super.testBRPop();
}
@Test(expected = UnsupportedOperationException.class)
public void testLInsert() {
super.testLInsert();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPopLPush() {
super.testBRPopLPush();
}
@Test(expected = UnsupportedOperationException.class)
public void testLPushX() {
super.testLPushX();
}
@Test(expected = UnsupportedOperationException.class)
public void testRPushX() {
super.testRPushX();
}
@Test(expected = UnsupportedOperationException.class)
public void testGetRangeSetRange() {
super.testGetRangeSetRange();
}
@Test(expected = UnsupportedOperationException.class)
public void testStrLen() {
super.testStrLen();
}
@Test(expected = UnsupportedOperationException.class)
public void testGetConfig() {
super.testGetConfig();
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStore() {
super.testZInterStore();
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRangeWithScores() {
super.testZRangeWithScores();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRangeByScoreOffsetCount() {
super.testZRangeByScoreOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRangeByScoreWithScores() {
super.testZRangeByScoreWithScores();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRangeByScoreWithScoresOffsetCount() {
super.testZRangeByScoreWithScoresOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeWithScores() {
super.testZRevRangeWithScores();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStore() {
super.testZUnionStore();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testHSetNX() throws Exception {
super.testHSetNX();
}
@Test(expected = UnsupportedOperationException.class)
public void testHIncrBy() {
super.testHIncrBy();
}
@Test(expected = UnsupportedOperationException.class)
public void testHMGetSet() {
super.testHMGetSet();
}
@Test(expected = UnsupportedOperationException.class)
public void testPersist() throws Exception {
super.testPersist();
}
@Test(expected = UnsupportedOperationException.class)
public void testSetEx() throws Exception {
super.testSetEx();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPopTimeout() throws Exception {
super.testBRPopTimeout();
}
@Test(expected = UnsupportedOperationException.class)
public void testBLPopTimeout() throws Exception {
super.testBLPopTimeout();
}
@Test(expected = UnsupportedOperationException.class)
public void testBRPopLPushTimeout() throws Exception {
super.testBRPopLPushTimeout();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScore() {
super.testZRevRangeByScore();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreOffsetCount() {
super.testZRevRangeByScoreOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreWithScores() {
super.testZRevRangeByScoreWithScores();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRevRangeByScoreWithScoresOffsetCount() {
super.testZRevRangeByScoreWithScoresOffsetCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testSelect() {
super.testSelect();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpire() {
super.testPExpire();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireKeyNotExists() {
super.testPExpireKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAt() {
super.testPExpireAt();
}
@Test(expected = UnsupportedOperationException.class)
public void testPExpireAtKeyNotExists() {
super.testPExpireAtKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testPTtl() {
super.testPTtl();
}
@Test(expected = UnsupportedOperationException.class)
public void testPTtlNoExpire() {
super.testPTtlNoExpire();
}
/**
* @see DATAREDIS-526
*/
@Test(expected = UnsupportedOperationException.class)
public void testPTtlWithTimeUnit() {
super.testPTtlWithTimeUnit();
}
@Test(expected = UnsupportedOperationException.class)
public void testDumpAndRestore() {
super.testDumpAndRestore();
}
@Test(expected = UnsupportedOperationException.class)
public void testDumpNonExistentKey() {
super.testDumpNonExistentKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testRestoreTtl() {
super.testRestoreTtl();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCount() {
super.testBitCount();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCountInterval() {
super.testBitCountInterval();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitCountNonExistentKey() {
super.testBitCountNonExistentKey();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpAnd() {
super.testBitOpAnd();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpOr() {
super.testBitOpOr();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpXOr() {
super.testBitOpXOr();
}
@Test(expected = UnsupportedOperationException.class)
public void testBitOpNot() {
super.testBitOpNot();
}
@Test(expected = UnsupportedOperationException.class)
public void testHIncrByDouble() {
super.testHIncrByDouble();
}
@Test(expected = UnsupportedOperationException.class)
public void testHashIncrDecrByLong() {
super.testHashIncrDecrByLong();
}
@Test(expected = UnsupportedOperationException.class)
public void testIncrByDouble() {
super.testIncrByDouble();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptLoadEvalSha() {
super.testScriptLoadEvalSha();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
super.testEvalShaArrayBytes();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnString() {
super.testEvalReturnString();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnNumber() {
super.testEvalReturnNumber();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleOK() {
super.testEvalReturnSingleOK();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnFalse() {
super.testEvalReturnFalse();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnTrue() {
super.testEvalReturnTrue();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayStrings() {
super.testEvalReturnArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayNumbers() {
super.testEvalReturnArrayNumbers();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
super.testEvalReturnArrayOKs();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayFalses() {
super.testEvalReturnArrayFalses();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayTrues() {
super.testEvalReturnArrayTrues();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptExists() {
super.testScriptExists();
}
@Test(expected = UnsupportedOperationException.class)
public void testScriptKill() throws Exception {
connection.scriptKill();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptFlush() {
connection.scriptFlush();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCount() {
super.testSRandMemberCount();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountKeyNotExists() {
super.testSRandMemberCountKeyNotExists();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testSRandMemberCountNegative() {
super.testSRandMemberCountNegative();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
@Test(expected = UnsupportedOperationException.class)
public void testHDelMultiple() {
super.testHDelMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testLPushMultiple() {
super.testLPushMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testRPushMultiple() {
super.testRPushMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testSAddMultiple() {
super.testSAddMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testSRemMultiple() {
super.testSRemMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testZAddMultiple() {
super.testZAddMultiple();
}
@Test(expected = UnsupportedOperationException.class)
public void testZRemMultiple() {
super.testZRemMultiple();
}
// Jredis returns null for rPush and lPush
@Test
public void testLLen() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "big");
connection.rPush("PopList", "world");
connection.rPush("PopList", "hello");
actual.add(connection.lLen("PopList"));
verifyResults(Arrays.asList(new Object[] { 4l }));
}
@Test
public void testSort() {
connection.rPush("sortlist", "foo");
connection.rPush("sortlist", "bar");
connection.rPush("sortlist", "baz");
assertEquals(Arrays.asList(new String[] { "bar", "baz", "foo" }),
connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true)));
}
@Test
public void testSortStore() {
connection.rPush("sortlist", "foo");
connection.rPush("sortlist", "bar");
connection.rPush("sortlist", "baz");
assertEquals(Long.valueOf(3),
connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true), "newlist"));
assertEquals(Arrays.asList(new String[] { "bar", "baz", "foo" }), connection.lRange("newlist", 0, 9));
}
@Test
public void testSortNullParams() {
connection.rPush("sortlist", "5");
connection.rPush("sortlist", "2");
connection.rPush("sortlist", "3");
actual.add(connection.sort("sortlist", null));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "2", "3", "5" }) }));
}
@Test
public void testSortStoreNullParams() {
connection.rPush("sortlist", "9");
connection.rPush("sortlist", "3");
connection.rPush("sortlist", "5");
actual.add(connection.sort("sortlist", null, "newlist"));
actual.add(connection.lRange("newlist", 0, 9));
verifyResults(Arrays.asList(new Object[] { 3l, Arrays.asList(new String[] { "3", "5", "9" }) }));
}
@Test
public void testLPop() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "world");
assertEquals("hello", connection.lPop("PopList"));
}
@Test
public void testLRem() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "big");
connection.rPush("PopList", "world");
connection.rPush("PopList", "hello");
assertEquals(Long.valueOf(2), connection.lRem("PopList", 2, "hello"));
assertEquals(Arrays.asList(new String[] { "big", "world" }), connection.lRange("PopList", 0, -1));
}
@Test
public void testLSet() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "big");
connection.rPush("PopList", "world");
connection.lSet("PopList", 1, "cruel");
assertEquals(Arrays.asList(new String[] { "hello", "cruel", "world" }), connection.lRange("PopList", 0, -1));
}
@Test
public void testLTrim() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "big");
connection.rPush("PopList", "world");
connection.lTrim("PopList", 1, -1);
assertEquals(Arrays.asList(new String[] { "big", "world" }), connection.lRange("PopList", 0, -1));
}
@Test
public void testRPop() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "world");
assertEquals("world", connection.rPop("PopList"));
}
@Test
public void testRPopLPush() {
connection.rPush("PopList", "hello");
connection.rPush("PopList", "world");
connection.rPush("pop2", "hey");
assertEquals("world", connection.rPopLPush("PopList", "pop2"));
assertEquals(Arrays.asList(new String[] { "hello" }), connection.lRange("PopList", 0, -1));
assertEquals(Arrays.asList(new String[] { "world", "hey" }), connection.lRange("pop2", 0, -1));
}
@Test
public void testLIndex() {
connection.lPush("testylist", "foo");
assertEquals("foo", connection.lIndex("testylist", 0));
}
@Test
public void testLPush() throws Exception {
connection.lPush("testlist", "bar");
connection.lPush("testlist", "baz");
assertEquals(Arrays.asList(new String[] { "baz", "bar" }), connection.lRange("testlist", 0, -1));
}
@Test
public void testExecute() {
connection.set("foo", "bar");
BulkResponse response = (BulkResponse) connection.execute("GET", "foo".getBytes());
assertEquals("bar", stringSerializer.deserialize(response.getBulkData()));
}
@Test
public void testSDiffStore() {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sDiffStore, so we always return -1
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
public void testSInterStore() {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sInterStore, so we always return -1
verifyResults(Arrays
.asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
public void testSUnionStore() {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sAdd("otherset", "baz"));
actual.add(connection.sUnionStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
// JRedis returns void for sUnionStore, so we always return -1
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, -1l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
public void testMove() {
connection.set("foo", "bar");
actual.add(connection.move("foo", 1));
verifyResults(Arrays.asList(new Object[] { true }));
// JRedis does not support select() on existing conn, create new one
JredisConnectionFactory factory2 = new JredisConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar", conn2.get("foo"));
} finally {
if (conn2.exists("foo")) {
conn2.del("foo");
}
conn2.close();
}
}
/**
* @see DATAREDIS-206
*/
@Test(expected = UnsupportedOperationException.class)
public void testGetTimeShouldRequestServerTime() {
super.testGetTimeShouldRequestServerTime();
}
/**
* @see DATAREDIS-285
*/
@Test
public void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
assertThat(result, IsInstanceOf.instanceOf(SyncMultiBulkResponse.class));
List<byte[]> data = ((SyncMultiBulkResponse) result).getMultiBulkData();
assertThat(
data,
IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(),
"supercalifragilisticexpialidocious".getBytes()));
}
/**
* @see DATAREDIS-271
*/
@Test(expected = UnsupportedOperationException.class)
public void testPsetEx() throws Exception {
super.testPsetEx();
}
/**
* @see DATAREDIS-269
*/
@Override
@Test(expected = UnsupportedOperationException.class)
public void clientSetNameWorksCorrectly() {
super.clientSetNameWorksCorrectly();
}
/**
* @see DATAREDIS-268
*/
@Override
@Test(expected = UnsupportedOperationException.class)
public void testListClientsContainsAtLeastOneElement() {
super.testListClientsContainsAtLeastOneElement();
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import org.jredis.JRedis;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
/**
* @author Christoph Strobl
*/
public class JRedisConnectionUnitTests extends AbstractConnectionUnitTestBase<JRedis> {
private JredisConnection connection;
@Before
public void setUp() {
connection = new JredisConnection(getNativeRedisConnectionMock());
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownSaveShouldThrowUnsupportedOperationException() {
connection.shutdown(ShutdownOption.SAVE);
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownNosaveShouldThrowUnsupportedOperationException() {
connection.shutdown(ShutdownOption.NOSAVE);
}
/**
* @see DATAREDIS-184
*/
@Test(expected = UnsupportedOperationException.class)
public void shutdownWithNullShouldThrowUnsupportedOperationException() {
connection.shutdown(null);
}
/**
* @see DATAREDIS-270
*/
@Test(expected = UnsupportedOperationException.class)
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
}
}

View File

@@ -1,141 +0,0 @@
/*
* Copyright 2013-2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.jredis;
import static org.junit.Assert.*;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.jredis.JRedis;
import org.jredis.RedisException;
import org.jredis.connector.ConnectionSpec;
import org.jredis.connector.NotConnectedException;
import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.PoolException;
/**
* Integration test of {@link JredisPool}.
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class JredisPoolTests {
private ConnectionSpec connectionSpec;
private JredisPool pool;
@Before
public void setUp() {
this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(), 0, null);
}
@After
public void tearDown() {
if (this.pool != null) {
this.pool.destroy();
}
}
@Test
public void testGetResource() throws RedisException {
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
client.ping();
}
@Test
public void testGetResourcePoolExhausted() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
try {
pool.getResource();
fail("PoolException should be thrown when pool exhausted");
} catch (PoolException e) {
}
}
@Test
public void testGetResourceValidate() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setTestOnBorrow(true);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
}
@Test(expected = PoolException.class)
public void testGetResourceCreationUnsuccessful() {
// Config poolConfig = new Config();
// poolConfig.testOnBorrow = true;
this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0, null));
pool.getResource();
}
@Test
public void testReturnResource() throws RedisException {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnResource(client);
assertNotNull(pool.getResource());
}
@Test
public void testReturnBrokenResource() throws RedisException {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
poolConfig.setMaxWaitMillis(1);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnBrokenResource(client);
JRedis client2 = pool.getResource();
assertNotSame(client, client2);
try {
client.ping();
fail("Broken resouce connection should be closed");
} catch (NotConnectedException e) {}
}
@Test
public void testCreateWithHostAndPort() {
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort());
assertNotNull(pool.getResource());
}
@Test
public void testCreateWithHostPortAndDbIndex() {
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort(), 1, null, 0);
assertNotNull(pool.getResource());
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnection;
import static org.junit.Assert.fail;
/**
* Integration test of {@link SrpConnectionFactory}
*
* @author Jennifer Hickey
*/
public class SrpConnectionFactoryTests {
@Test
public void testConnect() {
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
connection.ping();
}
@Test
public void testConnectInvalidHost() {
SrpConnectionFactory factory = new SrpConnectionFactory();
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
try {
factory.getConnection();
fail("Expected a connection failure exception");
} catch (RedisConnectionFailureException e) {}
}
@Ignore("Redis must have requirepass set to run this test")
@Test
public void testConnectWithPassword() {
SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory.setPassword("foob");
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
connection.ping();
RedisConnection connection2 = factory.getConnection();
connection2.ping();
}
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright 2011-2015 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import redis.reply.Reply;
/**
* Integration test of {@link SrpConnection}
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
* @author David Liu
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration
public class SrpConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
@After
public void tearDown() {
try {
connection.flushAll();
} catch (Exception e) {
// SRP doesn't allow other commands to be executed once subscribed,
// so
// this fails after pub/sub tests
}
connection.close();
connection = null;
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
/**
* @see DATAREDIS-285
*/
@Test
public void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
Assert.assertThat(result, IsInstanceOf.instanceOf(Reply[].class));
Reply<?>[] replies = (Reply[]) result;
Assert.assertThat(replies[0].data(), Is.<Object> is("awesome".getBytes()));
Assert.assertThat(replies[1].data(), Is.<Object> is("cool".getBytes()));
Assert.assertThat(replies[2].data(), Is.<Object> is("supercalifragilisticexpialidocious".getBytes()));
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
/**
* @see DATAREDIS-106
*/
@Test
public void zRangeByScoreTest() {
connection.zAdd("myzset", 1, "one");
connection.zAdd("myzset", 2, "two");
connection.zAdd("myzset", 3, "three");
Set<byte[]> zRangeByScore = connection.zRangeByScore("myzset", "(1", "2");
Assert.assertEquals("two", new String(zRangeByScore.iterator().next()));
}
}

View File

@@ -1,89 +0,0 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link SrpConnection} pipeline functionality
*
* @author Jennifer Hickey
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
public class SrpConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a
// MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
@Test(expected = RedisSystemException.class)
public void testExecWithoutMulti() {
connection.exec();
// SRP throws an Exception right away on exec instead of once pipeline is closed
getResults();
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
}

View File

@@ -1,112 +0,0 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link SrpConnection} transactions within a pipeline
*
* @author Jennifer Hickey
*/
public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransactionIntegrationTests {
@Test
public void testUsePipelineAfterTxExec() {
connection.set("foo", "bar");
assertNull(connection.exec());
assertNull(connection.get("foo"));
List<Object> results = connection.closePipeline();
assertEquals(Arrays.asList(new Object[] { Collections.emptyList(), "bar" }), results);
assertEquals("bar", connection.get("foo"));
}
@Test
public void testExec2TransactionsInPipeline() {
connection.set("foo", "bar");
assertNull(connection.get("foo"));
assertNull(connection.exec());
connection.multi();
connection.set("foo", "baz");
assertNull(connection.get("foo"));
assertNull(connection.exec());
List<Object> results = connection.closePipeline();
assertEquals(2, results.size());
assertEquals(Arrays.asList(new Object[] { "bar" }), results.get(0));
assertEquals(Arrays.asList(new Object[] { "baz" }), results.get(1));
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
super.testEvalShaNotFound();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
super.testEvalReturnSingleError();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreBadData() {
super.testRestoreBadData();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
super.testEvalArrayScriptError();
}
@Test(expected = RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
super.testEvalShaArrayError();
}
protected void initConnection() {
connection.openPipeline();
connection.multi();
}
@SuppressWarnings("unchecked")
protected List<Object> getResults() {
assertNull(connection.exec());
List<Object> pipelined = connection.closePipeline();
// We expect only the results of exec to be in the closed pipeline
assertEquals(1, pipelined.size());
List<Object> txResults = (List<Object>) pipelined.get(0);
// Return exec results and this test should behave exactly like its superclass
return txResults;
}
}

View File

@@ -1,70 +0,0 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link SrpConnection} functionality within a transaction
*
* @author Jennifer Hickey
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ContextConfiguration("SrpConnectionIntegrationTests-context.xml")
public class SrpConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
// SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[]
actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}",
ReturnType.MULTI, 0));
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
}
@Test
public void testExecuteNoArgs() {
// SRP returns this as String while other drivers return as byte[]
actual.add(connection.execute("PING"));
verifyResults(Arrays.asList(new Object[] { "PONG" }));
}
@Test(expected = UnsupportedOperationException.class)
public void testZInterStoreAggWeights() {
super.testZInterStoreAggWeights();
}
@Test(expected = UnsupportedOperationException.class)
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
/**
* @see DATAREDIS-268
*/
@Test(expected = UnsupportedOperationException.class)
public void testListClientsContainsAtLeastOneElement() {
super.testListClientsContainsAtLeastOneElement();
}
}

View File

@@ -1,189 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
import org.springframework.data.redis.connection.srp.SrpConnectionUnitTestSuite.SrpConnectionPiplineUnitTests;
import org.springframework.data.redis.connection.srp.SrpConnectionUnitTestSuite.SrpConnectionUnitTests;
import redis.client.RedisClient;
import redis.client.RedisClient.Pipeline;
import com.google.common.base.Charsets;
/**
* @author Christoph Strobl
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({ SrpConnectionUnitTests.class, SrpConnectionPiplineUnitTests.class })
public class SrpConnectionUnitTestSuite {
public static class SrpConnectionUnitTests extends AbstractConnectionUnitTestBase<RedisClient> {
protected SrpConnection connection;
@Before
public void setUp() {
connection = new SrpConnection(getNativeRedisConnectionMock());
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNullOpionsIsCalledCorrectly() {
connection.shutdown(null);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithSaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.SAVE);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNosaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.NOSAVE);
verifyNativeConnectionInvocation().shutdown("NOSAVE".getBytes(Charsets.UTF_8), null);
}
/**
* <<<<<<< HEAD
*
* @see DATAREDIS-267
*/
@Test
public void killClientShouldDelegateCallCorrectly() {
String ipPort = "127.0.0.1:1001";
connection.killClient("127.0.0.1", 1001);
verifyNativeConnectionInvocation().client_kill(eq(ipPort));
}
/**
* @see DATAREDIS-270
*/
@Test
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
verifyNativeConnectionInvocation().client_getname();
}
/**
* @see DATAREDIS-277
*/
@Test(expected = IllegalArgumentException.class)
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
connection.slaveOf(null, 0);
}
/**
* @see DATAREDIS-277
*/
@Test
public void slaveOfShouldBeSentCorrectly() {
connection.slaveOf("127.0.0.1", 1001);
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
}
/**
* @see DATAREDIS-277
*/
@Test
public void slaveOfNoOneShouldBeSentCorrectly() {
connection.slaveOfNoOne();
verifyNativeConnectionInvocation().slaveof(eq("NO"), eq("ONE"));
}
}
public static class SrpConnectionPiplineUnitTests extends AbstractConnectionUnitTestBase<Pipeline> {
protected SrpConnection connection;
@Before
public void setUp() {
RedisClient clientMock = mock(RedisClient.class);
connection = new SrpConnection(clientMock);
when(clientMock.pipeline()).thenReturn(getNativeRedisConnectionMock());
connection.openPipeline();
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNullOpionsIsCalledCorrectly() {
connection.shutdown(null);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithSaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.SAVE);
verifyNativeConnectionInvocation().shutdown("SAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-184
*/
@Test
public void shutdownWithNosaveIsCalledCorrectly() {
connection.shutdown(ShutdownOption.NOSAVE);
verifyNativeConnectionInvocation().shutdown("NOSAVE".getBytes(Charsets.UTF_8), null);
}
/**
* @see DATAREDIS-270
*/
@Test
public void getClientNameShouldSendRequestCorrectly() {
connection.getClientName();
verifyNativeConnectionInvocation().client_getname();
}
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import org.junit.Test;
import org.springframework.data.redis.core.types.RedisClientInfo;
import redis.reply.BulkReply;
import redis.reply.Reply;
/**
* @author Christoph Strobl
*/
public class SrpConvertersUnitTests {
private static final String CLIENT_ALL_SINGLE_LINE_RESPONSE = "addr=127.0.0.1:60311 fd=6 name= age=4059 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client";
/**
* @see DATAREDIS-268
*/
@Test
public void convertingNullReplyToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(null)),
equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingEmptyReplyToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(new byte[0])),
equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(SrpConverters.toListOfRedisClientInformation(null), equalTo(Collections.<RedisClientInfo> emptyList()));
}
/**
* @see DATAREDIS-268
*/
@Test
public void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
StringBuilder sb = new StringBuilder();
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
sb.append("\r\n");
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(sb.toString().getBytes())).size(), equalTo(2));
}
/**
* @see DATAREDIS-268
*/
@Test(expected = IllegalArgumentException.class)
public void expectExcptionWhenProvidingInvalidDataInReply() {
SrpConverters.toListOfRedisClientInformation(new Reply<String>() {
@Override
public String data() {
return "foo";
}
@Override
public void write(OutputStream os) throws IOException {
// just do nothing;
}
});
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import java.nio.charset.Charset;
import org.hamcrest.core.IsEqual;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import redis.reply.BulkReply;
import redis.reply.Reply;
/**
* @author Christoph Strobl
* @author Thomas Darimont
*/
public class SrpReplyToTimeAsLongConverterUnitTests {
@SuppressWarnings("rawtypes") private Converter<Reply[], Long> converter;
@Before
public void setUp() {
this.converter = SrpConverters.repliesToTimeAsLong();
}
/**
* @see DATAREDIS-206
*/
@Test
public void testConverterShouldCreateMillisecondsCorrectlyWhenGivenValidReplyArray() {
Reply<?> seconds = new BulkReply("1392183718".getBytes(Charset.forName("UTF-8")));
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
Assert.assertThat(converter.convert(new Reply[] { seconds, microseconds }), IsEqual.equalTo(1392183718555L));
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayIsNull() {
converter.convert(null);
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayIsEmpty() {
converter.convert(new Reply[] {});
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayHasOnlyOneItem() {
converter.convert(new Reply[] { new BulkReply(null) });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExceptionWhenGivenReplyArrayMoreThanTwoItems() {
converter.convert(new Reply[] { new BulkReply(null), new BulkReply(null), new BulkReply(null) });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = NumberFormatException.class)
public void testConverterShouldThrowExecptionForNonParsableReply() {
Reply<?> invalidDataBlock = new BulkReply("123-not-a-number".getBytes(Charset.forName("UTF-8")));
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
converter.convert(new Reply[] { invalidDataBlock, microseconds });
}
/**
* @see DATAREDIS-206
*/
@Test(expected = IllegalArgumentException.class)
public void testConverterShouldThrowExecptionForEmptyDataBlocks() {
Reply<?> invalidDataBlock = new BulkReply(null);
Reply<?> microseconds = new BulkReply("555122".getBytes(Charset.forName("UTF-8")));
converter.convert(new Reply[] { invalidDataBlock, microseconds });
}
}

View File

@@ -1,314 +0,0 @@
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.any;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
import redis.client.RedisClient;
import redis.client.ReplyListener;
/**
* Unit test of {@link SrpSubscription}
*
* @author Jennifer Hickey
*/
public class SrpSubscriptionTests {
private SrpSubscription subscription;
private RedisClient redisClient;
private MessageListener listener;
@Before
public void setUp() {
redisClient = Mockito.mock(RedisClient.class);
listener = Mockito.mock(MessageListener.class);
subscription = new SrpSubscription(listener, redisClient);
}
@Test
public void testUnsubscribeAllAndClose() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeAllChannelsWithPatterns() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeChannelAndClose() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(channel);
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
verify(redisClient).removeListener(any(ReplyListener.class));
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeChannelSomeLeft() {
byte[][] channels = new byte[][] { "a".getBytes(), "b".getBytes() };
subscription.subscribe(channels);
subscription.unsubscribe(new byte[][] { "a".getBytes() });
verify(redisClient, times(1)).unsubscribe((Object[]) new byte[][] { "a".getBytes() });
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> subChannels = subscription.getChannels();
assertEquals(1, subChannels.size());
assertArrayEquals("b".getBytes(), subChannels.iterator().next());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testUnsubscribeChannelWithPatterns() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(channel);
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeChannelWithPatternsSomeLeft() {
byte[][] channel = new byte[][] { "a".getBytes() };
subscription.subscribe(new byte[][] { "a".getBytes(), "b".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe(channel);
verify(redisClient, times(1)).unsubscribe((Object[]) channel);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("b".getBytes(), channels.iterator().next());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeAllNoChannels() {
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
}
@Test
public void testUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.unsubscribe();
verify(redisClient, times(1)).removeListener(any(ReplyListener.class));
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.subscribe(new byte[][] { "s".getBytes() });
}
@Test
public void testPUnsubscribeAllAndClose() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testPUnsubscribeAllPatternsWithChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
}
@Test
public void testPUnsubscribeAndClose() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
subscription.pSubscribe(pattern);
subscription.pUnsubscribe(pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
assertFalse(subscription.isAlive());
verify(redisClient).removeListener(any(ReplyListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
}
@Test
public void testPUnsubscribePatternSomeLeft() {
byte[][] patterns = new byte[][] { "a*".getBytes(), "b*".getBytes() };
subscription.pSubscribe(patterns);
subscription.pUnsubscribe(new byte[][] { "a*".getBytes() });
verify(redisClient, times(1)).punsubscribe((Object[]) new byte[][] { "a*".getBytes() });
verify(redisClient, never()).unsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
Collection<byte[]> subPatterns = subscription.getPatterns();
assertEquals(1, subPatterns.size());
assertArrayEquals("b*".getBytes(), subPatterns.iterator().next());
assertTrue(subscription.getChannels().isEmpty());
}
@Test
public void testPUnsubscribePatternWithChannels() {
byte[][] pattern = new byte[][] { "s*".getBytes() };
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(pattern);
subscription.pUnsubscribe(pattern);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
}
@Test
public void testUnsubscribePatternWithChannelsSomeLeft() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
subscription.pSubscribe(new byte[][] { "a*".getBytes(), "b*".getBytes() });
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pUnsubscribe(pattern);
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) pattern);
assertTrue(subscription.isAlive());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("b*".getBytes(), patterns.iterator().next());
}
@Test
public void testPUnsubscribeAllNoPatterns() {
subscription.subscribe(new byte[][] { "s".getBytes() });
subscription.pUnsubscribe();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("s".getBytes(), channels.iterator().next());
}
@Test
public void testPUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.pUnsubscribe();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
verify(redisClient, times(1)).removeListener(any(ReplyListener.class));
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testPSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
}
@Test
public void testDoCloseNotSubscribed() {
subscription.doClose();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test
public void testDoCloseSubscribedChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.doClose();
verify(redisClient, times(1)).unsubscribe((Object[]) null);
verify(redisClient, never()).punsubscribe((Object[]) null);
}
@Test
public void testDoCloseSubscribedPatterns() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.doClose();
verify(redisClient, never()).unsubscribe((Object[]) null);
verify(redisClient, times(1)).punsubscribe((Object[]) null);
}
}

View File

@@ -1,146 +0,0 @@
/*
* Copyright 2011-2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.junit.Test;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.SortParameters;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
/**
* Unit test of {@link SrpUtils}
*
* @author Jennifer Hickey
* @author Thomas Darimont Suppressed deprecation warnings since SrpUtils is deprecated.
*/
@SuppressWarnings("deprecation")
public class SrpUtilsTests {
@Test
public void testSortParamsWithAllParams() {
SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes())
.get("object_*".getBytes()).limit(0, 5);
Object[] sort = SrpUtils.sortParams(sortParams, "foo".getBytes());
assertArrayEquals(
new String[] { "BY", "weight_*", "LIMIT 0 5", "GET", "object_*", "ASC", "ALPHA", "STORE", "foo" },
convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyBy() {
SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes());
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "BY", "weight_*" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyLimit() {
SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5);
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "LIMIT 0 5" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyGetPatterns() {
SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes());
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "GET", "foo", "GET", "bar" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyOrder() {
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "DESC" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyAlpha() {
SortParameters sortParams = new DefaultSortParameters().alpha();
Object[] sort = SrpUtils.sortParams(sortParams);
assertArrayEquals(new String[] { "ALPHA" }, convertByteArrays(sort));
}
@Test
public void testSortParamsOnlyStore() {
SortParameters sortParams = new DefaultSortParameters().numeric();
Object[] sort = SrpUtils.sortParams(sortParams, "storelist".getBytes());
assertArrayEquals(new String[] { "STORE", "storelist" }, convertByteArrays(sort));
}
@Test
public void testSortWithAllParams() {
SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes())
.get("object_*".getBytes()).limit(0, 5);
byte[] sort = SrpUtils.sort(sortParams, "foo".getBytes());
assertEquals("BY weight_* LIMIT 0 5 GET object_* ASC ALPHA STORE foo", new String(sort));
}
@Test
public void testSortOnlyBy() {
SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes());
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("BY weight_*", new String(sort));
}
@Test
public void testSortOnlyLimit() {
SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5);
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("LIMIT 0 5", new String(sort));
}
@Test
public void testSortOnlyGetPatterns() {
SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes());
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("GET foo GET bar", new String(sort));
}
@Test
public void testSortOnlyOrder() {
SortParameters sortParams = new DefaultSortParameters().numeric().desc();
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("DESC", new String(sort));
}
@Test
public void testSortOnlyAlpha() {
SortParameters sortParams = new DefaultSortParameters().alpha();
byte[] sort = SrpUtils.sort(sortParams);
assertEquals("ALPHA", new String(sort));
}
@Test
public void testSortOnlyStore() {
SortParameters sortParams = new DefaultSortParameters().numeric();
byte[] sort = SrpUtils.sort(sortParams, "storelist".getBytes());
assertEquals("STORE storelist", new String(sort));
}
private String[] convertByteArrays(Object[] bytes) {
List<String> convertedParams = new ArrayList<String>();
for (Object b : bytes) {
convertedParams.add(new String((byte[]) b));
}
return convertedParams.toArray(new String[0]);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.srp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.AbstractTransactionalTestBase;
import org.springframework.data.redis.connection.srp.TransactionalSrpItegrationTests.SrpContextConfiguration;
import org.springframework.test.context.ContextConfiguration;
/**
* @author Christoph Strobl
*/
@ContextConfiguration(classes = { SrpContextConfiguration.class })
public class TransactionalSrpItegrationTests extends AbstractTransactionalTestBase {
@Configuration
public static class SrpContextConfiguration extends RedisContextConfiguration {
@Override
@Bean
public SrpConnectionFactory redisConnectionFactory() {
SrpConnectionFactory factory = new SrpConnectionFactory();
factory.setHostName("localhost");
factory.setPort(6379);
return factory;
}
}
}

View File

@@ -33,7 +33,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* @author Artem Bilian
@@ -67,11 +66,7 @@ public class MultithreadedRedisTemplateTests {
lettuce.setPort(6379);
lettuce.afterPropertiesSet();
SrpConnectionFactory srp = new SrpConnectionFactory();
srp.setPort(6379);
srp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedis }, { lettuce }, { srp } });
return Arrays.asList(new Object[][] { { jedis }, { lettuce } });
}
/**

View File

@@ -54,9 +54,7 @@ import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.core.query.SortQueryBuilder;
import org.springframework.data.redis.core.script.DefaultRedisScript;
@@ -202,8 +200,8 @@ public class RedisTemplateTests<K, V> {
});
List<V> list = Collections.singletonList(listValue);
Set<V> set = new HashSet<V>(Collections.singletonList(setValue));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(Collections.singletonList(new DefaultTypedTuple<V>(
zsetValue, 1d)));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(
Collections.singletonList(new DefaultTypedTuple<V>(zsetValue, 1d)));
assertThat(results, isEqual(Arrays.asList(new Object[] { value1, 1l, list, 1l, set, true, tupleSet })));
}
@@ -261,9 +259,13 @@ public class RedisTemplateTests<K, V> {
@Test
public void testExecConversionDisabled() {
SrpConnectionFactory factory2 = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setConvertPipelineAndTxResults(false);
factory2.afterPropertiesSet();
ConnectionFactoryTracker.add(factory2);
StringRedisTemplate template = new StringRedisTemplate(factory2);
template.afterPropertiesSet();
List<Object> results = template.execute(new SessionCallback<List<Object>>() {
@@ -490,30 +492,6 @@ public class RedisTemplateTests<K, V> {
}, 1500l);
}
@Test
public void testExpireMillisNotSupported() throws Exception {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(redisTemplate.getConnectionFactory() instanceof JredisConnectionFactory);
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String && value1 instanceof String);
final StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
template2.boundValueOps((String) key1).set((String) value1);
template2.expire((String) key1, 10, TimeUnit.MILLISECONDS);
Thread.sleep(15);
// 10 millis should get rounded up to 1 sec if pExpire not supported
assertTrue(template2.hasKey((String) key1));
waitFor(new TestCondition() {
public boolean passes() {
return (!template2.hasKey((String) key1));
}
}, 1000l);
}
@Test
public void testGetExpireNoTimeUnit() {
final K key1 = keyFactory.instance();

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2014 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.core.script.srp;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.script.AbstractDefaultScriptExecutorTests;
import org.springframework.data.redis.core.script.DefaultScriptExecutor;
/**
* Integration test of {@link DefaultScriptExecutor} with SRP.
*
* @author Thomas Darimont
*/
public class SrpDefaultScriptExecutorTests extends AbstractDefaultScriptExecutorTests {
private static SrpConnectionFactory connectionFactory;
@Before
public void setup() {
connectionFactory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
connectionFactory.afterPropertiesSet();
}
@After
public void teardown() {
super.tearDown();
if (connectionFactory != null) {
connectionFactory.destroy();
}
}
@Override
protected RedisConnectionFactory getConnectionFactory() {
return connectionFactory;
}
@Ignore("transactional execution is currently not supported with SRP")
@Override
public void testExecuteTx() {
// super.testExecuteTx();
}
@Ignore("pipelined execution is currently not supported with SRP")
@Override
public void testExecutePipelined() {
// super.testExecutePipelined();
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.listener;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -46,13 +45,10 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
@@ -75,7 +71,7 @@ public class PubSubResubscribeTests {
private RedisMessageListenerContainer container;
private RedisConnectionFactory factory;
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private RedisTemplate template;
public PubSubResubscribeTests(RedisConnectionFactory connectionFactory) {
@@ -99,7 +95,7 @@ public class PubSubResubscribeTests {
int port = SettingsUtils.getPort();
String host = SettingsUtils.getHost();
// Jedis
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
jedisConnFactory.setUsePool(false);
@@ -117,29 +113,12 @@ public class PubSubResubscribeTests {
lettuceConnFactory.setValidateConnection(true);
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(port);
srpConnFactory.setHostName(host);
srpConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jRedisConnectionFactory = new JredisConnectionFactory();
jRedisConnectionFactory.setPort(port);
jRedisConnectionFactory.setHostName(host);
jRedisConnectionFactory.setDatabase(2);
jRedisConnectionFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory },
{ jRedisConnectionFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
@Before
public void setUp() throws Exception {
// JredisConnection#publish is currently not supported -> tests would fail
assumeThat(ConnectionUtils.isJredis(factory), is(false));
template = new StringRedisTemplate(factory);
adapter.setSerializer(template.getValueSerializer());

View File

@@ -27,7 +27,6 @@ import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -77,26 +76,8 @@ public class PubSubTestParams {
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
rawTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSrp = new StringRedisTemplate(srpConnFactory);
RedisTemplate<String, Person> personTemplateSrp = new RedisTemplate<String, Person>();
personTemplateSrp.setConnectionFactory(srpConnFactory);
personTemplateSrp.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateSrp = new RedisTemplate<byte[], byte[]>();
rawTemplateSrp.setEnableDefaultSerializer(false);
rawTemplateSrp.setConnectionFactory(srpConnFactory);
rawTemplateSrp.afterPropertiesSet();
// JRedis does not support pub/sub
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate },
{ rawFactory, rawTemplate }, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ rawFactory, rawTemplateLtc }, { stringFactory, stringTemplateSrp }, { personFactory, personTemplateSrp },
{ rawFactory, rawTemplateSrp } });
{ rawFactory, rawTemplateLtc } });
}
}

View File

@@ -36,10 +36,8 @@ import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
/**
@@ -107,21 +105,7 @@ public class SubscriptionConnectionTests {
lettuceConnFactory.setValidateConnection(true);
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(port);
srpConnFactory.setHostName(host);
srpConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jRedisConnectionFactory = new JredisConnectionFactory();
jRedisConnectionFactory.setPort(port);
jRedisConnectionFactory.setHostName(host);
jRedisConnectionFactory.setDatabase(2);
jRedisConnectionFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory },
{ jRedisConnectionFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
@Test

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.support;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
import java.util.Map;
@@ -32,7 +31,6 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.BoundKeyOperations;
import org.springframework.data.redis.core.RedisCallback;
@@ -49,12 +47,12 @@ import org.springframework.data.redis.support.atomic.RedisAtomicLong;
@RunWith(Parameterized.class)
public class BoundKeyOperationsTest {
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private BoundKeyOperations keyOps;
private ObjectFactory<Object> objFactory;
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private RedisTemplate template;
@SuppressWarnings("rawtypes")
@@ -127,7 +125,6 @@ public class BoundKeyOperationsTest {
*/
@Test
public void testPersist() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
keyOps.persist();

View File

@@ -21,10 +21,8 @@ import java.util.Collection;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
@@ -52,16 +50,6 @@ public class BoundKeyParams {
DefaultRedisSet setJS = new DefaultRedisSet("bound:key:set", templateJS);
RedisList list = new DefaultRedisList("bound:key:list", templateJS);
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory();
jredisConnFactory.setPort(SettingsUtils.getPort());
jredisConnFactory.setHostName(SettingsUtils.getHost());
jredisConnFactory.afterPropertiesSet();
StringRedisTemplate templateJR = new StringRedisTemplate(jredisConnFactory);
DefaultRedisMap mapJR = new DefaultRedisMap("bound:key:mapJR", templateJR);
// Skip list and set. Rename in Collections uses Redis tx, not supported by JRedis
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -74,30 +62,14 @@ public class BoundKeyParams {
DefaultRedisSet setLT = new DefaultRedisSet("bound:key:setLT", templateLT);
RedisList listLT = new DefaultRedisList("bound:key:listLT", templateLT);
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
StringRedisTemplate templateSRP = new StringRedisTemplate(srpConnFactory);
DefaultRedisMap mapSRP = new DefaultRedisMap("bound:key:mapSRP", templateSRP);
DefaultRedisSet setSRP = new DefaultRedisSet("bound:key:setSRP", templateSRP);
RedisList listSRP = new DefaultRedisList("bound:key:listSRP", templateSRP);
StringObjectFactory sof = new StringObjectFactory();
return Arrays.asList(new Object[][] {
{ new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, templateJS },
{ new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, { list, sof, templateJS },
{ setJS, sof, templateJS }, { mapJS, sof, templateJS },
{ new RedisAtomicInteger("bound:key:intJR", jredisConnFactory), sof, templateJR },
{ new RedisAtomicLong("bound:key:longJR", jredisConnFactory), sof, templateJR }, { mapJR, sof, templateJR },
{ new RedisAtomicInteger("bound:key:intLT", lettuceConnFactory), sof, templateLT },
{ new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT }, { listLT, sof, templateLT },
{ setLT, sof, templateLT }, { mapLT, sof, templateLT },
{ new RedisAtomicInteger("bound:key:intSrp", srpConnFactory), sof, templateSRP },
{ new RedisAtomicLong("bound:key:longSrp", srpConnFactory), sof, templateSRP }, { listSRP, sof, templateSRP },
{ setSRP, sof, templateSRP }, { mapSRP, sof, templateSRP } });
return Arrays
.asList(new Object[][] { { new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, templateJS },
{ new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, { list, sof, templateJS },
{ setJS, sof, templateJS }, { mapJS, sof, templateJS },
{ new RedisAtomicInteger("bound:key:intLT", lettuceConnFactory), sof, templateLT },
{ new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT },
{ listLT, sof, templateLT }, { setLT, sof, templateLT }, { mapLT, sof, templateLT } });
}
}

View File

@@ -20,11 +20,8 @@ import java.util.Collection;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* @author Costin Leau
@@ -41,11 +38,6 @@ public abstract class AtomicCountersParam {
jedisConnFactory.setUsePool(true);
jedisConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -53,13 +45,6 @@ public abstract class AtomicCountersParam {
lettuceConnFactory.setHostName(SettingsUtils.getHost());
lettuceConnFactory.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
return Arrays.asList(new Object[][] { { jedisConnFactory }, { jredisConnFactory }, { lettuceConnFactory },
{ srpConnFactory } });
return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } });
}
}

View File

@@ -94,8 +94,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
doubleCounter.set(0);
assertFalse(doubleCounter.compareAndSet(1.2, 10.6));
assertTrue(doubleCounter.compareAndSet(0, 10.6));
@@ -104,14 +103,14 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testIncrementAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0);
assertEquals(1.0, doubleCounter.incrementAndGet(), 0);
}
@Test
public void testAddAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0);
double delta = 1.3;
assertEquals(delta, doubleCounter.addAndGet(delta), .0001);
@@ -119,7 +118,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testDecrementAndGet() throws Exception {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(1);
assertEquals(0, doubleCounter.decrementAndGet(), 0);
}
@@ -133,7 +132,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndIncrement() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(2.3);
assertEquals(2.3, doubleCounter.getAndIncrement(), 0);
assertEquals(3.3, doubleCounter.get(), .0001);
@@ -141,7 +140,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndDecrement() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0.5);
assertEquals(0.5, doubleCounter.getAndDecrement(), 0);
assertEquals(-0.5, doubleCounter.get(), .0001);
@@ -149,7 +148,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testGetAndAdd() {
assumeTrue(!ConnectionUtils.isJredis(factory) && !(ConnectionUtils.isJedis(factory)));
assumeTrue(!(ConnectionUtils.isJedis(factory)));
doubleCounter.set(0.5);
assertEquals(0.5, doubleCounter.getAndAdd(0.7), 0);
assertEquals(1.2, doubleCounter.get(), .0001);
@@ -163,8 +162,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@Test
public void testExpireAt() {
// JRedis converts Unix time to millis before sending command, so it expires right away
assumeTrue(!ConnectionUtils.isJredis(factory));
doubleCounter.set(7.8);
assertTrue(doubleCounter.expireAt(new Date(System.currentTimeMillis() + 10000)));
assertTrue(doubleCounter.getExpire() > 0);

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.support.atomic;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@@ -32,7 +31,6 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@@ -88,8 +86,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
intCounter.set(0);
assertFalse(intCounter.compareAndSet(1, 10));
assertTrue(intCounter.compareAndSet(0, 10));
@@ -162,8 +159,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@Test
@Ignore("DATAREDIS-108 Test is intermittently failing")
public void testCompareSet() throws Exception {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
final AtomicBoolean alreadySet = new AtomicBoolean(false);
final int NUM = 50;
final String KEY = getClass().getSimpleName() + ":atomic:counter";

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.support.atomic;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.util.Collection;
@@ -29,7 +28,6 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@@ -84,8 +82,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
@Test
public void testCheckAndSet() throws Exception {
// Txs not supported in Jredis
assumeTrue(!ConnectionUtils.isJredis(factory));
longCounter.set(0);
assertFalse(longCounter.compareAndSet(1, 10));
assertTrue(longCounter.compareAndSet(0, 10));
@@ -111,7 +108,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
assertEquals(0, longCounter.decrementAndGet());
}
/**
/**
* @see DATAREDIS-469
*/
@Test

View File

@@ -15,15 +15,9 @@
*/
package org.springframework.data.redis.support.collections;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -35,7 +29,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
/**
@@ -234,7 +227,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
@Test
public void testPollTimeout() throws InterruptedException {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
list.add(t1);
assertThat(list.poll(1, TimeUnit.MILLISECONDS), isEqual(t1));
@@ -466,7 +459,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
@Test
public void testPollLastTimeout() throws InterruptedException {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();

View File

@@ -44,7 +44,6 @@ import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
@@ -212,8 +211,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testIncrementNotNumber() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())
&& !(valueFactory instanceof LongAsStringObjectFactory));
assumeTrue(!(valueFactory instanceof LongAsStringObjectFactory));
K k1 = getKey();
V v1 = getValue();
@@ -291,7 +289,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testPutAll() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
Map<K, V> m = new LinkedHashMap<K, V>();
K k1 = getKey();
K k2 = getKey();
@@ -372,7 +370,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@SuppressWarnings("unchecked")
@Test
public void testEntrySet() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
Set<Entry<K, V>> entries = map.entrySet();
assertTrue(entries.isEmpty());
@@ -404,7 +402,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testPutIfAbsent() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
K k2 = getKey();
@@ -424,7 +422,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentRemove() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();
@@ -444,7 +442,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentReplaceTwoArgs() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();
@@ -471,7 +469,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testConcurrentReplaceOneArg() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
K k1 = getKey();
V v1 = getValue();
V v2 = getValue();

View File

@@ -34,7 +34,6 @@ import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.LongObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.BoundZSetOperations;
@@ -219,7 +218,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
@Test
public void testIntersectAndStore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
RedisZSet<T> interSet1 = createZSetFor("test:zset:inter1");
RedisZSet<T> interSet2 = createZSetFor("test:zset:inter");
@@ -265,7 +264,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -306,7 +305,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -334,10 +333,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnbounded() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -359,10 +356,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBounded() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -384,10 +379,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnboundedWithLimit() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -396,8 +389,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();
@@ -410,10 +403,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBoundedWithLimit() {
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -422,8 +413,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();
@@ -432,7 +423,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeByScore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -450,7 +441,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testReverseRangeByScoreWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -494,7 +485,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByScoreWithScores() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
T t1 = getT();
T t2 = getT();
T t3 = getT();
@@ -560,7 +551,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
@Test
public void testUnionAndStore() {
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
RedisZSet<T> unionSet1 = createZSetFor("test:zset:union1");
RedisZSet<T> unionSet2 = createZSetFor("test:zset:union2");

View File

@@ -26,11 +26,8 @@ import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -106,79 +103,6 @@ public abstract class CollectionTestParams {
rawTemplate.setKeySerializer(stringSerializer);
rawTemplate.afterPropertiesSet();
// jredis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateJR = new StringRedisTemplate(jredisConnFactory);
RedisTemplate<String, Person> personTemplateJR = new RedisTemplate<String, Person>();
personTemplateJR.setConnectionFactory(jredisConnFactory);
personTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xstreamStringTemplateJR = new RedisTemplate<String, Person>();
xstreamStringTemplateJR.setConnectionFactory(jredisConnFactory);
xstreamStringTemplateJR.setDefaultSerializer(serializer);
xstreamStringTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplateJR = new RedisTemplate<String, Person>();
xstreamPersonTemplateJR.setValueSerializer(serializer);
xstreamPersonTemplateJR.setConnectionFactory(jredisConnFactory);
xstreamPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setValueSerializer(jsonSerializer);
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateJR = new RedisTemplate<byte[], byte[]>();
rawTemplateJR.setConnectionFactory(jredisConnFactory);
rawTemplateJR.setEnableDefaultSerializer(false);
rawTemplateJR.setKeySerializer(stringSerializer);
rawTemplateJR.afterPropertiesSet();
// SRP
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
srConnFactory.setPort(SettingsUtils.getPort());
srConnFactory.setHostName(SettingsUtils.getHost());
srConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSRP = new StringRedisTemplate(srConnFactory);
RedisTemplate<String, Person> personTemplateSRP = new RedisTemplate<String, Person>();
personTemplateSRP.setConnectionFactory(srConnFactory);
personTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> xstreamStringTemplateSRP = new RedisTemplate<String, Person>();
xstreamStringTemplateSRP.setConnectionFactory(srConnFactory);
xstreamStringTemplateSRP.setDefaultSerializer(serializer);
xstreamStringTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplateSRP = new RedisTemplate<String, Person>();
xstreamPersonTemplateSRP.setValueSerializer(serializer);
xstreamPersonTemplateSRP.setConnectionFactory(srConnFactory);
xstreamPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSRP = new RedisTemplate<String, Person>();
jsonPersonTemplateSRP.setValueSerializer(jsonSerializer);
jsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
jsonPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSRP = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSRP.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
jackson2JsonPersonTemplateSRP.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateSRP = new RedisTemplate<byte[], byte[]>();
rawTemplateSRP.setConnectionFactory(srConnFactory);
rawTemplateSRP.setEnableDefaultSerializer(false);
rawTemplateSRP.setKeySerializer(stringSerializer);
rawTemplateSRP.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -217,36 +141,17 @@ public abstract class CollectionTestParams {
rawTemplateLtc.setKeySerializer(stringSerializer);
rawTemplateLtc.afterPropertiesSet();
return Arrays.asList(new Object[][] {
{ stringFactory, stringTemplate },
{ doubleAsStringObjectFactory, stringTemplate },
{ personFactory, personTemplate },
{ stringFactory, xstreamStringTemplate },
{ personFactory, xstreamPersonTemplate },
{ personFactory, jsonPersonTemplate },
{ personFactory, jackson2JsonPersonTemplate },
{ rawFactory, rawTemplate },
// Jredis
{ stringFactory, stringTemplateJR },
{ personFactory, personTemplateJR },
{ stringFactory, xstreamStringTemplateJR },
{ personFactory, xstreamPersonTemplateJR },
{ personFactory, jsonPersonTemplateJR },
{ personFactory, jackson2JsonPersonTemplateJR },
{ rawFactory, rawTemplateJR },
// srp
{ stringFactory, stringTemplateSRP },
{ personFactory, personTemplateSRP },
{ stringFactory, xstreamStringTemplateSRP },
{ personFactory, xstreamPersonTemplateSRP },
{ personFactory, jsonPersonTemplateSRP },
{ personFactory, jackson2JsonPersonTemplateSRP },
{ rawFactory, rawTemplateSRP },
// lettuce
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ doubleAsStringObjectFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
{ personFactory, jsonPersonTemplateLtc }, { personFactory, jackson2JsonPersonTemplateLtc },
{ rawFactory, rawTemplateLtc } });
return Arrays
.asList(new Object[][] { { stringFactory, stringTemplate }, { doubleAsStringObjectFactory, stringTemplate },
{ personFactory, personTemplate }, { stringFactory, xstreamStringTemplate },
{ personFactory, xstreamPersonTemplate }, { personFactory, jsonPersonTemplate },
{ personFactory, jackson2JsonPersonTemplate }, { rawFactory, rawTemplate },
// lettuce
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ doubleAsStringObjectFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
{ personFactory, jsonPersonTemplateLtc }, { personFactory, jackson2JsonPersonTemplateLtc },
{ rawFactory, rawTemplateLtc } });
}
}

View File

@@ -29,11 +29,8 @@ import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.PoolConfig;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -131,40 +128,6 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
rawTemplate.setKeySerializer(stringSerializer);
rawTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort(), defaultPoolConfig));
jredisConnFactory.afterPropertiesSet();
RedisTemplate genericTemplateJR = new RedisTemplate();
genericTemplateJR.setConnectionFactory(jredisConnFactory);
genericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> xGenericTemplateJR = new RedisTemplate<String, Person>();
xGenericTemplateJR.setConnectionFactory(jredisConnFactory);
xGenericTemplateJR.setDefaultSerializer(serializer);
xGenericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplateJR = new RedisTemplate<String, byte[]>();
rawTemplateJR.setEnableDefaultSerializer(false);
rawTemplateJR.setConnectionFactory(jredisConnFactory);
rawTemplateJR.setKeySerializer(stringSerializer);
rawTemplateJR.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -205,54 +168,11 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
rawTemplateLtc.setKeySerializer(stringSerializer);
rawTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate genericTemplateSrp = new RedisTemplate();
genericTemplateSrp.setConnectionFactory(srpConnFactory);
genericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> xGenericTemplateSrp = new RedisTemplate<String, Person>();
xGenericTemplateSrp.setConnectionFactory(srpConnFactory);
xGenericTemplateSrp.setDefaultSerializer(serializer);
xGenericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateSrp = new StringRedisTemplate();
stringTemplateSrp.setConnectionFactory(srpConnFactory);
stringTemplateSrp.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplateSrp = new RedisTemplate<String, byte[]>();
rawTemplateSrp.setEnableDefaultSerializer(false);
rawTemplateSrp.setConnectionFactory(srpConnFactory);
rawTemplateSrp.setKeySerializer(stringSerializer);
rawTemplateSrp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
{ personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate },
{ personFactory, stringFactory, genericTemplate }, { personFactory, stringFactory, xstreamGenericTemplate },
{ personFactory, stringFactory, jsonPersonTemplate },
{ personFactory, stringFactory, jackson2JsonPersonTemplate }, { rawFactory, rawFactory, rawTemplate },
{ stringFactory, stringFactory, genericTemplateJR }, { personFactory, personFactory, genericTemplateJR },
{ stringFactory, personFactory, genericTemplateJR }, { personFactory, stringFactory, genericTemplateJR },
{ personFactory, stringFactory, xGenericTemplateJR }, { personFactory, stringFactory, jsonPersonTemplateJR },
{ personFactory, stringFactory, jackson2JsonPersonTemplateJR }, { rawFactory, rawFactory, rawTemplateJR },
{ stringFactory, stringFactory, genericTemplateLettuce },
{ personFactory, personFactory, genericTemplateLettuce },
{ stringFactory, personFactory, genericTemplateLettuce },
@@ -261,11 +181,6 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
{ personFactory, stringFactory, jsonPersonTemplateLettuce },
{ personFactory, stringFactory, jackson2JsonPersonTemplateLettuce },
{ stringFactory, doubleFactory, stringTemplateLtc }, { stringFactory, longFactory, stringTemplateLtc },
{ rawFactory, rawFactory, rawTemplateLtc }, { stringFactory, stringFactory, genericTemplateSrp },
{ personFactory, personFactory, genericTemplateSrp }, { stringFactory, personFactory, genericTemplateSrp },
{ personFactory, stringFactory, genericTemplateSrp }, { personFactory, stringFactory, xGenericTemplateSrp },
{ stringFactory, doubleFactory, stringTemplateSrp }, { stringFactory, longFactory, stringTemplateSrp },
{ personFactory, stringFactory, jsonPersonTemplateSrp },
{ personFactory, stringFactory, jackson2JsonPersonTemplateSrp }, { rawFactory, rawFactory, rawTemplateSrp } });
{ rawFactory, rawFactory, rawTemplateLtc } });
}
}

View File

@@ -39,11 +39,8 @@ import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -91,8 +88,8 @@ public class RedisPropertiesTests extends RedisMapTests {
@Test
public void testPropertiesLoad() throws Exception {
InputStream stream = getClass().getResourceAsStream(
"/org/springframework/data/redis/support/collections/props.properties");
InputStream stream = getClass()
.getResourceAsStream("/org/springframework/data/redis/support/collections/props.properties");
assertNotNull(stream);
@@ -113,8 +110,8 @@ public class RedisPropertiesTests extends RedisMapTests {
@Test
@Ignore
public void testPropertiesLoadXml() throws Exception {
InputStream stream = getClass().getResourceAsStream(
"/org/springframework/data/keyvalue/redis/support/collections/props.properties");
InputStream stream = getClass()
.getResourceAsStream("/org/springframework/data/keyvalue/redis/support/collections/props.properties");
assertNotNull(stream);
@@ -284,31 +281,6 @@ public class RedisPropertiesTests extends RedisMapTests {
jackson2JsonPersonTemplate.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> genericTemplateJR = new StringRedisTemplate(jredisConnFactory);
RedisTemplate<String, Person> xGenericTemplateJR = new RedisTemplate<String, Person>();
xGenericTemplateJR.setConnectionFactory(jredisConnFactory);
xGenericTemplateJR.setDefaultSerializer(serializer);
xGenericTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateJR.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateJR.afterPropertiesSet();
// Lettuce
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -336,51 +308,17 @@ public class RedisPropertiesTests extends RedisMapTests {
jackson2JsonPersonTemplateLtc.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateLtc.afterPropertiesSet();
// SRP
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
srpConnFactory.setPort(SettingsUtils.getPort());
srpConnFactory.setHostName(SettingsUtils.getHost());
srpConnFactory.afterPropertiesSet();
RedisTemplate<String, String> genericTemplateSrp = new StringRedisTemplate(srpConnFactory);
RedisTemplate<String, Person> xGenericTemplateSrp = new RedisTemplate<String, Person>();
xGenericTemplateSrp.setConnectionFactory(srpConnFactory);
xGenericTemplateSrp.setDefaultSerializer(serializer);
xGenericTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer);
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
jsonPersonTemplateSrp.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, genericTemplate },
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, xstreamGenericTemplate },
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
{ stringFactory, stringFactory, xGenericTemplateJR }, { stringFactory, stringFactory, jsonPersonTemplate },
{ stringFactory, stringFactory, jsonPersonTemplate },
{ stringFactory, stringFactory, jackson2JsonPersonTemplate },
{ stringFactory, stringFactory, jsonPersonTemplateJR },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateJR },
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
{ stringFactory, doubleFactory, genericTemplateLtc }, { stringFactory, longFactory, genericTemplateLtc },
{ stringFactory, stringFactory, xGenericTemplateLtc }, { stringFactory, stringFactory, jsonPersonTemplateLtc },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateLtc },
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
{ stringFactory, doubleFactory, genericTemplateSrp }, { stringFactory, longFactory, genericTemplateSrp },
{ stringFactory, stringFactory, xGenericTemplateSrp }, { stringFactory, stringFactory, jsonPersonTemplateSrp },
{ stringFactory, stringFactory, jackson2JsonPersonTemplateSrp } });
{ stringFactory, stringFactory, jackson2JsonPersonTemplateLtc } });
}
}

View File

@@ -37,20 +37,7 @@ public enum RedisDriver {
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isLettuce(connectionFactory);
}
},
SRP {
@Override
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isSrp(connectionFactory);
}
},
JREDIS {
@Override
public boolean matches(RedisConnectionFactory connectionFactory) {
return ConnectionUtils.isJredis(connectionFactory);
}
};
/**

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jredisConnectionFactory "
class="org.springframework.data.redis.connection.jredis.JredisConnectionFactory">
<property name="hostName">
<bean class="org.springframework.data.redis.SettingsUtils"
factory-method="getHost" />
</property>
<property name="port">
<bean class="org.springframework.data.redis.SettingsUtils"
factory-method="getPort" />
</property>
</bean>
</beans>

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="srpConnectionFactory "
class="org.springframework.data.redis.connection.srp.SrpConnectionFactory">
<property name="hostName">
<bean class="org.springframework.data.redis.SettingsUtils"
factory-method="getHost" />
</property>
<property name="port">
<bean class="org.springframework.data.redis.SettingsUtils"
factory-method="getPort" />
</property>
</bean>
</beans>