diff --git a/pom.xml b/pom.xml index 1a4c01c3e..82f6399a9 100644 --- a/pom.xml +++ b/pom.xml @@ -23,8 +23,6 @@ 2.2 4.2.2.Final 2.9.0 - 0.7 - 06052013 1.01 @@ -85,27 +83,6 @@ true - - org.jredis - jredis-core-api - ${jredis} - true - - - - org.jredis - jredis-core-ri - ${jredis} - true - - - - com.github.spullara.redis - client - ${srp} - true - - biz.paluch.redis lettuce diff --git a/src/main/asciidoc/reference/redis-transactions.adoc b/src/main/asciidoc/reference/redis-transactions.adoc index 0976c4d7a..874232549 100644 --- a/src/main/asciidoc/reference/redis-transactions.adoc +++ b/src/main/asciidoc/reference/redis-transactions.adoc @@ -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 { // ... } diff --git a/src/main/asciidoc/reference/redis.adoc b/src/main/asciidoc/reference/redis.adoc index acdfd83c2..d68ee1218 100644 --- a/src/main/asciidoc/reference/redis.adoc +++ b/src/main/asciidoc/reference/redis.adoc @@ -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 ---- -[[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] ----- - - - - - - ----- - -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] ----- - - - - - - - - - - - - - ----- - -[[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] ----- - - - - - - ----- - -Needless to say, the configuration is quite similar to that of the other connectors. - [[redis:connectors:lettuce]] === Configuring Lettuce connector diff --git a/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java b/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java index 9ba1ccca8..1ff418c6e 100644 --- a/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java @@ -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) { diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java deleted file mode 100644 index 155dcab68..000000000 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java +++ /dev/null @@ -1,1643 +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.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.jredis.ClientRuntimeException; -import org.jredis.JRedis; -import org.jredis.Query.Support; -import org.jredis.RedisException; -import org.jredis.Sort; -import org.jredis.connector.ConnectionException; -import org.jredis.connector.NotConnectedException; -import org.jredis.protocol.Command; -import org.jredis.ri.alphazero.JRedisSupport; -import org.springframework.dao.DataAccessException; -import org.springframework.data.geo.Circle; -import org.springframework.data.geo.Distance; -import org.springframework.data.geo.GeoResults; -import org.springframework.data.geo.Metric; -import org.springframework.data.geo.Point; -import org.springframework.data.redis.RedisSystemException; -import org.springframework.data.redis.connection.AbstractRedisConnection; -import org.springframework.data.redis.connection.DataType; -import org.springframework.data.redis.connection.MessageListener; -import org.springframework.data.redis.connection.Pool; -import org.springframework.data.redis.connection.RedisNode; -import org.springframework.data.redis.connection.ReturnType; -import org.springframework.data.redis.connection.SortParameters; -import org.springframework.data.redis.connection.Subscription; -import org.springframework.data.redis.connection.convert.Converters; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.ScanOptions; -import org.springframework.data.redis.core.types.Expiration; -import org.springframework.data.redis.core.types.RedisClientInfo; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; -import org.springframework.util.ReflectionUtils; - -/** - * {@code RedisConnection} implementation on top of JRedis library. - * - * @author Costin Leau - * @author Jennifer Hickey - * @author Christoph Strobl - * @author Thomas Darimont - * @author David Liu - * @author Ninad Divadkar - * @author Mark Paluch - * @deprecated since 1.7. Will be removed in subsequent version. - */ -@Deprecated -public class JredisConnection extends AbstractRedisConnection { - - private static final Method SERVICE_REQUEST; - - private final JRedis jredis; - private final Pool pool; - private boolean isClosed = false; - /** flag indicating whether the connection needs to be dropped or not */ - private boolean broken = false; - - static { - SERVICE_REQUEST = ReflectionUtils.findMethod(JRedisSupport.class, "serviceRequest", Command.class, byte[][].class); - ReflectionUtils.makeAccessible(SERVICE_REQUEST); - } - - /** - * Constructs a new JredisConnection instance. - * - * @param jredis JRedis connection - */ - public JredisConnection(JRedis jredis) { - this(jredis, null); - } - - public JredisConnection(JRedis jredis, Pool pool) { - Assert.notNull(jredis, "a not-null instance required"); - this.jredis = jredis; - this.pool = pool; - } - - protected DataAccessException convertJredisAccessException(Exception ex) { - if (ex instanceof RedisException) { - return JredisUtils.convertJredisAccessException((RedisException) ex); - } - - if (ex instanceof ClientRuntimeException) { - if (ex instanceof NotConnectedException || ex instanceof ConnectionException) { - broken = true; - } - return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex); - } - - return new RedisSystemException("Unknown JRedis exception", ex); - } - - public Object execute(String command, byte[]... args) { - Assert.hasText(command, "a valid command needs to be specified"); - try { - List mArgs = new ArrayList(); - if (!ObjectUtils.isEmpty(args)) { - Collections.addAll(mArgs, args); - } - - return ReflectionUtils.invokeMethod(SERVICE_REQUEST, jredis, Command.valueOf(command.trim().toUpperCase()), - mArgs.toArray(new byte[mArgs.size()][])); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void close() throws RedisSystemException { - super.close(); - - if (isClosed()) { - return; - } - isClosed = true; - - if (pool != null) { - if (!broken) { - pool.returnResource(jredis); - } else { - pool.returnBrokenResource(jredis); - } - return; - } - - try { - jredis.quit(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - - } - - public JRedis getNativeConnection() { - return jredis; - } - - public boolean isClosed() { - return isClosed; - } - - public boolean isQueueing() { - return false; - } - - public boolean isPipelined() { - return false; - } - - public void openPipeline() { - throw new UnsupportedOperationException("Pipelining not supported by JRedis"); - } - - public List closePipeline() { - return Collections.emptyList(); - } - - public List sort(byte[] key, SortParameters params) { - Sort sort = jredis.sort(key); - JredisUtils.applySortingParams(sort, params, null); - try { - return sort.exec(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { - Sort sort = jredis.sort(key); - JredisUtils.applySortingParams(sort, params, storeKey); - try { - return Support.unpackValue(sort.exec()); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long dbSize() { - try { - return (Long) jredis.dbsize(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void flushDb() { - try { - jredis.flushdb(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void flushAll() { - try { - jredis.flushall(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] echo(byte[] message) { - try { - return jredis.echo(message); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public String ping() { - try { - jredis.ping(); - return "PONG"; - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void bgSave() { - try { - jredis.bgsave(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void bgReWriteAof() { - try { - jredis.bgrewriteaof(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - /** - * @deprecated As of 1.3, use {@link #bgReWriteAof}. - */ - @Deprecated - public void bgWriteAof() { - bgReWriteAof(); - } - - public void save() { - try { - jredis.save(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List getConfig(String pattern) { - throw new UnsupportedOperationException(); - } - - public Properties info() { - try { - return JredisUtils.info(jredis.info()); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Properties info(String section) { - throw new UnsupportedOperationException(); - } - - public Long lastSave() { - try { - return (Long) jredis.lastsave(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void setConfig(String param, String value) { - throw new UnsupportedOperationException(); - } - - public void resetConfigStats() { - throw new UnsupportedOperationException(); - } - - public void shutdown() { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption) - */ - @Override - public void shutdown(ShutdownOption option) { - throw new UnsupportedOperationException(); - } - - public Long del(byte[]... keys) { - try { - return jredis.del(keys); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void discard() { - try { - jredis.discard(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List exec() { - throw new UnsupportedOperationException(); - } - - public Boolean exists(byte[] key) { - try { - return jredis.exists(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean expire(byte[] key, long seconds) { - try { - return jredis.expire(key, (int) seconds); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean expireAt(byte[] key, long unixTime) { - try { - return jredis.expireat(key, unixTime); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean pExpire(byte[] key, long millis) { - throw new UnsupportedOperationException(); - } - - public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[]) - */ - @Override - public Long pTtl(byte[] key) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[], java.util.concurrent.TimeUnit) - */ - @Override - public Long pTtl(byte[] key, TimeUnit timeUnit) { - throw new UnsupportedOperationException(); - } - - public byte[] dump(byte[] key) { - throw new UnsupportedOperationException(); - } - - public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { - throw new UnsupportedOperationException(); - } - - public Set keys(byte[] pattern) { - try { - return new LinkedHashSet(jredis.keys(pattern)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void multi() { - throw new UnsupportedOperationException(); - } - - public Boolean persist(byte[] key) { - throw new UnsupportedOperationException(); - } - - public Boolean move(byte[] key, int dbIndex) { - try { - return jredis.move(key, dbIndex); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] randomKey() { - try { - return jredis.randomkey(); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void rename(byte[] oldName, byte[] newName) { - try { - jredis.rename(oldName, newName); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean renameNX(byte[] oldName, byte[] newName) { - try { - return jredis.renamenx(oldName, newName); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void select(int dbIndex) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[]) - */ - @Override - public Long ttl(byte[] key) { - - Assert.notNull(key, "Key must not be null!"); - - try { - return jredis.ttl(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[], java.util.concurrent.TimeUnit) - */ - @Override - public Long ttl(byte[] key, TimeUnit timeUnit) { - - Assert.notNull(key, "Key must not be null!"); - - try { - return Converters.secondsToTimeUnit(jredis.ttl(key), timeUnit); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public DataType type(byte[] key) { - try { - return JredisUtils.convertDataType(jredis.type(key)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void unwatch() { - throw new UnsupportedOperationException(); - } - - public void watch(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - // - // String operations - // - - public byte[] get(byte[] key) { - try { - return jredis.get(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void set(byte[] key, byte[] value) { - try { - jredis.set(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOption) - */ - @Override - public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { - throw new UnsupportedOperationException( - "SET with options is not supported for JRedis. Please use SETNX, SETEX, PSETEX."); - } - - public byte[] getSet(byte[] key, byte[] value) { - try { - return jredis.getset(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long append(byte[] key, byte[] value) { - try { - return jredis.append(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List mGet(byte[]... keys) { - try { - return jredis.mget(keys); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void mSet(Map tuple) { - try { - jredis.mset(tuple); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean mSetNX(Map tuple) { - try { - return jredis.msetnx(tuple); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void setEx(byte[] key, long seconds, byte[] value) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[]) - */ - @Override - public void pSetEx(byte[] key, long milliseconds, byte[] value) { - throw new UnsupportedOperationException(); - } - - public Boolean setNX(byte[] key, byte[] value) { - try { - return jredis.setnx(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] getRange(byte[] key, long start, long end) { - try { - return jredis.substr(key, start, end); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long decr(byte[] key) { - try { - return jredis.decr(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long decrBy(byte[] key, long value) { - try { - return jredis.decrby(key, (int) value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long incr(byte[] key) { - try { - return jredis.incr(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long incrBy(byte[] key, long value) { - try { - return jredis.incrby(key, (int) value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Double incrBy(byte[] key, double value) { - throw new UnsupportedOperationException(); - } - - public Boolean getBit(byte[] key, long offset) { - try { - return jredis.getbit(key, (int) offset); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean setBit(byte[] key, long offset, boolean value) { - try { - return jredis.setbit(key, (int) offset, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void setRange(byte[] key, byte[] value, long start) { - throw new UnsupportedOperationException(); - } - - public Long strLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - public Long bitCount(byte[] key) { - throw new UnsupportedOperationException(); - } - - public Long bitCount(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - // - // List commands - // - - public List bLPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - public List bRPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - public byte[] lIndex(byte[] key, long index) { - try { - return jredis.lindex(key, index); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long lLen(byte[] key) { - try { - return jredis.llen(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] lPop(byte[] key) { - try { - return jredis.lpop(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long lPush(byte[] key, byte[]... values) { - if (values.length > 1) { - throw new UnsupportedOperationException("lPush of multiple fields not supported"); - } - try { - jredis.lpush(key, values[0]); - return null; - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List lRange(byte[] key, long start, long end) { - try { - List lrange = jredis.lrange(key, start, end); - - return lrange; - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long lRem(byte[] key, long count, byte[] value) { - try { - return jredis.lrem(key, value, (int) count); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void lSet(byte[] key, long index, byte[] value) { - try { - jredis.lset(key, index, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public void lTrim(byte[] key, long start, long end) { - try { - jredis.ltrim(key, start, end); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] rPop(byte[] key) { - try { - return jredis.rpop(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - try { - return jredis.rpoplpush(srcKey, dstKey); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long rPush(byte[] key, byte[]... values) { - if (values.length > 1) { - throw new UnsupportedOperationException("rPush of multiple fields not supported"); - } - try { - jredis.rpush(key, values[0]); - return null; - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - throw new UnsupportedOperationException(); - } - - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - throw new UnsupportedOperationException(); - } - - public Long lPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - public Long rPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - // - // Set commands - // - - public Long sAdd(byte[] key, byte[]... values) { - if (values.length > 1) { - throw new UnsupportedOperationException("sAdd of multiple fields not supported"); - } - try { - return JredisUtils.toLong(jredis.sadd(key, values[0])); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long sCard(byte[] key) { - try { - return jredis.scard(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set sDiff(byte[]... keys) { - byte[] destKey = keys[0]; - byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); - - try { - List result = jredis.sdiff(destKey, sets); - return new LinkedHashSet(result); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long sDiffStore(byte[] destKey, byte[]... keys) { - try { - jredis.sdiffstore(destKey, keys); - return Long.valueOf(-1); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set sInter(byte[]... keys) { - byte[] set1 = keys[0]; - byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); - - try { - List result = jredis.sinter(set1, sets); - return new LinkedHashSet(result); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long sInterStore(byte[] destKey, byte[]... keys) { - try { - jredis.sinterstore(destKey, keys); - return Long.valueOf(-1); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean sIsMember(byte[] key, byte[] value) { - try { - return jredis.sismember(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set sMembers(byte[] key) { - try { - return new LinkedHashSet(jredis.smembers(key)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - try { - return jredis.smove(srcKey, destKey, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] sPop(byte[] key) { - try { - return jredis.spop(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] sRandMember(byte[] key) { - try { - return jredis.srandmember(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List sRandMember(byte[] key, long count) { - throw new UnsupportedOperationException(); - } - - public Long sRem(byte[] key, byte[]... values) { - if (values.length > 1) { - throw new UnsupportedOperationException("sRem of multiple fields not supported"); - } - try { - return JredisUtils.toLong(jredis.srem(key, values[0])); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set sUnion(byte[]... keys) { - byte[] set1 = keys[0]; - byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); - - try { - return new LinkedHashSet(jredis.sunion(set1, sets)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long sUnionStore(byte[] destKey, byte[]... keys) { - try { - jredis.sunionstore(destKey, keys); - return Long.valueOf(-1); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - // - // ZSet commands - // - - public Boolean zAdd(byte[] key, double score, byte[] value) { - try { - return jredis.zadd(key, score, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zAdd(byte[] key, Set tuples) { - throw new UnsupportedOperationException(); - } - - public Long zCard(byte[] key) { - try { - return jredis.zcard(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zCount(byte[] key, double min, double max) { - return zCount(key, new Range().gte(min).lte(max)); - } - - @Override - public Long zCount(byte[] key, Range range) { - - Assert.notNull(range, "Range for ZCOUNT must not be null!"); - - double min = ((Double) range.getMin().getValue()).doubleValue(); - double max = ((Double) range.getMax().getValue()).doubleValue(); - - try { - return jredis.zcount(key, min, max); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Double zIncrBy(byte[] key, double increment, byte[] value) { - try { - return jredis.zincrby(key, increment, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Long zInterStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Set zRange(byte[] key, long start, long end) { - try { - return new LinkedHashSet(jredis.zrange(key, start, end)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set zRangeWithScores(byte[] key, long start, long end) { - throw new UnsupportedOperationException(); - } - - public Set zRangeByScore(byte[] key, double min, double max) { - try { - return new LinkedHashSet(jredis.zrangebyscore(key, min, max)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException(); - } - - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - public Set zRevRangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - public Long zRank(byte[] key, byte[] value) { - try { - return jredis.zrank(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zRem(byte[] key, byte[]... values) { - if (values.length > 1) { - throw new UnsupportedOperationException("zRem of multiple fields not supported"); - } - try { - return JredisUtils.toLong(jredis.zrem(key, values[0])); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zRemRange(byte[] key, long start, long end) { - try { - return jredis.zremrangebyrank(key, start, end); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long zRemRangeByScore(byte[] key, double min, double max) { - try { - return jredis.zremrangebyscore(key, min, max); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set zRevRange(byte[] key, long start, long end) { - try { - return new LinkedHashSet(jredis.zrevrange(key, start, end)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Set zRevRangeWithScores(byte[] key, long start, long end) { - throw new UnsupportedOperationException(); - } - - public Long zRevRank(byte[] key, byte[] value) { - try { - return jredis.zrevrank(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Double zScore(byte[] key, byte[] value) { - try { - return jredis.zscore(key, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - // - // Hash commands - // - - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Long zUnionStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Long hDel(byte[] key, byte[]... fields) { - if (fields.length > 1) { - throw new UnsupportedOperationException("hDel of multiple fields not supported"); - } - try { - return JredisUtils.toLong(jredis.hdel(key, fields[0])); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean hExists(byte[] key, byte[] field) { - try { - return jredis.hexists(key, field); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public byte[] hGet(byte[] key, byte[] field) { - try { - return jredis.hget(key, field); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Map hGetAll(byte[] key) { - try { - return jredis.hgetall(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long hIncrBy(byte[] key, byte[] field, long delta) { - throw new UnsupportedOperationException(); - } - - public Double hIncrBy(byte[] key, byte[] field, double delta) { - throw new UnsupportedOperationException(); - } - - public Set hKeys(byte[] key) { - try { - return new LinkedHashSet(jredis.hkeys(key)); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Long hLen(byte[] key) { - try { - return jredis.hlen(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public List hMGet(byte[] key, byte[]... fields) { - throw new UnsupportedOperationException(); - } - - public void hMSet(byte[] key, Map values) { - throw new UnsupportedOperationException(); - } - - public Boolean hSet(byte[] key, byte[] field, byte[] value) { - try { - return jredis.hset(key, field, value); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException(); - } - - public List hVals(byte[] key) { - try { - return jredis.hvals(key); - } catch (Exception ex) { - throw convertJredisAccessException(ex); - } - } - - // - // PubSub commands - // - - public Subscription getSubscription() { - return null; - } - - public boolean isSubscribed() { - return false; - } - - public void pSubscribe(MessageListener listener, byte[]... patterns) { - throw new UnsupportedOperationException(); - } - - public Long publish(byte[] channel, byte[] message) { - throw new UnsupportedOperationException(); - } - - public void subscribe(MessageListener listener, byte[]... channels) { - throw new UnsupportedOperationException(); - } - - // - // Geo commands - // - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[]) - */ - @Override - public Long geoAdd(byte[] key, Point point, byte[] member) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation) - */ - @Override - public Long geoAdd(byte[] key, GeoLocation location) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map) - */ - @Override - public Long geoAdd(byte[] key, Map memberCoordinateMap) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable) - */ - @Override - public Long geoAdd(byte[] key, Iterable> locations) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[]) - */ - @Override - public Distance geoDist(byte[] key, byte[] member1, byte[] member2) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric) - */ - @Override - public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][]) - */ - @Override - public List geoHash(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][]) - */ - @Override - public List geoPos(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadius(byte[], org.springframework.data.geo.Circle) - */ - @Override - public GeoResults> geoRadius(byte[] key, Circle within) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs) - */ - @Override - public GeoResults> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], double) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, double radius) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], org.springframework.data.geo.Distance) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, Distance radius) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, Distance radius, - GeoRadiusCommandArgs args) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][]) - */ - @Override - public Long geoRemove(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - // - // Scripting commands - // - - public void scriptFlush() { - throw new UnsupportedOperationException(); - } - - public void scriptKill() { - throw new UnsupportedOperationException(); - } - - public String scriptLoad(byte[] script) { - throw new UnsupportedOperationException(); - } - - public List scriptExists(String... scriptSha1) { - throw new UnsupportedOperationException(); - } - - public T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - throw new UnsupportedOperationException(); - } - - public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - throw new UnsupportedOperationException(); - } - - public T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#time() - */ - @Override - public Long time() { - throw new UnsupportedOperationException("The 'TIME' command is not supported by the JRedis driver."); - } - - @Override - public void killClient(String host, int port) { - throw new UnsupportedOperationException("The 'CLIENT KILL' command is not supported by the JRedis driver."); - } - - @Override - public void setClientName(byte[] name) { - throw new UnsupportedOperationException("'CLIENT SETNAME' is not supported by the JRedis driver."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int) - */ - @Override - public void slaveOf(String host, int port) { - - try { - this.jredis.slaveof(host, port); - } catch (Exception e) { - throw convertJredisAccessException(e); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#getClientName() - */ - @Override - public String getClientName() { - throw new UnsupportedOperationException("The 'CLIENT GETNAME' command is not supported by the JRedis driver."); - } - - public List getClientList() { - throw new UnsupportedOperationException(); - } - - /* - * @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne() - */ - @Override - public void slaveOfNoOne() { - - try { - this.jredis.slaveofnone(); - } catch (Exception e) { - throw convertJredisAccessException(e); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#scan(org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor scan(ScanOptions options) { - throw new UnsupportedOperationException("'SCAN' command is not supported for jredis."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor zScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'ZSCAN' command is not supported for jredis."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisSetCommands#sScan(byte[], org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor sScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'SSCAN' command is not uspported for jredis"); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisHashCommands#hscan(byte[], org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor> hScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'HSCAN' command is not uspported for jredis"); - } - - @Override - public Set zRangeByScore(byte[] key, String min, String max) { - throw new UnsupportedOperationException("'zRangeByScore' command is not uspported for jredis"); - } - - @Override - public Set zRangeByScore(byte[] key, String min, String max, long offset, long count) { - throw new UnsupportedOperationException("'zRangeByScore' command is not uspported for jredis"); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfAdd(byte[], byte[][]) - */ - @Override - public Long pfAdd(byte[] key, byte[]... values) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfCount(byte[][]) - */ - @Override - public Long pfCount(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfMerge(byte[], byte[][]) - */ - @Override - public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[]) - */ - @Override - public Set zRangeByLex(byte[] key) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for jredis."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Set zRangeByLex(byte[] key, Range range) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for jredis."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRangeByLex(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for jredis."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Set zRevRangeByScore(byte[] key, Range range) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRevRangeByScore(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRemRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Long zRemRangeByScore(byte[] key, Range range) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Set zRangeByScore(byte[] key, Range range) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRangeByScore(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#migrate(byte[], org.springframework.data.redis.connection.RedisNode, int, org.springframework.data.redis.connection.RedisServerCommands.MigrateOption) - */ - @Override - public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#migrate(byte[], org.springframework.data.redis.connection.RedisNode, int, org.springframework.data.redis.connection.RedisServerCommands.MigrateOption, long) - */ - @Override - public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java deleted file mode 100644 index 2ed153a6f..000000000 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java +++ /dev/null @@ -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 JRedis 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 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 JredisConnectionFactory instance. - */ - public JredisConnectionFactory() {} - - /** - * Constructs a new JredisConnectionFactory 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 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(); - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java deleted file mode 100644 index 7f7ddd1b8..000000000 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java +++ /dev/null @@ -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 { - - private final GenericObjectPool 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(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(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(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 { - - private final ConnectionSpec connectionSpec; - - public JredisFactory(ConnectionSpec connectionSpec) { - super(); - this.connectionSpec = connectionSpec; - } - - @Override - public void destroyObject(final PooledObject obj) throws Exception { - try { - obj.getObject().quit(); - } catch (Exception e) { - // Errors may happen if returning a broken resource - } - } - - @Override - public boolean validateObject(final PooledObject 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 wrap(JRedis obj) { - return new DefaultPooledObject(obj); - } - } - -} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java deleted file mode 100644 index 28e82df99..000000000 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java +++ /dev/null @@ -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 map) { - Properties info = new Properties(); - info.putAll(map); - return info; - } - - static Long toLong(Boolean source) { - return source ? 1l : 0l; - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/package-info.java b/src/main/java/org/springframework/data/redis/connection/jredis/package-info.java deleted file mode 100644 index a52db9646..000000000 --- a/src/main/java/org/springframework/data/redis/connection/jredis/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Connection package for JRedis library. - * @deprecated since 1.7. Will be removed in subsequent version. - */ -package org.springframework.data.redis.connection.jredis; - diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java deleted file mode 100644 index 960b1d3fd..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ /dev/null @@ -1,2844 +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.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import org.springframework.core.convert.converter.Converter; -import org.springframework.dao.DataAccessException; -import org.springframework.data.geo.Circle; -import org.springframework.data.geo.Distance; -import org.springframework.data.geo.GeoResults; -import org.springframework.data.geo.Metric; -import org.springframework.data.geo.Point; -import org.springframework.data.redis.ExceptionTranslationStrategy; -import org.springframework.data.redis.FallbackExceptionTranslationStrategy; -import org.springframework.data.redis.RedisConnectionFailureException; -import org.springframework.data.redis.connection.AbstractRedisConnection; -import org.springframework.data.redis.connection.DataType; -import org.springframework.data.redis.connection.FutureResult; -import org.springframework.data.redis.connection.MessageListener; -import org.springframework.data.redis.connection.RedisNode; -import org.springframework.data.redis.connection.RedisPipelineException; -import org.springframework.data.redis.connection.RedisSubscribedConnectionException; -import org.springframework.data.redis.connection.ReturnType; -import org.springframework.data.redis.connection.SortParameters; -import org.springframework.data.redis.connection.Subscription; -import org.springframework.data.redis.connection.convert.Converters; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.ScanOptions; -import org.springframework.data.redis.core.types.Expiration; -import org.springframework.data.redis.core.types.RedisClientInfo; -import org.springframework.util.Assert; - -import com.google.common.base.Charsets; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; - -import redis.Command; -import redis.client.RedisClient; -import redis.client.RedisClient.Pipeline; -import redis.client.RedisException; -import redis.reply.MultiBulkReply; -import redis.reply.Reply; - -/** - * {@code RedisConnection} implementation on top of spullara Redis - * Protocol library. - * - * @author Costin Leau - * @author Jennifer Hickey - * @author Christoph Strobl - * @author Thomas Darimont - * @author David Liu - * @author Ninad Divadkar - * @author Mark Paluch - * @deprecated since 1.7. Will be removed in subsequent version. - */ -@Deprecated -public class SrpConnection extends AbstractRedisConnection { - - private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy( - SrpConverters.exceptionConverter()); - - private static final Object[] EMPTY_PARAMS_ARRAY = new Object[0]; - private static final byte[] WITHSCORES = "WITHSCORES".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); - - private final RedisClient client; - private final BlockingQueue queue; - - private boolean isClosed = false; - private boolean isMulti = false; - private boolean pipelineRequested = false; - private Pipeline pipeline; - private PipelineTracker callback; - private PipelineTracker txTracker; - private volatile SrpSubscription subscription; - private boolean convertPipelineAndTxResults = true; - - @SuppressWarnings("rawtypes") - private class PipelineTracker implements FutureCallback { - - private final List results = Collections.synchronizedList(new ArrayList()); - private final Queue futureResults = new LinkedList(); - private boolean convertResults; - - public PipelineTracker(boolean convertResults) { - this.convertResults = convertResults; - } - - public void onSuccess(Reply result) { - results.add(result.data()); - } - - public void onFailure(Throwable t) { - results.add(t); - } - - @SuppressWarnings("unchecked") - public List complete() { - int txResults = 0; - List> futures = new ArrayList>(); - for (FutureResult future : futureResults) { - if (future instanceof SrpTxResult) { - txResults++; - } else { - ListenableFuture f = (ListenableFuture) future.getResultHolder(); - futures.add(f); - } - } - try { - Futures.successfulAsList(futures).get(); - } catch (Exception ex) { - // ignore - } - if (futureResults.size() != results.size() + txResults) { - throw new RedisPipelineException( - "Received a different number of results than expected. Expected: " + futureResults.size(), results); - } - List convertedResults = new ArrayList(); - - int i = 0; - for (FutureResult future : futureResults) { - if (future instanceof SrpTxResult) { - PipelineTracker txTracker = ((SrpTxResult) future).getResultHolder(); - if (txTracker != null) { - convertedResults.add(getPipelinedResults(txTracker, true)); - } else { - convertedResults.add(null); - } - } else { - Object result = results.get(i); - if (result instanceof Exception || !convertResults) { - convertedResults.add(result); - } else if (!(future.isStatus())) { - convertedResults.add(future.convert(result)); - } - i++; - } - } - return convertedResults; - } - - public void addCommand(FutureResult result) { - futureResults.add(result); - if (!(result instanceof SrpTxResult) && result.getResultHolder() != null) { - Futures.addCallback(((SrpGenericResult) result).getResultHolder(), this); - } - } - - public void close() { - results.clear(); - futureResults.clear(); - } - } - - @SuppressWarnings("rawtypes") - private class SrpGenericResult extends FutureResult> { - public SrpGenericResult(ListenableFuture resultHolder, Converter converter) { - super(resultHolder, converter); - } - - public SrpGenericResult(ListenableFuture resultHolder) { - super(resultHolder); - } - - @Override - public Object get() { - throw new UnsupportedOperationException(); - } - } - - @SuppressWarnings("rawtypes") - private class SrpResult extends SrpGenericResult { - public SrpResult(ListenableFuture> resultHolder, Converter converter) { - super(resultHolder, converter); - } - - public SrpResult(ListenableFuture resultHolder) { - super(resultHolder); - } - } - - private class SrpStatusResult extends SrpResult { - @SuppressWarnings("rawtypes") - public SrpStatusResult(ListenableFuture resultHolder) { - super(resultHolder); - setStatus(true); - } - } - - private class SrpTxResult extends FutureResult { - public SrpTxResult(PipelineTracker txTracker) { - super(txTracker); - } - - public List get() { - if (resultHolder == null) { - return null; - } - return resultHolder.complete(); - } - } - - SrpConnection(RedisClient client) { - - Assert.notNull(client); - this.client = client; - this.queue = new ArrayBlockingQueue(50); - } - - public SrpConnection(String host, int port, BlockingQueue queue) { - try { - this.client = new RedisClient(host, port); - this.queue = queue; - } catch (IOException e) { - throw new RedisConnectionFailureException("Could not connect", e); - } catch (RedisException e) { - throw new RedisConnectionFailureException("Could not connect", e); - } - } - - public SrpConnection(String host, int port, String password, BlockingQueue queue) { - this(host, port, queue); - try { - this.client.auth(password); - } catch (RedisException e) { - throw new RedisConnectionFailureException("Could not connect", e); - } - } - - protected DataAccessException convertSrpAccessException(Exception ex) { - return EXCEPTION_TRANSLATION.translate(ex); - } - - public Object execute(String command, byte[]... args) { - Assert.hasText(command, "a valid command needs to be specified"); - try { - String name = command.trim().toUpperCase(); - Command cmd = new Command(name.getBytes(Charsets.UTF_8), args); - if (isPipelined()) { - pipeline(new SrpResult(client.pipeline(name, cmd))); - return null; - } - return client.execute(name, cmd).data(); - } catch (RedisException ex) { - throw convertSrpAccessException(ex); - } - } - - public void close() throws DataAccessException { - - super.close(); - isClosed = true; - queue.remove(this); - - if (subscription != null) { - if (subscription.isAlive()) { - subscription.doClose(); - } - subscription = null; - } - - try { - client.close(); - } catch (IOException ex) { - throw convertSrpAccessException(ex); - } - } - - public boolean isClosed() { - return isClosed; - } - - public RedisClient getNativeConnection() { - return client; - } - - public boolean isQueueing() { - return isMulti; - } - - public boolean isPipelined() { - return pipelineRequested || (txTracker != null); - } - - public void openPipeline() { - pipelineRequested = true; - initPipeline(); - } - - public List sort(byte[] key, SortParameters params) { - - Object[] sort = sortParams(params); - - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.sort(key, sort), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList((Reply[]) client.sort(key, sort).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sort(byte[] key, SortParameters params, byte[] sortKey) { - - Object[] sort = sortParams(params, sortKey); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sort(key, sort))); - return null; - } - return ((Long) client.sort(key, sort).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long dbSize() { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.dbsize())); - return null; - } - return client.dbsize().data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void flushDb() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.flushdb())); - return; - } - client.flushdb(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void flushAll() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.flushall())); - return; - } - client.flushall(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void bgSave() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.bgsave())); - return; - } - client.bgsave(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void bgReWriteAof() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.bgrewriteaof())); - return; - } - client.bgrewriteaof(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /** - * @deprecated As of 1.3, use {@link #bgReWriteAof}. - */ - @Deprecated - public void bgWriteAof() { - bgReWriteAof(); - } - - public void save() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.save())); - return; - } - client.save(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List getConfig(String param) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.config_get(param), SrpConverters.repliesToStringList())); - return null; - } - return SrpConverters.toStringList(client.config_get(param).data().toString()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Properties info() { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.info(null), SrpConverters.bytesToProperties())); - return null; - } - return SrpConverters.toProperties(client.info(null).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Properties info(String section) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.info(section), SrpConverters.bytesToProperties())); - return null; - } - return SrpConverters.toProperties(client.info(section).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long lastSave() { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lastsave())); - return null; - } - return client.lastsave().data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void setConfig(String param, String value) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.config_set(param, value))); - return; - } - client.config_set(param, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void resetConfigStats() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.config_resetstat())); - return; - } - client.config_resetstat(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void shutdown() { - byte[] save = "SAVE".getBytes(Charsets.UTF_8); - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.shutdown(save, null))); - return; - } - client.shutdown(save, null); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption) - */ - @Override - public void shutdown(ShutdownOption option) { - - if (option == null) { - shutdown(); - return; - } - - byte[] save = option.name().getBytes(Charsets.UTF_8); - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.shutdown(save, null))); - return; - } - client.shutdown(save, null); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - - } - - public byte[] echo(byte[] message) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.echo(message))); - return null; - } - return client.echo(message).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public String ping() { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.ping())); - return null; - } - return client.ping().data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long del(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.del((Object[]) keys))); - return null; - } - return client.del((Object[]) keys).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void discard() { - isMulti = false; - try { - // discard tracked futures - txTracker = null; - client.discard(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List exec() { - isMulti = false; - try { - Future exec = client.exec(); - // Need to wait on execution or subsequent non-pipelined calls may read exec results - boolean resultsSet = exec.get(); - if (!resultsSet) { - // This is the case where a nil MultiBulk Reply was returned b/c watched variable modified - if (pipelineRequested) { - pipeline(new SrpTxResult(null)); - } - return null; - } - if (pipelineRequested) { - pipeline(new SrpTxResult(txTracker)); - return null; - } - return closeTransaction(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } finally { - txTracker = null; - } - } - - public Boolean exists(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.exists(key), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.exists(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean expire(byte[] key, long seconds) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.expire(key, seconds), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.expire(key, seconds).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean expireAt(byte[] key, long unixTime) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.expireat(key, unixTime), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.expireat(key, unixTime).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean pExpire(byte[] key, long millis) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.pexpire(key, millis), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.pexpire(key, millis).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.pexpireat(key, unixTimeInMillis), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.pexpireat(key, unixTimeInMillis).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set keys(byte[] pattern) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.keys(pattern), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.keys(pattern).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void multi() { - if (isQueueing()) { - return; - } - isMulti = true; - initTxTracker(); - try { - client.multi(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean persist(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.persist(key), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.persist(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean move(byte[] key, int dbIndex) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.move(key, dbIndex), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.move(key, dbIndex).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] randomKey() { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.randomkey())); - return null; - } - return client.randomkey().data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void rename(byte[] oldName, byte[] newName) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.rename(oldName, newName))); - return; - } - client.rename(oldName, newName); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean renameNX(byte[] oldName, byte[] newName) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.renamenx(oldName, newName), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.renamenx(oldName, newName).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void select(int dbIndex) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.select(dbIndex))); - return; - } - client.select(dbIndex); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[]) - */ - @Override - public Long ttl(byte[] key) { - - Assert.notNull(key, "Key must not be null!"); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.ttl(key))); - return null; - } - - return client.ttl(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[], java.util.concurrent.TimeUnit) - */ - @Override - public Long ttl(byte[] key, TimeUnit timeUnit) { - - Assert.notNull(key, "Key must not be null!"); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.ttl(key), Converters.secondsToTimeUnit(timeUnit))); - return null; - } - return Converters.secondsToTimeUnit(client.ttl(key).data(), timeUnit); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[]) - */ - @Override - public Long pTtl(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.pttl(key))); - return null; - } - return client.pttl(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[], java.util.concurrent.TimeUnit) - */ - @Override - public Long pTtl(byte[] key, TimeUnit timeUnit) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.pttl(key), Converters.millisecondsToTimeUnit(timeUnit))); - return null; - } - return Converters.millisecondsToTimeUnit(client.pttl(key).data(), timeUnit); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] dump(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.dump(key))); - return null; - } - return client.dump(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.restore(key, ttlInMillis, serializedValue))); - return; - } - client.restore(key, ttlInMillis, serializedValue); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public DataType type(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.type(key), SrpConverters.stringToDataType())); - return null; - } - return SrpConverters.toDataType(client.type(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void unwatch() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.unwatch())); - return; - } - client.unwatch(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void watch(byte[]... keys) { - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.watch((Object[]) keys))); - return; - } else { - client.watch((Object[]) keys); - } - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // String commands - // - - public byte[] get(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.get(key))); - return null; - } - - return client.get(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void set(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.set(key, value))); - return; - } - client.set(key, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOption) - */ - @Override - public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { - throw new UnsupportedOperationException( - "SET with options is not supported for Srp. Please use SETNX, SETEX, PSETEX."); - } - - public byte[] getSet(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.getset(key, value))); - return null; - } - return client.getset(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long append(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.append(key, value))); - return null; - } - return client.append(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List mGet(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.mget((Object[]) keys), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.mget((Object[]) keys).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void mSet(Map tuples) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.mset((Object[]) SrpConverters.toByteArrays(tuples)))); - return; - } - client.mset((Object[]) SrpConverters.toByteArrays(tuples)); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean mSetNX(Map tuples) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.msetnx((Object[]) SrpConverters.toByteArrays(tuples)), - SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.msetnx((Object[]) SrpConverters.toByteArrays(tuples)).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void setEx(byte[] key, long time, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.setex(key, time, value))); - return; - } - client.setex(key, time, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[]) - */ - @Override - public void pSetEx(byte[] key, long milliseconds, byte[] value) { - - try { - if (isPipelined()) { - doPipelined(pipeline.psetex(key, milliseconds, value)); - return; - } - client.psetex(key, milliseconds, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean setNX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.setnx(key, value), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.setnx(key, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] getRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.getrange(key, start, end))); - return null; - } - return client.getrange(key, start, end).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long decr(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.decr(key))); - return null; - } - return client.decr(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long decrBy(byte[] key, long value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.decrby(key, value))); - return null; - } - return client.decrby(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long incr(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.incr(key))); - return null; - } - return client.incr(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long incrBy(byte[] key, long value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.incrby(key, value))); - return null; - } - return client.incrby(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Double incrBy(byte[] key, double value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.incrbyfloat(key, value), SrpConverters.bytesToDouble())); - return null; - } - return SrpConverters.toDouble(client.incrbyfloat(key, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean getBit(byte[] key, long offset) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.getbit(key, offset), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.getbit(key, offset).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean setBit(byte[] key, long offset, boolean value) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.setbit(key, offset, SrpConverters.toBit(value)), - SrpConverters.longToBooleanConverter())); - return null; - } - return SrpConverters.toBoolean(client.setbit(key, offset, SrpConverters.toBit(value))); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void setRange(byte[] key, byte[] value, long start) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.setrange(key, start, value))); - return; - } - client.setrange(key, start, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long strLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.strlen(key))); - return null; - } - return client.strlen(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long bitCount(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.bitcount(key, 0, -1))); - return null; - } - return client.bitcount(key, 0, -1).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long bitCount(byte[] key, long begin, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.bitcount(key, begin, end))); - return null; - } - return client.bitcount(key, begin, end).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - if (op == BitOperation.NOT && keys.length > 1) { - throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); - } - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.bitop(SrpConverters.toBytes(op), destination, (Object[]) keys))); - return null; - } - return client.bitop(SrpConverters.toBytes(op), destination, (Object[]) keys).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // List commands - // - - public Long lPush(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lpush(key, (Object[]) values))); - return null; - } - return client.lpush(key, (Object[]) values).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long rPush(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.rpush(key, (Object[]) values))); - return null; - } - return client.rpush(key, (Object[]) values).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List bLPop(int timeout, byte[]... keys) { - Object[] args = popArgs(timeout, keys); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.blpop(args), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.blpop(args).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List bRPop(int timeout, byte[]... keys) { - Object[] args = popArgs(timeout, keys); - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.brpop(args), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.brpop(args).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] lIndex(byte[] key, long index) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lindex(key, index))); - return null; - } - return client.lindex(key, index).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.linsert(key, SrpConverters.toBytes(where), pivot, value))); - return null; - } - return client.linsert(key, SrpConverters.toBytes(where), pivot, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long lLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.llen(key))); - return null; - } - return client.llen(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] lPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lpop(key))); - return null; - } - return client.lpop(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List lRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lrange(key, start, end), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.lrange(key, start, end).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long lRem(byte[] key, long count, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lrem(key, count, value))); - return null; - } - return client.lrem(key, count, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void lSet(byte[] key, long index, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.lset(key, index, value))); - return; - } - client.lset(key, index, value); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void lTrim(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.ltrim(key, start, end))); - return; - } - client.ltrim(key, start, end); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] rPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.rpop(key))); - return null; - } - return client.rpop(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.rpoplpush(srcKey, dstKey))); - return null; - } - return client.rpoplpush(srcKey, dstKey).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.brpoplpush(srcKey, dstKey, timeout))); - return null; - } - return (byte[]) client.brpoplpush(srcKey, dstKey, timeout).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long lPushX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.lpushx(key, value))); - return null; - } - return client.lpushx(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long rPushX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.rpushx(key, value))); - return null; - } - return client.rpushx(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // Set commands - // - - public Long sAdd(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sadd(key, (Object[]) values))); - return null; - } - return client.sadd(key, (Object[]) values).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sCard(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.scard(key))); - return null; - } - return client.scard(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set sDiff(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sdiff((Object[]) keys), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.sdiff((Object[]) keys).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sDiffStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sdiffstore(destKey, (Object[]) keys))); - return null; - } - return client.sdiffstore(destKey, (Object[]) keys).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set sInter(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sinter((Object[]) keys), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.sinter((Object[]) keys).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sInterStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sinterstore(destKey, (Object[]) keys))); - return null; - } - return client.sinterstore(destKey, (Object[]) keys).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean sIsMember(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sismember(key, value), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.sismember(key, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set sMembers(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.smembers(key), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.smembers(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.smove(srcKey, destKey, value), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.smove(srcKey, destKey, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] sPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.spop(key))); - return null; - } - return client.spop(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] sRandMember(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.srandmember(key, null))); - return null; - } - return (byte[]) client.srandmember(key, null).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List sRandMember(byte[] key, long count) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.srandmember(key, count), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(((MultiBulkReply) client.srandmember(key, count)).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sRem(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.srem(key, (Object[]) values))); - return null; - } - return client.srem(key, (Object[]) values).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set sUnion(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sunion((Object[]) keys), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.sunion((Object[]) keys).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long sUnionStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.sunionstore(destKey, (Object[]) keys))); - return null; - } - return client.sunionstore(destKey, (Object[]) keys).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // ZSet commands - // - - public Boolean zAdd(byte[] key, double score, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zadd(new Object[] { key, score, value }), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.zadd(new Object[] { key, score, value }).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zAdd(byte[] key, Set tuples) { - try { - List args = new ArrayList(); - args.add(key); - args.addAll(SrpConverters.toObjects(tuples)); - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zadd(args.toArray()))); - return null; - } - return client.zadd(args.toArray()).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zCard(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zcard(key))); - return null; - } - return client.zcard(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zCount(byte[] key, double min, double max) { - return zCount(key, new Range().gte(min).lte(max)); - } - - @Override - public Long zCount(byte[] key, Range range) { - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zcount(key, min, max))); - return null; - } - return client.zcount(key, min, max).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Double zIncrBy(byte[] key, double increment, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zincrby(key, increment, value), SrpConverters.bytesToDouble())); - return null; - } - return SrpConverters.toDouble(client.zincrby(key, increment, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Long zInterStore(byte[] destKey, byte[]... sets) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zinterstore(destKey, sets.length, (Object[]) sets))); - return null; - } - return client.zinterstore(destKey, sets.length, (Object[]) sets).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrange(key, start, end, null), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrange(key, start, end, null).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRangeWithScores(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrange(key, start, end, WITHSCORES), SrpConverters.repliesToTupleSet())); - return null; - } - return SrpConverters.toTupleSet(client.zrange(key, start, end, WITHSCORES).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRangeByScore(byte[] key, double min, double max) { - return zRangeByScore(key, new Range().gte(min).lte(max)); - } - - @Override - public Set zRangeByScore(byte[] key, Range range) { - return zRangeByScore(key, range, null); - } - - @Override - public Set zRangeByScore(byte[] key, Range range, Limit limit) { - - Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!"); - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - Object[] params = limit != null ? limitParams(limit.getOffset(), limit.getCount()) : EMPTY_PARAMS_ARRAY; - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, null, params), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrangebyscore(key, min, max, null, params).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { - return zRangeByScoreWithScores(key, new Range().gte(min).lte(max)); - } - - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range) { - return zRangeByScoreWithScores(key, range, null); - } - - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - - Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!"); - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - Object[] params = limit != null ? limitParams(limit.getOffset(), limit.getCount()) : EMPTY_PARAMS_ARRAY; - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, WITHSCORES, params), - SrpConverters.repliesToTupleSet())); - return null; - } - return SrpConverters.toTupleSet(client.zrangebyscore(key, min, max, WITHSCORES, params).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRevRangeWithScores(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrange(key, start, end, WITHSCORES), SrpConverters.repliesToTupleSet())); - return null; - } - return SrpConverters.toTupleSet(client.zrevrange(key, start, end, WITHSCORES).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @Override - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - - return zRangeByScore(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } - - @Override - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - - return zRangeByScoreWithScores(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } - - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { - return zRevRangeByScore(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - - } - - @Override - public Set zRevRangeByScore(byte[] key, double min, double max) { - return zRevRangeByScore(key, new Range().gte(min).lte(max)); - } - - @Override - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } - - @Override - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { - return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max)); - } - - @Override - public Set zRevRangeByScore(byte[] key, Range range) { - return zRevRangeByScore(key, range, null); - } - - @Override - public Set zRevRangeByScore(byte[] key, Range range, Limit limit) { - - Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!"); - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - Object[] params = limit != null ? limitParams(limit.getOffset(), limit.getCount()) : EMPTY_PARAMS_ARRAY; - - try { - if (isPipelined()) { - pipeline( - new SrpResult(pipeline.zrevrangebyscore(key, max, min, null, params), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrevrangebyscore(key, max, min, null, params).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range) { - return zRevRangeByScoreWithScores(key, range, null); - } - - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - - Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!"); - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - Object[] params = limit != null ? limitParams(limit.getOffset(), limit.getCount()) : EMPTY_PARAMS_ARRAY; - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, WITHSCORES, params), - SrpConverters.repliesToTupleSet())); - return null; - } - return SrpConverters.toTupleSet(client.zrevrangebyscore(key, max, min, WITHSCORES, params).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zRank(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrank(key, value))); - return null; - } - return (Long) client.zrank(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zRem(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrem(key, (Object[]) values))); - return null; - } - return client.zrem(key, (Object[]) values).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zRemRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zremrangebyrank(key, start, end))); - return null; - } - return client.zremrangebyrank(key, start, end).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zRemRangeByScore(byte[] key, double min, double max) { - return zRemRangeByScore(key, new Range().gte(min).lte(max)); - } - - @Override - public Long zRemRangeByScore(byte[] key, Range range) { - - byte[] min = SrpConverters.boundaryToBytesForZRange(range.getMin(), SrpConverters.toBytes("-inf")); - byte[] max = SrpConverters.boundaryToBytesForZRange(range.getMax(), SrpConverters.toBytes("+inf")); - - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zremrangebyscore(key, min, max))); - return null; - } - return client.zremrangebyscore(key, min, max).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set zRevRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrange(key, start, end, null), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrevrange(key, start, end, null).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zRevRank(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrank(key, value))); - return null; - } - return (Long) client.zrevrank(key, value).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Double zScore(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zscore(key, value), SrpConverters.bytesToDouble())); - return null; - } - return SrpConverters.toDouble(client.zscore(key, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - public Long zUnionStore(byte[] destKey, byte[]... sets) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zunionstore(destKey, sets.length, (Object[]) sets))); - return null; - } - return client.zunionstore(destKey, sets.length, (Object[]) sets).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // Hash commands - // - - public Boolean hSet(byte[] key, byte[] field, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hset(key, field, value), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.hset(key, field, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hsetnx(key, field, value), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.hsetnx(key, field, value).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long hDel(byte[] key, byte[]... fields) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hdel(key, (Object[]) fields))); - return null; - } - return client.hdel(key, (Object[]) fields).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Boolean hExists(byte[] key, byte[] field) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hexists(key, field), SrpConverters.longToBoolean())); - return null; - } - return SrpConverters.toBoolean(client.hexists(key, field).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public byte[] hGet(byte[] key, byte[] field) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hget(key, field))); - return null; - } - return client.hget(key, field).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Map hGetAll(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hgetall(key), SrpConverters.repliesToBytesMap())); - return null; - } - return SrpConverters.toBytesMap(client.hgetall(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long hIncrBy(byte[] key, byte[] field, long delta) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hincrby(key, field, delta))); - return null; - } - return client.hincrby(key, field, delta).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Double hIncrBy(byte[] key, byte[] field, double delta) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hincrbyfloat(key, field, delta), SrpConverters.bytesToDouble())); - return null; - } - return SrpConverters.toDouble(client.hincrbyfloat(key, field, delta).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Set hKeys(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hkeys(key), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.hkeys(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Long hLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hlen(key))); - return null; - } - return client.hlen(key).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List hMGet(byte[] key, byte[]... fields) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hmget(key, (Object[]) fields), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.hmget(key, (Object[]) fields).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void hMSet(byte[] key, Map tuple) { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.hmset(key, (Object[]) SrpConverters.toByteArrays(tuple)))); - return; - } - client.hmset(key, (Object[]) SrpConverters.toByteArrays(tuple)); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List hVals(byte[] key) { - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.hvals(key), SrpConverters.repliesToBytesList())); - return null; - } - return SrpConverters.toBytesList(client.hvals(key).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - // - // Scripting commands - // - - public void scriptFlush() { - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.script_flush())); - return; - } - client.script_flush(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void scriptKill() { - if (isQueueing()) { - throw new UnsupportedOperationException("Script kill not permitted in a transaction"); - } - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.script_kill())); - return; - } - client.script_kill(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public String scriptLoad(byte[] script) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.script_load(script), SrpConverters.bytesToString())); - return null; - } - return SrpConverters.toString((byte[]) client.script_load(script).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public List scriptExists(String... scriptSha1) { - try { - if (isPipelined()) { - pipeline( - new SrpGenericResult(pipeline.script_exists((Object[]) scriptSha1), SrpConverters.repliesToBooleanList())); - return null; - } - return SrpConverters.toBooleanList(((MultiBulkReply) client.script_exists_((Object[]) scriptSha1)).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @SuppressWarnings("unchecked") - public T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.eval(script, numKeys, (Object[]) keysAndArgs), - new SrpScriptReturnConverter(returnType))); - return null; - } - return (T) new SrpScriptReturnConverter(returnType) - .convert(client.eval(script, numKeys, (Object[]) keysAndArgs).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @SuppressWarnings("unchecked") - public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - try { - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.evalsha(scriptSha1, numKeys, (Object[]) keysAndArgs), - new SrpScriptReturnConverter(returnType))); - return null; - } - return (T) new SrpScriptReturnConverter(returnType) - .convert(client.evalsha(scriptSha1, numKeys, (Object[]) keysAndArgs).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - return evalSha(SrpConverters.toString(scriptSha1), returnType, numKeys, keysAndArgs); - } - - // - // Pub/Sub functionality - // - - public Long publish(byte[] channel, byte[] message) { - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - try { - if (isPipelined()) { - pipeline(new SrpResult(pipeline.publish(channel, message))); - return null; - } - return client.publish(channel, message).data(); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public Subscription getSubscription() { - return subscription; - } - - public boolean isSubscribed() { - return (subscription != null && subscription.isAlive()); - } - - public void pSubscribe(MessageListener listener, byte[]... patterns) { - checkSubscription(); - - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - if (isPipelined()) { - throw new UnsupportedOperationException(); - } - try { - subscription = new SrpSubscription(listener, client); - subscription.pSubscribe(patterns); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - public void subscribe(MessageListener listener, byte[]... channels) { - checkSubscription(); - - if (isPipelined()) { - throw new UnsupportedOperationException(); - } - try { - subscription = new SrpSubscription(listener, client); - subscription.subscribe(channels); - - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[]) - */ - @Override - public Long geoAdd(byte[] key, Point point, byte[] member) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation) - */ - @Override - public Long geoAdd(byte[] key, GeoLocation location) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map) - */ - @Override - public Long geoAdd(byte[] key, Map memberCoordinateMap) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable) - */ - @Override - public Long geoAdd(byte[] key, Iterable> locations) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[]) - */ - @Override - public Distance geoDist(byte[] key, byte[] member1, byte[] member2) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric) - */ - @Override - public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][]) - */ - @Override - public List geoHash(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][]) - */ - @Override - public List geoPos(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadius(byte[], org.springframework.data.geo.Circle) - */ - @Override - public GeoResults> geoRadius(byte[] key, Circle within) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs) - */ - @Override - public GeoResults> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], double) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, double radius) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], org.springframework.data.geo.Distance) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, Distance radius) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs) - */ - @Override - public GeoResults> geoRadiusByMember(byte[] key, byte[] member, Distance radius, - GeoRadiusCommandArgs param) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][]) - */ - @Override - public Long geoRemove(byte[] key, byte[]... members) { - throw new UnsupportedOperationException(); - } - - /** - * Specifies if pipelined results should be converted to the expected data type. If false, results of - * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver - * - * @param convertPipelineAndTxResults Whether or not to convert pipeline results - */ - public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { - this.convertPipelineAndTxResults = convertPipelineAndTxResults; - } - - private void checkSubscription() { - if (isSubscribed()) { - throw new RedisSubscribedConnectionException( - "Connection already subscribed; use the connection Subscription to cancel or add new channels"); - } - } - - @SuppressWarnings("rawtypes") - private void doPipelined(ListenableFuture listenableFuture) { - pipeline(new SrpStatusResult(listenableFuture)); - } - - // processing method that adds a listener to the future in order to track down the results and close the pipeline - private void pipeline(FutureResult future) { - if (isQueueing()) { - txTracker.addCommand(future); - } else { - callback.addCommand(future); - } - } - - private void initPipeline() { - if (pipeline == null) { - callback = new PipelineTracker(convertPipelineAndTxResults); - pipeline = client.pipeline(); - } - } - - private void initTxTracker() { - if (txTracker == null) { - txTracker = new PipelineTracker(convertPipelineAndTxResults); - } - initPipeline(); - } - - public List closePipeline() { - pipelineRequested = false; - List results = Collections.emptyList(); - if (pipeline != null) { - pipeline = null; - results = getPipelinedResults(callback, true); - callback.close(); - callback = null; - } - return results; - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#time() - */ - @Override - public Long time() { - - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.time(), SrpConverters.repliesToTimeAsLong())); - return null; - } - - MultiBulkReply reply = this.client.time(); - Assert.notNull(reply, "Received invalid result from server. MultiBulkReply must not be empty."); - - return SrpConverters.toTimeAsLong(reply.data()); - } - - @Override - public void killClient(String host, int port) { - - Assert.hasText(host, "Host for 'CLIENT KILL' must not be 'null' or 'empty'."); - - String client = String.format("%s:%s", host, port); - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.client_kill(client))); - return; - } - - this.client.client_kill(client); - } catch (Exception e) { - throw convertSrpAccessException(e); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#setClientName(byte[]) - */ - @Override - public void setClientName(byte[] name) { - - try { - - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.client_setname(name))); - return; - } - - this.client.client_setname(name); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int) - */ - @Override - public void slaveOf(String host, int port) { - - Assert.hasText(host, "Host must not be null for 'SLAVEOF' command."); - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.slaveof(host, port))); - return; - } - client.slaveof(host, port); - } catch (Exception e) { - throw convertSrpAccessException(e); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#getClientName() - */ - @Override - public String getClientName() { - - try { - - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.client_getname(), SrpConverters.replyToString())); - return null; - } - - return SrpConverters.toString(client.client_getname()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @Override - public List getClientList() { - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.client_list(), SrpConverters.replyToListOfRedisClientInfo())); - return null; - } - - return SrpConverters.toListOfRedisClientInformation(this.client.client_list()); - } - - /* - * @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne() - */ - @Override - public void slaveOfNoOne() { - - try { - if (isPipelined()) { - pipeline(new SrpStatusResult(pipeline.slaveof("NO", "ONE"))); - return; - } - client.slaveof("NO", "ONE"); - } catch (Exception e) { - throw convertSrpAccessException(e); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisKeyCommands#scan(org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor scan(ScanOptions options) { - throw new UnsupportedOperationException("'SCAN' command is not supported for Srp."); - } - - @Override - public Cursor zScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'ZSCAN' command is not supported for Srp."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisSetCommands#sScan(byte[], org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor sScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'SSCAN' command is not supported for Srp."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisHashCommands#hscan(byte[], org.springframework.data.redis.core.ScanOptions) - */ - @Override - public Cursor> hScan(byte[] key, ScanOptions options) { - throw new UnsupportedOperationException("'HSCAN' command is not supported for Srp."); - } - - private List closeTransaction() { - List results = Collections.emptyList(); - if (txTracker != null) { - results = getPipelinedResults(txTracker, false); - txTracker.close(); - txTracker = null; - } - return results; - } - - private List getPipelinedResults(PipelineTracker tracker, boolean throwPipelineException) { - List execute = new ArrayList(tracker.complete()); - if (execute != null && !execute.isEmpty()) { - Exception cause = null; - for (int i = 0; i < execute.size(); i++) { - Object object = execute.get(i); - if (object instanceof Exception) { - DataAccessException dataAccessException = convertSrpAccessException((Exception) object); - if (cause == null) { - cause = dataAccessException; - } - execute.set(i, dataAccessException); - } - } - if (cause != null) { - if (throwPipelineException) { - throw new RedisPipelineException(cause, execute); - } else { - throw convertSrpAccessException(cause); - } - } - - return execute; - } - return Collections.emptyList(); - } - - private Object[] popArgs(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; - } - - private 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) }; - } - - private byte[] limit(long offset, long count) { - return ("LIMIT " + offset + " " + count).getBytes(Charsets.UTF_8); - } - - private Object[] sortParams(SortParameters params) { - return sortParams(params, null); - } - - private Object[] sortParams(SortParameters params, byte[] sortKey) { - List arrays = new ArrayList(); - 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(); - } - - @Override - public Set zRangeByScore(byte[] key, String min, String max) { - - try { - String keyStr = new String(key, "UTF-8"); - if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, EMPTY_PARAMS_ARRAY), - SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, EMPTY_PARAMS_ARRAY).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - @Override - public Set zRangeByScore(byte[] key, String min, String max, long offset, long count) { - - try { - String keyStr = new String(key, "UTF-8"); - Object[] limit = limitParams(offset, count); - if (isPipelined()) { - pipeline( - new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, limit), SrpConverters.repliesToBytesSet())); - return null; - } - return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, limit).data()); - } catch (Exception ex) { - throw convertSrpAccessException(ex); - } - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfAdd(byte[], byte[][]) - */ - @Override - public Long pfAdd(byte[] key, byte[]... values) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfCount(byte[][]) - */ - @Override - public Long pfCount(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.HyperLogLogCommands#pfMerge(byte[], byte[][]) - */ - @Override - public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[]) - */ - @Override - public Set zRangeByLex(byte[] key) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for srp."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) - */ - @Override - public Set zRangeByLex(byte[] key, Range range) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for srp."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRangeByLex(byte[] key, Range range, Limit limit) { - throw new UnsupportedOperationException("ZRANGEBYLEX is no supported for srp."); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#migrate(byte[], org.springframework.data.redis.connection.RedisNode, int, org.springframework.data.redis.connection.RedisServerCommands.MigrateOption) - */ - @Override - public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) { - throw new UnsupportedOperationException(); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#migrate(byte[], org.springframework.data.redis.connection.RedisNode, int, org.springframework.data.redis.connection.RedisServerCommands.MigrateOption, long) - */ - @Override - public void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java deleted file mode 100644 index f0926c620..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java +++ /dev/null @@ -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 Redis Protocol 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 trackedConnections = new ArrayBlockingQueue(50); - private boolean convertPipelineAndTxResults = true; - private String password; - - /** - * Constructs a new SRedisConnectionFactory instance with default settings. - */ - public SrpConnectionFactory() {} - - /** - * Constructs a new SRedisConnectionFactory 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(); - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java deleted file mode 100644 index dc33953f0..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java +++ /dev/null @@ -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> REPLIES_TO_BYTES_LIST; - private static final Converter> REPLIES_TO_BYTES_SET; - private static final Converter> REPLIES_TO_TUPLE_SET; - private static final Converter> REPLIES_TO_BYTES_MAP; - private static final Converter> REPLIES_TO_BOOLEAN_LIST; - private static final Converter> REPLIES_TO_STRING_LIST; - private static final Converter REPLY_TO_STRING; - private static final Converter BYTES_TO_PROPERTIES; - private static final Converter BYTES_TO_STRING; - private static final Converter BYTES_TO_DOUBLE; - private static final Converter REPLIES_TO_TIME_AS_LONG; - private static final Converter> REPLY_T0_LIST_OF_CLIENT_INFO; - private static final Converter> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter(); - private static final Converter> BYTEARRAY_T0_LIST_OF_CLIENT_INFO; - private static final Converter INTEGER_REPLY_TO_BOOLEAN; - private static final Converter LONG_TO_BOOLEAN = new LongToBooleanConverter(); - private static final Converter EXCEPTION_CONVERTER; - - static { - - REPLIES_TO_BYTES_LIST = new Converter>() { - public List convert(Reply[] replies) { - if (replies == null) { - return null; - } - List list = new ArrayList(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>() { - public Set convert(Reply[] source) { - return source != null ? new LinkedHashSet(SrpConverters.toBytesList(source)) : null; - } - }; - - BYTES_TO_PROPERTIES = new Converter() { - public Properties convert(byte[] source) { - return source != null ? SrpConverters.toProperties(new String(source, Charsets.UTF_8)) : null; - } - }; - - BYTES_TO_DOUBLE = new Converter() { - 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() { - - @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 serverTimeInformation = REPLIES_TO_STRING_LIST.convert(reply); - - return Converters.toTimeMillis(serverTimeInformation.get(0), serverTimeInformation.get(1)); - } - - }; - - REPLIES_TO_TUPLE_SET = new Converter>() { - public Set convert(Reply[] byteArrays) { - if (byteArrays == null) { - return null; - } - Set tuples = new LinkedHashSet(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>() { - public Map convert(Reply[] byteArrays) { - if (byteArrays == null) { - return null; - } - Map map = new LinkedHashMap(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() { - public String convert(byte[] data) { - return data != null ? new String((byte[]) data, Charsets.UTF_8) : null; - } - }; - - REPLIES_TO_BOOLEAN_LIST = new Converter>() { - public List convert(Reply[] source) { - if (source == null) { - return null; - } - List results = new ArrayList(); - for (Reply r : source) { - results.add(SrpConverters.toBoolean(((IntegerReply) r).data())); - } - return results; - } - }; - - REPLIES_TO_STRING_LIST = new Converter>() { - public List convert(Reply[] source) { - if (source == null) { - return null; - } - List results = new ArrayList(); - for (Reply r : source) { - results.add(SrpConverters.toString((byte[]) r.data())); - } - return results; - } - }; - - REPLY_TO_STRING = new Converter() { - - @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>() { - - @Override - public List 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>() { - - @Override - public List 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() { - - @Override - public Boolean convert(IntegerReply source) { - if (source == null || source.data() == null) { - return false; - } - return source.data() == 1; - } - }; - - EXCEPTION_CONVERTER = new Converter() { - - @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> repliesToBytesList() { - return REPLIES_TO_BYTES_LIST; - } - - public static Converter> repliesToBytesSet() { - return REPLIES_TO_BYTES_SET; - } - - public static Converter bytesToProperties() { - return BYTES_TO_PROPERTIES; - } - - public static Converter bytesToDouble() { - return BYTES_TO_DOUBLE; - } - - public static Converter> repliesToTupleSet() { - return REPLIES_TO_TUPLE_SET; - } - - public static Converter> repliesToBytesMap() { - return REPLIES_TO_BYTES_MAP; - } - - public static Converter bytesToString() { - return BYTES_TO_STRING; - } - - public static Converter replyToString() { - return REPLY_TO_STRING; - } - - public static Converter> repliesToBooleanList() { - return REPLIES_TO_BOOLEAN_LIST; - } - - public static Converter> repliesToStringList() { - return REPLIES_TO_STRING_LIST; - } - - public static Converter repliesToTimeAsLong() { - return REPLIES_TO_TIME_AS_LONG; - } - - /** - * @return - * @since 1.3 - */ - public static List toListOfRedisClientInformation(Reply reply) { - return REPLY_T0_LIST_OF_CLIENT_INFO.convert(reply); - } - - /** - * @return - * @since 1.3 - */ - public static Converter longToBooleanConverter() { - return LONG_TO_BOOLEAN; - } - - public static List toBytesList(Reply[] source) { - return REPLIES_TO_BYTES_LIST.convert(source); - } - - public static Set 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 toTupleSet(Reply[] source) { - return REPLIES_TO_TUPLE_SET.convert(source); - } - - public static Map 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 toBooleanList(Reply[] source) { - return REPLIES_TO_BOOLEAN_LIST.convert(source); - } - - public static List 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 source) { - byte[][] result = new byte[source.size() * 2][]; - int index = 0; - for (Map.Entry 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 toStringList(String source) { - return Collections.singletonList(source); - } - - /** - * @since 1.3 - * @return - */ - public static Converter> 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 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(); - - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java deleted file mode 100644 index 072659cdc..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java +++ /dev/null @@ -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) {} -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java deleted file mode 100644 index edb850ba6..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java +++ /dev/null @@ -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 { - - private ReturnType returnType; - - public SrpScriptReturnConverter(ReturnType returnType) { - this.returnType = returnType; - } - - public Object convert(Object source) { - if (returnType == ReturnType.MULTI) { - Reply[] replies = (Reply[]) source; - List results = new ArrayList(); - 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; - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java deleted file mode 100644 index a303fd8ee..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java deleted file mode 100644 index 19512b8d8..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java +++ /dev/null @@ -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 toBytesList(Reply[] replies) { - if (replies == null) { - return null; - } - List list = new ArrayList(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 asStatusList(Reply[] replies) { - List statuses = new ArrayList(); - for (Reply reply : replies) { - statuses.add(((StatusReply) reply).data()); - } - return statuses; - } - - static List toList(T[] byteArrays) { - return Arrays.asList(byteArrays); - } - - @SuppressWarnings("rawtypes") - static Set toSet(Reply[] byteArrays) { - return new LinkedHashSet(toBytesList(byteArrays)); - } - - static byte[][] convert(Map hgetAll) { - byte[][] result = new byte[hgetAll.size() * 2][]; - - int index = 0; - for (Map.Entry 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 convertTuple(MultiBulkReply zrange) { - return convertTuple(zrange.data()); - } - - @SuppressWarnings("rawtypes") - static Set convertTuple(Reply[] byteArrays) { - Set tuples = new LinkedHashSet(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 toMap(Reply[] byteArrays) { - Map map = new LinkedHashMap(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 arrays = new ArrayList(); - - 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 arrays = new ArrayList(); - - 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 asBooleanList(Reply reply) { - if (!(reply instanceof MultiBulkReply)) { - throw new IllegalArgumentException(); - } - List results = new ArrayList(); - for (Reply r : ((MultiBulkReply) reply).data()) { - results.add(SrpUtils.asBoolean((IntegerReply) r)); - } - return results; - } - - static List asIntegerList(Reply[] replies) { - List results = new ArrayList(); - for (Reply reply : replies) { - results.add(((IntegerReply) reply).data()); - } - return results; - } - - static List asList(MultiBulkReply genericReply) { - Reply[] replies = genericReply.data(); - List results = new ArrayList(); - 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(); - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/package-info.java b/src/main/java/org/springframework/data/redis/connection/srp/package-info.java deleted file mode 100644 index 1ef195d58..000000000 --- a/src/main/java/org/springframework/data/redis/connection/srp/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Connection package for spullara Redis Protocol library. - * @deprecated since 1.7. Will be removed in subsequent version. - */ -package org.springframework.data.redis.connection.srp; - diff --git a/src/main/java/org/springframework/data/redis/core/RedisCommand.java b/src/main/java/org/springframework/data/redis/core/RedisCommand.java index 0d7363ff8..902e7f97e 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisCommand.java +++ b/src/main/java/org/springframework/data/redis/core/RedisCommand.java @@ -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; /** diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java deleted file mode 100644 index 23433beeb..000000000 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ /dev/null @@ -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(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(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(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 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(); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionUnitTests.java deleted file mode 100644 index 1172c080c..000000000 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionUnitTests.java +++ /dev/null @@ -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 { - - 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(); - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java deleted file mode 100644 index 6b5deec8b..000000000 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java +++ /dev/null @@ -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()); - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java deleted file mode 100644 index fc17d3b0e..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java +++ /dev/null @@ -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(); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java deleted file mode 100644 index 681ba1497..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java +++ /dev/null @@ -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. is("awesome".getBytes())); - Assert.assertThat(replies[1].data(), Is. is("cool".getBytes())); - Assert.assertThat(replies[2].data(), Is. 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 results = getResults(); - List scriptResults = (List) 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 zRangeByScore = connection.zRangeByScore("myzset", "(1", "2"); - - Assert.assertEquals("two", new String(zRangeByScore.iterator().next())); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java deleted file mode 100644 index c70fd570e..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java +++ /dev/null @@ -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 results = getResults(); - List scriptResults = (List) results.get(0); - assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }), - Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) })); - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java deleted file mode 100644 index ac42cb6ac..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java +++ /dev/null @@ -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 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 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 getResults() { - assertNull(connection.exec()); - List pipelined = connection.closePipeline(); - // We expect only the results of exec to be in the closed pipeline - assertEquals(1, pipelined.size()); - List txResults = (List) pipelined.get(0); - // Return exec results and this test should behave exactly like its superclass - return txResults; - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java deleted file mode 100644 index d9297934f..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java +++ /dev/null @@ -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(); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionUnitTestSuite.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionUnitTestSuite.java deleted file mode 100644 index cca6a600c..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionUnitTestSuite.java +++ /dev/null @@ -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 { - - 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 { - - 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(); - } - - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConvertersUnitTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConvertersUnitTests.java deleted file mode 100644 index c33619d07..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConvertersUnitTests.java +++ /dev/null @@ -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. emptyList())); - } - - /** - * @see DATAREDIS-268 - */ - @Test - public void convertingEmptyReplyToListOfRedisClientInfoShouldReturnEmptyList() { - assertThat(SrpConverters.toListOfRedisClientInformation(new BulkReply(new byte[0])), - equalTo(Collections. emptyList())); - } - - /** - * @see DATAREDIS-268 - */ - @Test - public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() { - assertThat(SrpConverters.toListOfRedisClientInformation(null), equalTo(Collections. 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() { - - @Override - public String data() { - return "foo"; - } - - @Override - public void write(OutputStream os) throws IOException { - // just do nothing; - } - }); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpReplyToTimeAsLongConverterUnitTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpReplyToTimeAsLongConverterUnitTests.java deleted file mode 100644 index 5d9c9f9b1..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpReplyToTimeAsLongConverterUnitTests.java +++ /dev/null @@ -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 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 }); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java deleted file mode 100644 index 0a03160a5..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java +++ /dev/null @@ -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 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 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 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 channels = subscription.getChannels(); - assertEquals(1, channels.size()); - assertArrayEquals("b".getBytes(), channels.iterator().next()); - Collection 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 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 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 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 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 channels = subscription.getChannels(); - assertEquals(1, channels.size()); - assertArrayEquals("a".getBytes(), channels.iterator().next()); - Collection 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 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); - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java deleted file mode 100644 index bd8420d3c..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java +++ /dev/null @@ -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 convertedParams = new ArrayList(); - for (Object b : bytes) { - convertedParams.add(new String((byte[]) b)); - } - return convertedParams.toArray(new String[0]); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/srp/TransactionalSrpItegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/TransactionalSrpItegrationTests.java deleted file mode 100644 index 0ba9434ed..000000000 --- a/src/test/java/org/springframework/data/redis/connection/srp/TransactionalSrpItegrationTests.java +++ /dev/null @@ -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; - } - - } - -} diff --git a/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java index cfe63ae0d..3bf07faa6 100644 --- a/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java @@ -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 } }); } /** diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java index 02e2de688..9033632fe 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java @@ -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 { }); List list = Collections.singletonList(listValue); Set set = new HashSet(Collections.singletonList(setValue)); - Set> tupleSet = new LinkedHashSet>(Collections.singletonList(new DefaultTypedTuple( - zsetValue, 1d))); + Set> tupleSet = new LinkedHashSet>( + Collections.singletonList(new DefaultTypedTuple(zsetValue, 1d))); assertThat(results, isEqual(Arrays.asList(new Object[] { value1, 1l, list, 1l, set, true, tupleSet }))); } @@ -261,9 +259,13 @@ public class RedisTemplateTests { @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 results = template.execute(new SessionCallback>() { @@ -490,30 +492,6 @@ public class RedisTemplateTests { }, 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(); diff --git a/src/test/java/org/springframework/data/redis/core/script/srp/SrpDefaultScriptExecutorTests.java b/src/test/java/org/springframework/data/redis/core/script/srp/SrpDefaultScriptExecutorTests.java deleted file mode 100644 index 2961452ef..000000000 --- a/src/test/java/org/springframework/data/redis/core/script/srp/SrpDefaultScriptExecutorTests.java +++ /dev/null @@ -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(); - } -} diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java index 23cde319a..4e2ca2125 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java @@ -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()); diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java index d35d4ca4a..5a6c29471 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java @@ -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 stringTemplateSrp = new StringRedisTemplate(srpConnFactory); - RedisTemplate personTemplateSrp = new RedisTemplate(); - personTemplateSrp.setConnectionFactory(srpConnFactory); - personTemplateSrp.afterPropertiesSet(); - RedisTemplate rawTemplateSrp = new RedisTemplate(); - 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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java index 033ef0bc7..944827722 100644 --- a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java index 7602103af..1e3690c7f 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java @@ -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 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(); diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java index b227fe8d2..57bc1fb92 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java @@ -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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java b/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java index 229a013f1..deffb9806 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java @@ -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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java index b62e8d7eb..4b2fea776 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java index 1f7e3cff7..083d3a86b 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java @@ -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"; diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java index 685011b16..e3780a715 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java index 945b8de1c..b065c8c95 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java @@ -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 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 extends AbstractRedisCollectionT @Test public void testPollLastTimeout() throws InterruptedException { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + T t1 = getT(); T t2 = getT(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java index 3e7da39ba..af77f399d 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java @@ -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 { @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 { @Test public void testPutAll() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + Map m = new LinkedHashMap(); K k1 = getKey(); K k2 = getKey(); @@ -372,7 +370,7 @@ public abstract class AbstractRedisMapTests { @SuppressWarnings("unchecked") @Test public void testEntrySet() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + Set> entries = map.entrySet(); assertTrue(entries.isEmpty()); @@ -404,7 +402,7 @@ public abstract class AbstractRedisMapTests { @Test public void testPutIfAbsent() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + K k1 = getKey(); K k2 = getKey(); @@ -424,7 +422,7 @@ public abstract class AbstractRedisMapTests { @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 { @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 { @Test public void testConcurrentReplaceOneArg() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + K k1 = getKey(); V v1 = getValue(); V v2 = getValue(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java index b762ee0f9..30951cea7 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java @@ -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 extends AbstractRedisCollectionTe @SuppressWarnings("unchecked") @Test public void testIntersectAndStore() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + RedisZSet interSet1 = createZSetFor("test:zset:inter1"); RedisZSet interSet2 = createZSetFor("test:zset:inter"); @@ -265,7 +264,7 @@ public abstract class AbstractRedisZSetTest 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 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 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 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 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 extends AbstractRedisCollectionTe zSet.add(t1, 1); zSet.add(t2, 2); zSet.add(t3, 3); - Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1) - .offset(1)); + Set 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 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 extends AbstractRedisCollectionTe zSet.add(t1, 1); zSet.add(t2, 2); zSet.add(t3, 3); - Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), RedisZSetCommands.Limit.limit().count(1) - .offset(1)); + Set 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 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 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 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 extends AbstractRedisCollectionTe @SuppressWarnings("unchecked") @Test public void testUnionAndStore() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory())); + RedisZSet unionSet1 = createZSetFor("test:zset:union1"); RedisZSet unionSet2 = createZSetFor("test:zset:union2"); diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index b4f5c91e6..cbe626d2b 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -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 stringTemplateJR = new StringRedisTemplate(jredisConnFactory); - RedisTemplate personTemplateJR = new RedisTemplate(); - personTemplateJR.setConnectionFactory(jredisConnFactory); - personTemplateJR.afterPropertiesSet(); - - RedisTemplate xstreamStringTemplateJR = new RedisTemplate(); - xstreamStringTemplateJR.setConnectionFactory(jredisConnFactory); - xstreamStringTemplateJR.setDefaultSerializer(serializer); - xstreamStringTemplateJR.afterPropertiesSet(); - - RedisTemplate xstreamPersonTemplateJR = new RedisTemplate(); - xstreamPersonTemplateJR.setValueSerializer(serializer); - xstreamPersonTemplateJR.setConnectionFactory(jredisConnFactory); - xstreamPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateJR = new RedisTemplate(); - jsonPersonTemplateJR.setValueSerializer(jsonSerializer); - jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); - jsonPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateJR = new RedisTemplate(); - jackson2JsonPersonTemplateJR.setValueSerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); - jackson2JsonPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate rawTemplateJR = new RedisTemplate(); - 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 stringTemplateSRP = new StringRedisTemplate(srConnFactory); - RedisTemplate personTemplateSRP = new RedisTemplate(); - personTemplateSRP.setConnectionFactory(srConnFactory); - personTemplateSRP.afterPropertiesSet(); - - RedisTemplate xstreamStringTemplateSRP = new RedisTemplate(); - xstreamStringTemplateSRP.setConnectionFactory(srConnFactory); - xstreamStringTemplateSRP.setDefaultSerializer(serializer); - xstreamStringTemplateSRP.afterPropertiesSet(); - - RedisTemplate xstreamPersonTemplateSRP = new RedisTemplate(); - xstreamPersonTemplateSRP.setValueSerializer(serializer); - xstreamPersonTemplateSRP.setConnectionFactory(srConnFactory); - xstreamPersonTemplateSRP.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateSRP = new RedisTemplate(); - jsonPersonTemplateSRP.setValueSerializer(jsonSerializer); - jsonPersonTemplateSRP.setConnectionFactory(srConnFactory); - jsonPersonTemplateSRP.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateSRP = new RedisTemplate(); - jackson2JsonPersonTemplateSRP.setValueSerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateSRP.setConnectionFactory(srConnFactory); - jackson2JsonPersonTemplateSRP.afterPropertiesSet(); - - RedisTemplate rawTemplateSRP = new RedisTemplate(); - 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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java index e61265309..7f8193224 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java @@ -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 { 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 xGenericTemplateJR = new RedisTemplate(); - xGenericTemplateJR.setConnectionFactory(jredisConnFactory); - xGenericTemplateJR.setDefaultSerializer(serializer); - xGenericTemplateJR.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateJR = new RedisTemplate(); - jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); - jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer); - jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer); - jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer); - jsonPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateJR = new RedisTemplate(); - jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); - jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer); - jackson2JsonPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate rawTemplateJR = new RedisTemplate(); - 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 { 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 xGenericTemplateSrp = new RedisTemplate(); - xGenericTemplateSrp.setConnectionFactory(srpConnFactory); - xGenericTemplateSrp.setDefaultSerializer(serializer); - xGenericTemplateSrp.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateSrp = new RedisTemplate(); - jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory); - jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer); - jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer); - jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer); - jsonPersonTemplateSrp.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateSrp = new RedisTemplate(); - jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory); - jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer); - jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer); - jackson2JsonPersonTemplateSrp.afterPropertiesSet(); - - RedisTemplate stringTemplateSrp = new StringRedisTemplate(); - stringTemplateSrp.setConnectionFactory(srpConnFactory); - stringTemplateSrp.afterPropertiesSet(); - - RedisTemplate rawTemplateSrp = new RedisTemplate(); - 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 { { 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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java index 3b0588caf..389cc9c41 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java @@ -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 genericTemplateJR = new StringRedisTemplate(jredisConnFactory); - RedisTemplate xGenericTemplateJR = new RedisTemplate(); - xGenericTemplateJR.setConnectionFactory(jredisConnFactory); - xGenericTemplateJR.setDefaultSerializer(serializer); - xGenericTemplateJR.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateJR = new RedisTemplate(); - jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); - jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer); - jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer); - jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer); - jsonPersonTemplateJR.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateJR = new RedisTemplate(); - 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 genericTemplateSrp = new StringRedisTemplate(srpConnFactory); - RedisTemplate xGenericTemplateSrp = new RedisTemplate(); - xGenericTemplateSrp.setConnectionFactory(srpConnFactory); - xGenericTemplateSrp.setDefaultSerializer(serializer); - xGenericTemplateSrp.afterPropertiesSet(); - - RedisTemplate jsonPersonTemplateSrp = new RedisTemplate(); - jsonPersonTemplateSrp.setConnectionFactory(srpConnFactory); - jsonPersonTemplateSrp.setDefaultSerializer(jsonSerializer); - jsonPersonTemplateSrp.setHashKeySerializer(jsonSerializer); - jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer); - jsonPersonTemplateSrp.afterPropertiesSet(); - - RedisTemplate jackson2JsonPersonTemplateSrp = new RedisTemplate(); - 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 } }); } } diff --git a/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java b/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java index 4617448a0..9dfefe59d 100644 --- a/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java +++ b/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java @@ -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); - } }; /** diff --git a/src/test/resources/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests-context.xml b/src/test/resources/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests-context.xml deleted file mode 100644 index 90c446816..000000000 --- a/src/test/resources/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests-context.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests-context.xml b/src/test/resources/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests-context.xml deleted file mode 100644 index 89a45052b..000000000 --- a/src/test/resources/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests-context.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file