diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 19179ad55..2603520ee 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -15,17 +15,25 @@ */ package org.springframework.data.redis.connection; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Queue; import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.core.convert.converter.Converter; import org.springframework.data.redis.RedisSystemException; +import org.springframework.data.redis.connection.convert.IdentityConverter; +import org.springframework.data.redis.connection.convert.ListConverter; +import org.springframework.data.redis.connection.convert.MapConverter; +import org.springframework.data.redis.connection.convert.SetConverter; import org.springframework.data.redis.serializer.RedisSerializer; -import org.springframework.data.redis.serializer.SerializationUtils; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; @@ -33,11 +41,33 @@ import org.springframework.util.Assert; * Default implementation of {@link StringRedisConnection}. * * @author Costin Leau + * @author Jennifer Hickey */ public class DefaultStringRedisConnection implements StringRedisConnection { + private final Log log = LogFactory.getLog(DefaultStringRedisConnection.class); private final RedisConnection delegate; private final RedisSerializer serializer; + private Converter bytesToString = new DeserializingConverter(); + private SetConverter tupleToStringTuple = new SetConverter(new TupleConverter()); + private ListConverter byteListToStringList = new ListConverter(bytesToString); + private MapConverter byteMapToStringMap = new MapConverter(bytesToString); + private SetConverter byteSetToStringSet = new SetConverter(bytesToString); + @SuppressWarnings("rawtypes") + private Queue pipelineConverters = new LinkedList(); + private boolean deserializePipelineResults = true; + + private class DeserializingConverter implements Converter { + public String convert(byte[] source) { + return serializer.deserialize(source); + } + } + + private class TupleConverter implements Converter { + public StringTuple convert(Tuple source) { + return new DefaultStringTuple(source, serializer.deserialize(source.getValue())); + } + } /** * Constructs a new DefaultStringRedisConnection instance. @@ -65,7 +95,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Long append(byte[] key, byte[] value) { - return delegate.append(key, value); + Long result = delegate.append(key,value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void bgSave() { @@ -77,15 +111,27 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public List bLPop(int timeout, byte[]... keys) { - return delegate.bLPop(timeout, keys); + List results = delegate.bLPop(timeout, keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public List bRPop(int timeout, byte[]... keys) { - return delegate.bRPop(timeout, keys); + List results = delegate.bRPop(timeout, keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - return delegate.bRPopLPush(timeout, srcKey, dstKey); + byte[] result = delegate.bRPopLPush(timeout, srcKey, dstKey); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void close() throws RedisSystemException { @@ -93,19 +139,35 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Long dbSize() { - return delegate.dbSize(); + Long result = delegate.dbSize(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long decr(byte[] key) { - return delegate.decr(key); + Long result = delegate.decr(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long decrBy(byte[] key, long value) { - return delegate.decrBy(key, value); + Long result = delegate.decrBy(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long del(byte[]... keys) { - return delegate.del(keys); + Long result = delegate.del(keys); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void discard() { @@ -113,23 +175,43 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public byte[] echo(byte[] message) { - return delegate.echo(message); + byte[] result = delegate.echo(message); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List exec() { - return delegate.exec(); + List results = delegate.exec(); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Boolean exists(byte[] key) { - return delegate.exists(key); + Boolean result = delegate.exists(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean expire(byte[] key, long seconds) { - return delegate.expire(key, seconds); + Boolean result = delegate.expire(key, seconds); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean expireAt(byte[] key, long unixTime) { - return delegate.expireAt(key, unixTime); + Boolean result = delegate.expireAt(key, unixTime); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void flushAll() { @@ -141,27 +223,51 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public byte[] get(byte[] key) { - return delegate.get(key); + byte[] result = delegate.get(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean getBit(byte[] key, long offset) { - return delegate.getBit(key, offset); + Boolean result = delegate.getBit(key, offset); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List getConfig(String pattern) { - return delegate.getConfig(pattern); + List results = delegate.getConfig(pattern); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Object getNativeConnection() { - return delegate.getNativeConnection(); + Object result = delegate.getNativeConnection(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] getRange(byte[] key, long start, long end) { - return delegate.getRange(key, start, end); + byte[] result = delegate.getRange(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] getSet(byte[] key, byte[] value) { - return delegate.getSet(key, value); + byte[] result = delegate.getSet(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Subscription getSubscription() { @@ -169,39 +275,75 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean hDel(byte[] key, byte[] field) { - return delegate.hDel(key, field); + Boolean result = delegate.hDel(key, field); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean hExists(byte[] key, byte[] field) { - return delegate.hExists(key, field); + Boolean result = delegate.hExists(key, field); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] hGet(byte[] key, byte[] field) { - return delegate.hGet(key, field); + byte[] result = delegate.hGet(key, field); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Map hGetAll(byte[] key) { - return delegate.hGetAll(key); + Map results = delegate.hGetAll(key); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long hIncrBy(byte[] key, byte[] field, long delta) { - return delegate.hIncrBy(key, field, delta); + Long result = delegate.hIncrBy(key, field, delta); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double hIncrBy(byte[] key, byte[] field, double delta) { - return delegate.hIncrBy(key, field, delta); + Double result = delegate.hIncrBy(key, field, delta); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set hKeys(byte[] key) { - return delegate.hKeys(key); + Set results = delegate.hKeys(key); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long hLen(byte[] key) { - return delegate.hLen(key); + Long result = delegate.hLen(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List hMGet(byte[] key, byte[]... fields) { - return delegate.hMGet(key, fields); + List results = delegate.hMGet(key, fields); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public void hMSet(byte[] key, Map hashes) { @@ -209,35 +351,67 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean hSet(byte[] key, byte[] field, byte[] value) { - return delegate.hSet(key, field, value); + Boolean result = delegate.hSet(key, field, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - return delegate.hSetNX(key, field, value); + Boolean result = delegate.hSetNX(key, field, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List hVals(byte[] key) { - return delegate.hVals(key); + List results = delegate.hVals(key); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long incr(byte[] key) { - return delegate.incr(key); + Long result = delegate.incr(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long incrBy(byte[] key, long value) { - return delegate.incrBy(key, value); + Long result = delegate.incrBy(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double incrBy(byte[] key, double value) { - return delegate.incrBy(key, value); + Double result = delegate.incrBy(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Properties info() { - return delegate.info(); + Properties result = delegate.info(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Properties info(String section) { - return delegate.info(section); + Properties result = delegate.info(section); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public boolean isClosed() { @@ -253,43 +427,83 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Set keys(byte[] pattern) { - return delegate.keys(pattern); + Set results = delegate.keys(pattern); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long lastSave() { - return delegate.lastSave(); + Long result = delegate.lastSave(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] lIndex(byte[] key, long index) { - return delegate.lIndex(key, index); + byte[] result = delegate.lIndex(key, index); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - return delegate.lInsert(key, where, pivot, value); + Long result = delegate.lInsert(key, where, pivot, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lLen(byte[] key) { - return delegate.lLen(key); + Long result = delegate.lLen(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] lPop(byte[] key) { - return delegate.lPop(key); + byte[] result = delegate.lPop(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lPush(byte[] key, byte[] value) { - return delegate.lPush(key, value); + Long result = delegate.lPush(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lPushX(byte[] key, byte[] value) { - return delegate.lPushX(key, value); + Long result = delegate.lPushX(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List lRange(byte[] key, long start, long end) { - return delegate.lRange(key, start, end); + List results = delegate.lRange(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long lRem(byte[] key, long count, byte[] value) { - return delegate.lRem(key, count, value); + Long result = delegate.lRem(key, count, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void lSet(byte[] key, long index, byte[] value) { @@ -301,7 +515,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public List mGet(byte[]... keys) { - return delegate.mGet(keys); + List results = delegate.mGet(keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public void mSet(Map tuple) { @@ -309,7 +527,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean mSetNX(Map tuple) { - return delegate.mSetNX(tuple); + Boolean result = delegate.mSetNX(tuple); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void multi() { @@ -317,15 +539,27 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean persist(byte[] key) { - return delegate.persist(key); + Boolean result = delegate.persist(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean move(byte[] key, int dbIndex) { - return delegate.move(key, dbIndex); + Boolean result = delegate.move(key, dbIndex); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String ping() { - return delegate.ping(); + String result = delegate.ping(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void pSubscribe(MessageListener listener, byte[]... patterns) { @@ -333,11 +567,19 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Long publish(byte[] channel, byte[] message) { - return delegate.publish(channel, message); + Long result = delegate.publish(channel, message); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] randomKey() { - return delegate.randomKey(); + byte[] result = delegate.randomKey(); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void rename(byte[] oldName, byte[] newName) { @@ -345,7 +587,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean renameNX(byte[] oldName, byte[] newName) { - return delegate.renameNX(oldName, newName); + Boolean result = delegate.renameNX(oldName, newName); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void resetConfigStats() { @@ -353,23 +599,43 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public byte[] rPop(byte[] key) { - return delegate.rPop(key); + byte[] result = delegate.rPop(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - return delegate.rPopLPush(srcKey, dstKey); + byte[] result = delegate.rPopLPush(srcKey, dstKey); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long rPush(byte[] key, byte[] value) { - return delegate.rPush(key, value); + Long result = delegate.rPush(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long rPushX(byte[] key, byte[] value) { - return delegate.rPushX(key, value); + Long result = delegate.rPushX(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean sAdd(byte[] key, byte[] value) { - return delegate.sAdd(key, value); + Boolean result = delegate.sAdd(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void save() { @@ -377,15 +643,27 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Long sCard(byte[] key) { - return delegate.sCard(key); + Long result = delegate.sCard(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set sDiff(byte[]... keys) { - return delegate.sDiff(keys); + Set results = delegate.sDiff(keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long sDiffStore(byte[] destKey, byte[]... keys) { - return delegate.sDiffStore(destKey, keys); + Long result = delegate.sDiffStore(destKey, keys); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void select(int dbIndex) { @@ -409,7 +687,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean setNX(byte[] key, byte[] value) { - return delegate.setNX(key, value); + Boolean result = delegate.setNX(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void setRange(byte[] key, byte[] value, long start) { @@ -421,63 +703,123 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Set sInter(byte[]... keys) { - return delegate.sInter(keys); + Set results = delegate.sInter(keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long sInterStore(byte[] destKey, byte[]... keys) { - return delegate.sInterStore(destKey, keys); + Long result = delegate.sInterStore(destKey, keys); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean sIsMember(byte[] key, byte[] value) { - return delegate.sIsMember(key, value); + Boolean result = delegate.sIsMember(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set sMembers(byte[] key) { - return delegate.sMembers(key); + Set results = delegate.sMembers(key); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - return delegate.sMove(srcKey, destKey, value); + Boolean result = delegate.sMove(srcKey, destKey, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long sort(byte[] key, SortParameters params, byte[] storeKey) { - return delegate.sort(key, params, storeKey); + Long result = delegate.sort(key, params, storeKey); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List sort(byte[] key, SortParameters params) { - return delegate.sort(key, params); + List results = delegate.sort(key, params); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public byte[] sPop(byte[] key) { - return delegate.sPop(key); + byte[] result = delegate.sPop(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] sRandMember(byte[] key) { - return delegate.sRandMember(key); + byte[] result = delegate.sRandMember(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List sRandMember(byte[] key, long count) { - return delegate.sRandMember(key, count); + List results = delegate.sRandMember(key, count); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Boolean sRem(byte[] key, byte[] value) { - return delegate.sRem(key, value); + Boolean result = delegate.sRem(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long strLen(byte[] key) { - return delegate.strLen(key); + Long result = delegate.strLen(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitCount(byte[] key) { - return delegate.bitCount(key); + Long result = delegate.bitCount(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitCount(byte[] key, long begin, long end) { - return delegate.bitCount(key, begin, end); + Long result = delegate.bitCount(key, begin, end); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - return delegate.bitOp(op, destination, keys); + Long result = delegate.bitOp(op, destination, keys); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void subscribe(MessageListener listener, byte[]... channels) { @@ -485,19 +827,35 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Set sUnion(byte[]... keys) { - return delegate.sUnion(keys); + Set results = delegate.sUnion(keys); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long sUnionStore(byte[] destKey, byte[]... keys) { - return delegate.sUnionStore(destKey, keys); + Long result = delegate.sUnionStore(destKey, keys); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long ttl(byte[] key) { - return delegate.ttl(key); + Long result = delegate.ttl(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public DataType type(byte[] key) { - return delegate.type(key); + DataType result = delegate.type(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void unwatch() { @@ -509,123 +867,243 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean zAdd(byte[] key, double score, byte[] value) { - return delegate.zAdd(key, score, value); + Boolean result = delegate.zAdd(key, score, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zCard(byte[] key) { - return delegate.zCard(key); + Long result = delegate.zCard(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zCount(byte[] key, double min, double max) { - return delegate.zCount(key, min, max); + Long result = delegate.zCount(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double zIncrBy(byte[] key, double increment, byte[] value) { - return delegate.zIncrBy(key, increment, value); + Double result = delegate.zIncrBy(key, increment, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return delegate.zInterStore(destKey, aggregate, weights, sets); + Long result = delegate.zInterStore(destKey, aggregate, weights, sets); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zInterStore(byte[] destKey, byte[]... sets) { - return delegate.zInterStore(destKey, sets); + Long result = delegate.zInterStore(destKey, sets); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set zRange(byte[] key, long start, long end) { - return delegate.zRange(key, start, end); + Set results = delegate.zRange(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - return delegate.zRangeByScore(key, min, max, offset, count); + Set results = delegate.zRangeByScore(key, min, max, offset, count); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRangeByScore(byte[] key, double min, double max) { - return delegate.zRangeByScore(key, min, max); + Set results = delegate.zRangeByScore(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - return delegate.zRangeByScoreWithScores(key, min, max, offset, count); + Set results = delegate.zRangeByScoreWithScores(key, min, max, offset, count); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRangeByScoreWithScores(byte[] key, double min, double max) { - return delegate.zRangeByScoreWithScores(key, min, max); + Set results = delegate.zRangeByScoreWithScores(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRangeWithScores(byte[] key, long start, long end) { - return delegate.zRangeWithScores(key, start, end); + Set results = delegate.zRangeWithScores(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { - return delegate.zRevRangeByScore(key, min, max, offset, count); + Set results = delegate.zRevRangeByScore(key, min, max, offset, count); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRevRangeByScore(byte[] key, double min, double max) { - return delegate.zRevRangeByScore(key, min, max); + Set results = delegate.zRevRangeByScore(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - return delegate.zRevRangeByScoreWithScores(key, min, max, offset, count); + Set results = delegate.zRevRangeByScoreWithScores(key, min, max, offset, count); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { - return delegate.zRevRangeByScoreWithScores(key, min, max); + Set results = delegate.zRevRangeByScoreWithScores(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long zRank(byte[] key, byte[] value) { - return delegate.zRank(key, value); + Long result = delegate.zRank(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean zRem(byte[] key, byte[] value) { - return delegate.zRem(key, value); + Boolean result = delegate.zRem(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zRemRange(byte[] key, long start, long end) { - return delegate.zRemRange(key, start, end); + Long result = delegate.zRemRange(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zRemRangeByScore(byte[] key, double min, double max) { - return delegate.zRemRangeByScore(key, min, max); + Long result = delegate.zRemRangeByScore(key, min, max); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set zRevRange(byte[] key, long start, long end) { - return delegate.zRevRange(key, start, end); + Set results = delegate.zRevRange(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Set zRevRangeWithScores(byte[] key, long start, long end) { - return delegate.zRevRangeWithScores(key, start, end); + Set results = delegate.zRevRangeWithScores(key, start, end); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public Long zRevRank(byte[] key, byte[] value) { - return delegate.zRevRank(key, value); + Long result = delegate.zRevRank(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double zScore(byte[] key, byte[] value) { - return delegate.zScore(key, value); + Double result = delegate.zScore(key, value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - return delegate.zUnionStore(destKey, aggregate, weights, sets); + Long result = delegate.zUnionStore(destKey, aggregate, weights, sets); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zUnionStore(byte[] destKey, byte[]... sets) { - return delegate.zUnionStore(destKey, sets); + Long result = delegate.zUnionStore(destKey, sets); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean pExpire(byte[] key, long millis) { - return delegate.pExpire(key, millis); + Boolean result = delegate.pExpire(key, millis); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { - return delegate.pExpireAt(key, unixTimeInMillis); + Boolean result = delegate.pExpireAt(key, unixTimeInMillis); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long pTtl(byte[] key) { - return delegate.pTtl(key); + Long result = delegate.pTtl(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public byte[] dump(byte[] key) { - return delegate.dump(key); + byte[] result = delegate.dump(key); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { @@ -641,19 +1119,35 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public String scriptLoad(byte[] script) { - return delegate.scriptLoad(script); + String result = delegate.scriptLoad(script); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List scriptExists(String... scriptSha1) { - return delegate.scriptExists(scriptSha1); + List results = delegate.scriptExists(scriptSha1); + if(isPipelined()) { + pipeline(identityConverter(results)); + } + return results; } public T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - return delegate.eval(script, returnType, numKeys, keysAndArgs); + T result = delegate.eval(script, returnType, numKeys, keysAndArgs); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { - return delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs); + T result = delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } // @@ -684,150 +1178,218 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return ret; } - private Map deserialize(Map hashes) { - return SerializationUtils.deserialize(hashes, serializer); - } - - private List deserialize(List data) { - return SerializationUtils.deserialize(data, serializer); - } - - private Set deserialize(Set data) { - return SerializationUtils.deserialize(data, serializer); - } - - private String deserialize(byte[] data) { - return serializer.deserialize(data); - } - - private Set deserializeTuple(Set data) { - if (data == null) { - return null; + + public Long append(String key, String value) { + Long result = delegate.append(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); } - Set result = new LinkedHashSet(data.size()); - for (Tuple raw : data) { - result.add(new DefaultStringTuple(raw, serializer.deserialize(raw.getValue()))); - } - return result; } - public Long append(String key, String value) { - return delegate.append(serialize(key), serialize(value)); - } - - public List bLPop(int timeout, String... keys) { - return deserialize(delegate.bLPop(timeout, serializeMulti(keys))); + List results = delegate.bLPop(timeout, serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public List bRPop(int timeout, String... keys) { - return deserialize(delegate.bRPop(timeout, serializeMulti(keys))); + List results = delegate.bRPop(timeout, serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public String bRPopLPush(int timeout, String srcKey, String dstKey) { - return deserialize(delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey))); + byte[] result = delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Long decr(String key) { - return delegate.decr(serialize(key)); + Long result = delegate.decr(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long decrBy(String key, long value) { - return delegate.decrBy(serialize(key), value); + Long result = delegate.decrBy(serialize(key), value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long del(String... keys) { - return delegate.del(serializeMulti(keys)); + Long result = delegate.del(serializeMulti(keys)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String echo(String message) { - return deserialize(delegate.echo(serialize(message))); + byte[] result = delegate.echo(serialize(message)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Boolean exists(String key) { - return delegate.exists(serialize(key)); + Boolean result = delegate.exists(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean expire(String key, long seconds) { - return delegate.expire(serialize(key), seconds); + Boolean result = delegate.expire(serialize(key), seconds); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean expireAt(String key, long unixTime) { - return delegate.expireAt(serialize(key), unixTime); + Boolean result = delegate.expireAt(serialize(key), unixTime); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String get(String key) { - return deserialize(delegate.get(serialize(key))); + byte[] result = delegate.get(serialize(key)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Boolean getBit(String key, long offset) { - return delegate.getBit(serialize(key), offset); + Boolean result = delegate.getBit(serialize(key), offset); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String getRange(String key, long start, long end) { - return deserialize(delegate.getRange(serialize(key), start, end)); + byte[] result = delegate.getRange(serialize(key), start, end); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public String getSet(String key, String value) { - return deserialize(delegate.getSet(serialize(key), serialize(value))); + byte[] result = delegate.getSet(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Boolean hDel(String key, String field) { - return delegate.hDel(serialize(key), serialize(field)); + Boolean result = delegate.hDel(serialize(key), serialize(field)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean hExists(String key, String field) { - return delegate.hExists(serialize(key), serialize(field)); + Boolean result = delegate.hExists(serialize(key), serialize(field)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String hGet(String key, String field) { - return deserialize(delegate.hGet(serialize(key), serialize(field))); + byte[] result = delegate.hGet(serialize(key), serialize(field)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Map hGetAll(String key) { - return deserialize(delegate.hGetAll(serialize(key))); + Map results = delegate.hGetAll(serialize(key)); + if(isPipelined()) { + pipeline(byteMapToStringMap); + } + return byteMapToStringMap.convert(results); } public Long hIncrBy(String key, String field, long delta) { - return delegate.hIncrBy(serialize(key), serialize(field), delta); + Long result = delegate.hIncrBy(serialize(key), serialize(field), delta); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double hIncrBy(String key, String field, double delta) { - return delegate.hIncrBy(serialize(key), serialize(field), delta); + Double result = delegate.hIncrBy(serialize(key), serialize(field), delta); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set hKeys(String key) { - return deserialize(delegate.hKeys(serialize(key))); + Set results = delegate.hKeys(serialize(key)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Long hLen(String key) { - return delegate.hLen(serialize(key)); + Long result = delegate.hLen(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List hMGet(String key, String... fields) { - return deserialize(delegate.hMGet(serialize(key), serializeMulti(fields))); + List results = delegate.hMGet(serialize(key), serializeMulti(fields)); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public void hMSet(String key, Map hashes) { @@ -836,75 +1398,135 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean hSet(String key, String field, String value) { - return delegate.hSet(serialize(key), serialize(field), serialize(value)); + Boolean result = delegate.hSet(serialize(key), serialize(field), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean hSetNX(String key, String field, String value) { - return delegate.hSetNX(serialize(key), serialize(field), serialize(value)); + Boolean result = delegate.hSetNX(serialize(key), serialize(field), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List hVals(String key) { - return deserialize(delegate.hVals(serialize(key))); + List results = delegate.hVals(serialize(key)); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public Long incr(String key) { - return delegate.incr(serialize(key)); + Long result = delegate.incr(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long incrBy(String key, long value) { - return delegate.incrBy(serialize(key), value); + Long result = delegate.incrBy(serialize(key), value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double incrBy(String key, double value) { - return delegate.incrBy(serialize(key), value); + Double result = delegate.incrBy(serialize(key), value); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Collection keys(String pattern) { - return deserialize(delegate.keys(serialize(pattern))); + Set results = delegate.keys(serialize(pattern)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public String lIndex(String key, long index) { - return deserialize(delegate.lIndex(serialize(key), index)); + byte[] result = delegate.lIndex(serialize(key), index); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Long lInsert(String key, Position where, String pivot, String value) { - return delegate.lInsert(serialize(key), where, serialize(pivot), serialize(value)); + Long result = delegate.lInsert(serialize(key), where, serialize(pivot), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lLen(String key) { - return delegate.lLen(serialize(key)); + Long result = delegate.lLen(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String lPop(String key) { - return deserialize(delegate.lPop(serialize(key))); + byte[] result = delegate.lPop(serialize(key)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Long lPush(String key, String value) { - return delegate.lPush(serialize(key), serialize(value)); + Long result = delegate.lPush(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long lPushX(String key, String value) { - return delegate.lPushX(serialize(key), serialize(value)); + Long result = delegate.lPushX(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List lRange(String key, long start, long end) { - return deserialize(delegate.lRange(serialize(key), start, end)); + List results = delegate.lRange(serialize(key), start, end); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public Long lRem(String key, long count, String value) { - return delegate.lRem(serialize(key), count, serialize(value)); + Long result = delegate.lRem(serialize(key), count, serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -919,12 +1541,20 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List mGet(String... keys) { - return deserialize(delegate.mGet(serializeMulti(keys))); + List results = delegate.mGet(serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public Boolean mSetNXString(Map tuple) { - return delegate.mSetNX(serialize(tuple)); + Boolean result = delegate.mSetNX(serialize(tuple)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -934,12 +1564,20 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean persist(String key) { - return delegate.persist(serialize(key)); + Boolean result = delegate.persist(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean move(String key, int dbIndex) { - return delegate.move(serialize(key), dbIndex); + Boolean result = delegate.move(serialize(key), dbIndex); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -949,7 +1587,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long publish(String channel, String message) { - return delegate.publish(serialize(channel), serialize(message)); + Long result = delegate.publish(serialize(channel), serialize(message)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -959,47 +1601,83 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean renameNX(String oldName, String newName) { - return delegate.renameNX(serialize(oldName), serialize(newName)); + Boolean result = delegate.renameNX(serialize(oldName), serialize(newName)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public String rPop(String key) { - return deserialize(delegate.rPop(serialize(key))); + byte[] result = delegate.rPop(serialize(key)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public String rPopLPush(String srcKey, String dstKey) { - return deserialize(delegate.rPopLPush(serialize(srcKey), serialize(dstKey))); + byte[] result = delegate.rPopLPush(serialize(srcKey), serialize(dstKey)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public Long rPush(String key, String value) { - return delegate.rPush(serialize(key), serialize(value)); + Long result = delegate.rPush(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long rPushX(String key, String value) { - return delegate.rPushX(serialize(key), serialize(value)); + Long result = delegate.rPushX(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean sAdd(String key, String value) { - return delegate.sAdd(serialize(key), serialize(value)); + Boolean result = delegate.sAdd(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long sCard(String key) { - return delegate.sCard(serialize(key)); + Long result = delegate.sCard(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set sDiff(String... keys) { - return deserialize(delegate.sDiff(serializeMulti(keys))); + Set results = delegate.sDiff(serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Long sDiffStore(String destKey, String... keys) { - return delegate.sDiffStore(serialize(destKey), serializeMulti(keys)); + Long result = delegate.sDiffStore(serialize(destKey), serializeMulti(keys)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -1019,7 +1697,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean setNX(String key, String value) { - return delegate.setNX(serialize(key), serialize(value)); + Boolean result = delegate.setNX(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } @@ -1029,71 +1711,131 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sInter(String... keys) { - return deserialize(delegate.sInter(serializeMulti(keys))); + Set results = delegate.sInter(serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Long sInterStore(String destKey, String... keys) { - return delegate.sInterStore(serialize(destKey), serializeMulti(keys)); + Long result = delegate.sInterStore(serialize(destKey), serializeMulti(keys)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean sIsMember(String key, String value) { - return delegate.sIsMember(serialize(key), serialize(value)); + Boolean result = delegate.sIsMember(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set sMembers(String key) { - return deserialize(delegate.sMembers(serialize(key))); + Set results = delegate.sMembers(serialize(key)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Boolean sMove(String srcKey, String destKey, String value) { - return delegate.sMove(serialize(srcKey), serialize(destKey), serialize(value)); + Boolean result = delegate.sMove(serialize(srcKey), serialize(destKey), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long sort(String key, SortParameters params, String storeKey) { - return delegate.sort(serialize(key), params, serialize(storeKey)); + Long result = delegate.sort(serialize(key), params, serialize(storeKey)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public List sort(String key, SortParameters params) { - return deserialize(delegate.sort(serialize(key), params)); + List results = delegate.sort(serialize(key), params); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public String sPop(String key) { - return deserialize(delegate.sPop(serialize(key))); + byte[] result = delegate.sPop(serialize(key)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public String sRandMember(String key) { - return deserialize(delegate.sRandMember(serialize(key))); + byte[] result = delegate.sRandMember(serialize(key)); + if(isPipelined()) { + pipeline(bytesToString); + } + return bytesToString.convert(result); } public List sRandMember(String key, long count) { - return deserialize(delegate.sRandMember(serialize(key), count)); + List results = delegate.sRandMember(serialize(key), count); + if(isPipelined()) { + pipeline(byteListToStringList); + } + return byteListToStringList.convert(results); } public Boolean sRem(String key, String value) { - return delegate.sRem(serialize(key), serialize(value)); + Boolean result = delegate.sRem(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long strLen(String key) { - return delegate.strLen(serialize(key)); + Long result = delegate.strLen(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitCount(String key) { - return delegate.bitCount(serialize(key)); + Long result = delegate.bitCount(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitCount(String key, long begin, long end) { - return delegate.bitCount(serialize(key), begin, end); + Long result = delegate.bitCount(serialize(key), begin, end); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long bitOp(BitOperation op, String destination, String... keys) { - return delegate.bitOp(op, serialize(destination), serializeMulti(keys)); + Long result = delegate.bitOp(op, serialize(destination), serializeMulti(keys)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public void subscribe(MessageListener listener, String... channels) { @@ -1102,137 +1844,259 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sUnion(String... keys) { - return deserialize(delegate.sUnion(serializeMulti(keys))); + Set results = delegate.sUnion(serializeMulti(keys)); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Long sUnionStore(String destKey, String... keys) { - return delegate.sUnionStore(serialize(destKey), serializeMulti(keys)); + Long result = delegate.sUnionStore(serialize(destKey), serializeMulti(keys)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long ttl(String key) { - return delegate.ttl(serialize(key)); + Long result = delegate.ttl(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public DataType type(String key) { - return delegate.type(serialize(key)); + DataType result = delegate.type(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean zAdd(String key, double score, String value) { - return delegate.zAdd(serialize(key), score, serialize(value)); + Boolean result = delegate.zAdd(serialize(key), score, serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zCard(String key) { - return delegate.zCard(serialize(key)); + Long result = delegate.zCard(serialize(key)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zCount(String key, double min, double max) { - return delegate.zCount(serialize(key), min, max); + Long result = delegate.zCount(serialize(key), min, max); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double zIncrBy(String key, double increment, String value) { - return delegate.zIncrBy(serialize(key), increment, serialize(value)); + Double result = delegate.zIncrBy(serialize(key), increment, serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { - return delegate.zInterStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); + Long result = delegate.zInterStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zInterStore(String destKey, String... sets) { - return delegate.zInterStore(serialize(destKey), serializeMulti(sets)); + Long result = delegate.zInterStore(serialize(destKey), serializeMulti(sets)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set zRange(String key, long start, long end) { - return deserialize(delegate.zRange(serialize(key), start, end)); + Set results = delegate.zRange(serialize(key), start, end); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Set zRangeByScore(String key, double min, double max, long offset, long count) { - return deserialize(delegate.zRangeByScore(serialize(key), min, max, offset, count)); + Set results = delegate.zRangeByScore(serialize(key), min, max, offset, count); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Set zRangeByScore(String key, double min, double max) { - return deserialize(delegate.zRangeByScore(serialize(key), min, max)); + Set results = delegate.zRangeByScore(serialize(key), min, max); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Set zRangeByScoreWithScores(String key, double min, double max, long offset, long count) { - return deserializeTuple(delegate.zRangeByScoreWithScores(serialize(key), min, max, offset, count)); + Set results = delegate.zRangeByScoreWithScores(serialize(key), min, max, offset, count); + if(isPipelined()) { + pipeline(tupleToStringTuple); + } + return tupleToStringTuple.convert(results); } public Set zRangeByScoreWithScores(String key, double min, double max) { - return deserializeTuple(delegate.zRangeByScoreWithScores(serialize(key), min, max)); + Set results = delegate.zRangeByScoreWithScores(serialize(key), min, max); + if(isPipelined()) { + pipeline(tupleToStringTuple); + } + return tupleToStringTuple.convert(results); } public Set zRangeWithScores(String key, long start, long end) { - return deserializeTuple(delegate.zRangeWithScores(serialize(key), start, end)); + Set results = delegate.zRangeWithScores(serialize(key), start, end); + if(isPipelined()) { + pipeline(tupleToStringTuple); + } + return tupleToStringTuple.convert(results); } public Long zRank(String key, String value) { - return delegate.zRank(serialize(key), serialize(value)); + Long result = delegate.zRank(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Boolean zRem(String key, String value) { - return delegate.zRem(serialize(key), serialize(value)); + Boolean result = delegate.zRem(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zRemRange(String key, long start, long end) { - return delegate.zRemRange(serialize(key), start, end); + Long result = delegate.zRemRange(serialize(key), start, end); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zRemRangeByScore(String key, double min, double max) { - return delegate.zRemRangeByScore(serialize(key), min, max); + Long result = delegate.zRemRangeByScore(serialize(key), min, max); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Set zRevRange(String key, long start, long end) { - return deserialize(delegate.zRevRange(serialize(key), start, end)); + Set results = delegate.zRevRange(serialize(key), start, end); + if(isPipelined()) { + pipeline(byteSetToStringSet); + } + return byteSetToStringSet.convert(results); } public Set zRevRangeWithScores(String key, long start, long end) { - return deserializeTuple(delegate.zRevRangeWithScores(serialize(key), start, end)); + Set results = delegate.zRevRangeWithScores(serialize(key), start, end); + if(isPipelined()) { + pipeline(tupleToStringTuple); + } + return tupleToStringTuple.convert(results); } public Long zRevRank(String key, String value) { - return delegate.zRevRank(serialize(key), serialize(value)); + Long result = delegate.zRevRank(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Double zScore(String key, String value) { - return delegate.zScore(serialize(key), serialize(value)); + Double result = delegate.zScore(serialize(key), serialize(value)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { - return delegate.zUnionStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); + Long result = delegate.zUnionStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Long zUnionStore(String destKey, String... sets) { - return delegate.zUnionStore(serialize(destKey), serializeMulti(sets)); + Long result = delegate.zUnionStore(serialize(destKey), serializeMulti(sets)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } + @SuppressWarnings("unchecked") public List closePipeline() { - return delegate.closePipeline(); + try { + List results = delegate.closePipeline(); + if(!deserializePipelineResults) { + return results; + } + if(results.size() != pipelineConverters.size()) { + // Some of the pipelined commands were done directly on the delegate, don't attempt to convert + log.warn("Delegate returned an unexpected number of results on closePipeline. Abandoning type conversion."); + return results; + } + List convertedResults = new ArrayList(); + for(Object result: results) { + convertedResults.add(pipelineConverters.remove().convert(result)); + } + return convertedResults; + }finally { + pipelineConverters.clear(); + } } @@ -1251,7 +2115,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Object execute(String command, byte[]... args) { - return delegate.execute(command, args); + Object result = delegate.execute(command, args); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } public Object execute(String command, String... args) { @@ -1271,7 +2139,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public String scriptLoad(String script) { - return delegate.scriptLoad(serialize(script)); + String result = delegate.scriptLoad(serialize(script)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } /** @@ -1280,7 +2152,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { * be returned as byte[]s */ public T eval(String script, ReturnType returnType, int numKeys, String... keysAndArgs) { - return delegate.eval(serialize(script), returnType, numKeys, serializeMulti(keysAndArgs)); + T result = delegate.eval(serialize(script), returnType, numKeys, serializeMulti(keysAndArgs)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; } /** @@ -1289,6 +2165,29 @@ public class DefaultStringRedisConnection implements StringRedisConnection { * be returned as byte[]s */ public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, String... keysAndArgs) { - return delegate.evalSha(scriptSha1, returnType, numKeys, serializeMulti(keysAndArgs)); + T result = delegate.evalSha(scriptSha1, returnType, numKeys, serializeMulti(keysAndArgs)); + if(isPipelined()) { + pipeline(identityConverter(result)); + } + return result; + } + + /** + * Specifies if pipelined results should be deserialized to Strings. + * If false, results of {@link #closePipeline()} will be of the + * type returned by the underlying connection + * + * @param deserializePipelineResults Whether or not to deserialize pipeline results + */ + public void setDeserializePipelineResults(boolean deserializePipelineResults) { + this.deserializePipelineResults = deserializePipelineResults; + } + + private IdentityConverter identityConverter(T foo) { + return new IdentityConverter(); + } + + private void pipeline(Converter converter) { + pipelineConverters.add(converter); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java index 91c80561e..28f838bcb 100644 --- a/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java @@ -34,6 +34,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; */ public class StringRedisTemplate extends RedisTemplate { + private boolean deserializePipelineResults = true; + /** * Constructs a new StringRedisTemplate instance. * {@link #setConnectionFactory(RedisConnectionFactory)} and {@link #afterPropertiesSet()} still need to be called. @@ -58,8 +60,20 @@ public class StringRedisTemplate extends RedisTemplate { afterPropertiesSet(); } - + /** + * Specifies if pipelined results should be deserialized to Strings. + * If false, results of {@link StringRedisConnection#closePipeline()} will be of the + * type returned by the underlying connection + * + * @param deserializePipelineResults Whether or not to deserialize pipeline results + */ + public void setDeserializePipelineResults(boolean deserializePipelineResults) { + this.deserializePipelineResults = deserializePipelineResults; + } + protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) { - return new DefaultStringRedisConnection(connection); + DefaultStringRedisConnection stringConn = new DefaultStringRedisConnection(connection); + stringConn.setDeserializePipelineResults(deserializePipelineResults); + return stringConn; } } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 8c5dc762e..79ef537ba 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -94,6 +94,7 @@ public abstract class AbstractConnectionIntegrationTests { public void setUp() { byteConnection = connectionFactory.getConnection(); connection = new DefaultStringRedisConnection(byteConnection); + ((DefaultStringRedisConnection)connection).setDeserializePipelineResults(false); } @After diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java new file mode 100644 index 000000000..66420e259 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java @@ -0,0 +1,1397 @@ +/* + * 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; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; + +/** + * Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline + * + * @author Jennifer Hickey + * + */ +public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests { + + @Before + public void setUp() { + super.setUp(); + when(nativeConnection.isPipelined()).thenReturn(true); + } + + @Test + public void testAppend() { + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testAppend(); + } + + @Test + public void testAppendBytes() { + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testAppendBytes(); + } + + @Test + public void testBlPopBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testBlPopBytes(); + } + + @Test + public void testBlPop() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testBlPop(); + } + + @Test + public void testBrPopBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testBrPopBytes(); + } + + @Test + public void testBrPop() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testBrPop(); + } + + @Test + public void testBrPopLPushBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testBrPopLPushBytes(); + } + + @Test + public void testBrPopLPush() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testBrPopLPush(); + } + + @Test + public void testDbSize() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testDbSize(); + } + + @Test + public void testDecrBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testDecrBytes(); + } + + @Test + public void testDecr() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testDecr(); + } + + @Test + public void testDecrByBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testDecrByBytes(); + } + + @Test + public void testDecrBy() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testDecrBy(); + } + + @Test + public void testDelBytes() { + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testDelBytes(); + } + + @Test + public void testDel() { + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testDel(); + } + + @Test + public void testEchoBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testEchoBytes(); + } + + @Test + public void testEcho() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testEcho(); + } + + @Test + public void testExec() { + List results = Arrays.asList(new Object[] { barBytes }); + doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); + super.testExec(); + } + + @Test + public void testExistsBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExistsBytes(); + } + + @Test + public void testExists() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExists(); + } + + @Test + public void testExpireBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExpireBytes(); + } + + @Test + public void testExpire() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExpire(); + } + + @Test + public void testExpireAtBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExpireAtBytes(); + } + + @Test + public void testExpireAt() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testExpireAt(); + } + + @Test + public void testGetBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGetBytes(); + } + + @Test + public void testGet() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGet(); + } + + @Test + public void testGetBitBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testGetBitBytes(); + } + + @Test + public void testGetBit() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testGetBit(); + } + + @Test + public void testGetConfig() { + List results = Collections.singletonList("bar"); + doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); + super.testGetConfig(); + } + + @Test + public void testGetNativeConnection() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testGetNativeConnection(); + } + + @Test + public void testGetRangeBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGetRangeBytes(); + } + + @Test + public void testGetRange() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGetRange(); + } + + @Test + public void testGetSetBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGetSetBytes(); + } + + @Test + public void testGetSet() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testGetSet(); + } + + @Test + public void testHDelBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHDelBytes(); + } + + @Test + public void testHDel() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHDel(); + } + + @Test + public void testHExistsBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHExistsBytes(); + } + + @Test + public void testHExists() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHExists(); + } + + @Test + public void testHGetBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testHGetBytes(); + } + + @Test + public void testHGet() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testHGet(); + } + + @Test + public void testHGetAllBytes() { + doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).closePipeline(); + super.testHGetAllBytes(); + } + + @Test + public void testHGetAll() { + doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).closePipeline(); + super.testHGetAll(); + } + + @Test + public void testHIncrByBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testHIncrByBytes(); + } + + @Test + public void testHIncrBy() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testHIncrBy(); + } + + @Test + public void testHIncrByDoubleBytes() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testHIncrByDoubleBytes(); + } + + @Test + public void testHIncrByDouble() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testHIncrByDouble(); + } + + @Test + public void testHKeysBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testHKeysBytes(); + } + + @Test + public void testHKeys() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testHKeys(); + } + + @Test + public void testHLenBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testHLenBytes(); + } + + @Test + public void testHLen() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testHLen(); + } + + @Test + public void testHMGetBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testHMGetBytes(); + } + + @Test + public void testHMGet() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testHMGet(); + } + + @Test + public void testHSetBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHSetBytes(); + } + + @Test + public void testHSet() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHSet(); + } + + @Test + public void testHSetNXBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHSetNXBytes(); + } + + @Test + public void testHSetNX() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testHSetNX(); + } + + @Test + public void testHValsBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testHValsBytes(); + } + + @Test + public void testHVals() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testHVals(); + } + + @Test + public void testIncrBytes() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testIncrBytes(); + } + + @Test + public void testIncr() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testIncr(); + } + + @Test + public void testIncrByBytes() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testIncrByBytes(); + } + + @Test + public void testIncrBy() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testIncrBy(); + } + + @Test + public void testIncrByDoubleBytes() { + doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).closePipeline(); + super.testIncrByDoubleBytes(); + } + + @Test + public void testIncrByDouble() { + doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).closePipeline(); + super.testIncrByDouble(); + } + + @Test + public void testInfo() { + Properties props = new Properties(); + props.put("foo", "bar"); + doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).closePipeline(); + super.testInfo(); + } + + @Test + public void testInfoBySection() { + Properties props = new Properties(); + props.put("foo", "bar"); + doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).closePipeline(); + super.testInfoBySection(); + } + + @Test + public void testKeysBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testKeysBytes(); + } + + @Test + public void testKeys() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testKeys(); + } + + @Test + public void testLastSave() { + doReturn(Arrays.asList(new Object[] { 6l })).when(nativeConnection).closePipeline(); + super.testLastSave(); + } + + @Test + public void testLIndexBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testLIndexBytes(); + } + + @Test + public void testLIndex() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testLIndex(); + } + + @Test + public void testLInsertBytes() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLInsertBytes(); + } + + @Test + public void testLInsert() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLInsert(); + } + + @Test + public void testLLenBytes() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLLenBytes(); + } + + @Test + public void testLLen() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLLen(); + } + + @Test + public void testLPopBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + actual.add(connection.lPop(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testLPop() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testLPop(); + } + + @Test + public void testLPushBytes() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLPushBytes(); + } + + @Test + public void testLPush() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLPush(); + } + + @Test + public void testLPushXBytes() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLPushXBytes(); + } + + @Test + public void testLPushX() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLPushX(); + } + + @Test + public void testLRangeBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testLRangeBytes(); + } + + @Test + public void testLRange() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testLRange(); + } + + @Test + public void testLRemBytes() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLRemBytes(); + } + + @Test + public void testLRem() { + doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + super.testLRem(); + } + + @Test + public void testMGetBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testMGetBytes(); + } + + @Test + public void testMGet() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testMGet(); + } + + @Test + public void testMSetNXBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testMSetNXBytes(); + } + + @Test + public void testMSetNXString() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testMSetNXString(); + } + + @Test + public void testPersistBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPersistBytes(); + } + + @Test + public void testPersist() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPersist(); + } + + @Test + public void testMoveBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testMoveBytes(); + } + + @Test + public void testMove() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testMove(); + } + + @Test + public void testPing() { + doReturn(Arrays.asList(new Object[] { "pong" })).when(nativeConnection).closePipeline(); + super.testPing(); + } + + @Test + public void testPublishBytes() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testPublishBytes(); + } + + @Test + public void testPublish() { + doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + super.testPublish(); + } + + @Test + public void testRandomKey() { + doReturn(Arrays.asList(new Object[] { fooBytes })).when(nativeConnection).closePipeline(); + super.testRandomKey(); + } + + @Test + public void testRenameNXBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testRenameNXBytes(); + } + + @Test + public void testRenameNX() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testRenameNX(); + } + + @Test + public void testRPopBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testRPopBytes(); + } + + @Test + public void testRPop() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testRPop(); + } + + @Test + public void testRPopLPushBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testRPopLPushBytes(); + } + + @Test + public void testRPopLPush() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testRPopLPush(); + } + + @Test + public void testRPushBytes() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testRPushBytes(); + } + + @Test + public void testRPush() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testRPush(); + } + + @Test + public void testRPushXBytes() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testRPushXBytes(); + } + + @Test + public void testRPushX() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testRPushX(); + } + + @Test + public void testSAddBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSAddBytes(); + } + + @Test + public void testSAdd() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSAdd(); + } + + @Test + public void testSCardBytes() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testSCardBytes(); + } + + @Test + public void testSCard() { + doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + super.testSCard(); + } + + @Test + public void testSDiffBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSDiffBytes(); + } + + @Test + public void testSDiff() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSDiff(); + } + + @Test + public void testSDiffStoreBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSDiffStoreBytes(); + } + + @Test + public void testSDiffStore() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSDiffStore(); + } + + @Test + public void testSetNXBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSetNXBytes(); + } + + @Test + public void testSetNX() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSetNX(); + } + + @Test + public void testSInterBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSInterBytes(); + } + + @Test + public void testSInter() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSInter(); + } + + @Test + public void testSInterStoreBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSInterStoreBytes(); + } + + @Test + public void testSInterStore() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSInterStore(); + } + + @Test + public void testSIsMemberBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSIsMemberBytes(); + } + + @Test + public void testSIsMember() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSIsMember(); + } + + @Test + public void testSMembersBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSMembersBytes(); + } + + @Test + public void testSMembers() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSMembers(); + } + + @Test + public void testSMoveBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSMoveBytes(); + } + + @Test + public void testSMove() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSMove(); + } + + @Test + public void testSortStoreBytes() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSortStoreBytes(); + } + + @Test + public void testSortStore() { + doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + super.testSortStore(); + } + + @Test + public void testSortBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testSortBytes(); + } + + @Test + public void testSort() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testSort(); + } + + @Test + public void testSPopBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testSPopBytes(); + } + + @Test + public void testSPop() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testSPop(); + } + + @Test + public void testSRandMemberBytes() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testSRandMemberBytes(); + } + + @Test + public void testSRandMember() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testSRandMember(); + } + + @Test + public void testSRandMemberCountBytes() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testSRandMemberCountBytes(); + } + + @Test + public void testSRandMemberCount() { + doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + super.testSRandMemberCount(); + } + + @Test + public void testSRemBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSRemBytes(); + } + + @Test + public void testSRem() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testSRem(); + } + + @Test + public void testStrLenBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testStrLenBytes(); + } + + @Test + public void testStrLen() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testStrLen(); + } + + @Test + public void testBitCountBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitCountBytes(); + } + + @Test + public void testBitCount() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitCount(); + } + + @Test + public void testBitCountRangeBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitCountRangeBytes(); + } + + @Test + public void testBitCountRange() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitCountRange(); + } + + @Test + public void testBitOpBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitOpBytes(); + } + + @Test + public void testBitOp() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testBitOp(); + } + + @Test + public void testSUnionBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSUnionBytes(); + } + + @Test + public void testSUnion() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testSUnion(); + } + + @Test + public void testSUnionStoreBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testSUnionStoreBytes(); + } + + @Test + public void testSUnionStore() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testSUnionStore(); + } + + @Test + public void testTtlBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testTtlBytes(); + } + + @Test + public void testTtl() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testTtl(); + } + + @Test + public void testTypeBytes() { + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) + .closePipeline(); + super.testTypeBytes(); + } + + @Test + public void testType() { + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) + .closePipeline(); + super.testType(); + } + + @Test + public void testZAddBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testZAddBytes(); + } + + @Test + public void testZAdd() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testZAdd(); + } + + @Test + public void testZCardBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZCardBytes(); + } + + @Test + public void testZCard() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZCard(); + } + + @Test + public void testZCountBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZCountBytes(); + } + + @Test + public void testZCount() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZCount(); + } + + @Test + public void testZIncrByBytes() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testZIncrByBytes(); + } + + @Test + public void testZIncrBy() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testZIncrBy(); + } + + @Test + public void testZInterStoreAggWeightsBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZInterStoreAggWeightsBytes(); + } + + @Test + public void testZInterStoreAggWeights() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZInterStoreAggWeights(); + } + + @Test + public void testZInterStoreBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZInterStoreBytes(); + } + + @Test + public void testZInterStore() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZInterStore(); + } + + @Test + public void testZRangeBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRangeBytes(); + } + + @Test + public void testZRange() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRange(); + } + + @Test + public void testZRangeByScoreOffsetCountBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreOffsetCountBytes(); + } + + @Test + public void testZRangeByScoreOffsetCount() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreOffsetCount(); + } + + @Test + public void testZRangeByScoreBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreBytes(); + } + + @Test + public void testZRangeByScore() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScore(); + } + + @Test + public void testZRangeByScoreWithScoresOffsetCountBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreWithScoresOffsetCountBytes(); + } + + @Test + public void testZRangeByScoreWithScoresOffsetCount() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreWithScoresOffsetCount(); + } + + @Test + public void testZRangeByScoreWithScoresBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreWithScoresBytes(); + } + + @Test + public void testZRangeByScoreWithScores() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeByScoreWithScores(); + } + + @Test + public void testZRangeWithScoresBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeWithScoresBytes(); + } + + @Test + public void testZRangeWithScores() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRangeWithScores(); + } + + @Test + public void testZRevRangeByScoreOffsetCountBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeByScoreOffsetCountBytes(); + } + + @Test + public void testZRevRangeByScoreBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeByScoreBytes(); + } + + @Test + public void testZRevRangeByScoreWithScoresOffsetCountBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeByScoreWithScoresOffsetCountBytes(); + } + + @Test + public void testZRevRangeByScoreWithScoresBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeByScoreWithScoresBytes(); + } + + @Test + public void testZRankBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRankBytes(); + } + + @Test + public void testZRank() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRank(); + } + + @Test + public void testZRemBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testZRemBytes(); + } + + @Test + public void testZRem() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testZRem(); + } + + @Test + public void testZRemRangeBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRemRangeBytes(); + } + + @Test + public void testZRemRange() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRemRange(); + } + + @Test + public void testZRemRangeByScoreBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRemRangeByScoreBytes(); + } + + @Test + public void testZRemRangeByScore() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRemRangeByScore(); + } + + @Test + public void testZRevRangeBytes() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeBytes(); + } + + @Test + public void testZRevRange() { + doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + super.testZRevRange(); + } + + @Test + public void testZRevRangeWithScoresBytes() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeWithScoresBytes(); + } + + @Test + public void testZRevRangeWithScores() { + doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + super.testZRevRangeWithScores(); + } + + @Test + public void testZRevRankBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRevRankBytes(); + } + + @Test + public void testZRevRank() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZRevRank(); + } + + @Test + public void testZScoreBytes() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testZScoreBytes(); + } + + @Test + public void testZScore() { + doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + super.testZScore(); + } + + @Test + public void testZUnionStoreAggWeightsBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZUnionStoreAggWeightsBytes(); + } + + @Test + public void testZUnionStoreAggWeights() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZUnionStoreAggWeights(); + } + + @Test + public void testZUnionStoreBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZUnionStoreBytes(); + } + + @Test + public void testZUnionStore() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testZUnionStore(); + } + + @Test + public void testPExpireBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPExpireBytes(); + } + + @Test + public void testPExpire() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPExpire(); + } + + @Test + public void testPExpireAtBytes() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPExpireAtBytes(); + } + + @Test + public void testPExpireAt() { + doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + super.testPExpireAt(); + } + + @Test + public void testPTtlBytes() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testPTtlBytes(); + } + + @Test + public void testPTtl() { + doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + super.testPTtl(); + } + + @Test + public void testDump() { + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + super.testDump(); + } + + @Test + public void testScriptLoadBytes() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testScriptLoadBytes(); + } + + @Test + public void testScriptLoad() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testScriptLoad(); + } + + @Test + public void testScriptExists() { + List results = Collections.singletonList(true); + doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); + super.testScriptExists(); + } + + @Test + public void testEvalBytes() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testEvalBytes(); + } + + @Test + public void testEval() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testEval(); + } + + @Test + public void testEvalShaBytes() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testEvalShaBytes(); + } + + @Test + public void testEvalSha() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testEvalSha(); + } + + @Test + public void testExecute() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testExecute(); + } + + @Test + public void testExecuteByteArgs() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testExecuteByteArgs(); + } + + @Test + public void testExecuteStringArgs() { + doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + super.testExecuteStringArgs(); + } + + @Test + public void testDisablePipelineDeserialize() { + connection.setDeserializePipelineResults(false); + doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); + doReturn(barBytes).when(nativeConnection).get(fooBytes); + connection.get(foo); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testPipelineNotSameSizeAsResults() { + // Only call one method, but return 2 results from nativeConnection.closePipeline() + // Emulates scenario where user has called some methods directly on the native connection + // while pipeline is open + doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection) + .closePipeline(); + doReturn(barBytes).when(nativeConnection).get(fooBytes); + connection.get(foo); + verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); + } + + protected List getResults() { + return connection.closePipeline(); + } +} diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java new file mode 100644 index 000000000..b255b222d --- /dev/null +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -0,0 +1,1655 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Mockito.doReturn; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.data.redis.connection.RedisListCommands.Position; +import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; +import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; +import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * Unit test of {@link DefaultStringRedisConnection} + * + * @author Jennifer Hickey + * + */ +public class DefaultStringRedisConnectionTests { + + protected List actual = new ArrayList(); + + @Mock + protected RedisConnection nativeConnection; + + protected DefaultStringRedisConnection connection; + + protected StringRedisSerializer serializer = new StringRedisSerializer(); + + protected String foo = "foo"; + + protected String bar = "bar"; + + protected byte[] fooBytes = serializer.serialize(foo); + + protected byte[] barBytes = serializer.serialize(bar); + + protected List bytesList = Collections.singletonList(barBytes); + + protected List stringList = Collections.singletonList(bar); + + protected Set bytesSet = new LinkedHashSet(Collections.singletonList(barBytes)); + + protected Set stringSet = new LinkedHashSet(Collections.singletonList(bar)); + + protected Map bytesMap = new HashMap(); + + protected Map stringMap = new HashMap(); + + protected Set tupleSet = new HashSet(Collections.singletonList(new DefaultTuple( + barBytes, 3d))); + + protected Set stringTupleSet = new HashSet( + Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar))); + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + this.connection = new DefaultStringRedisConnection(nativeConnection); + bytesMap.put(fooBytes, barBytes); + stringMap.put(foo, bar); + } + + @Test + public void testAppend() { + doReturn(1l).when(nativeConnection).append(fooBytes, barBytes); + actual.add(connection.append(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testAppendBytes() { + doReturn(1l).when(nativeConnection).append(fooBytes, barBytes); + actual.add(connection.append(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testBlPopBytes() { + doReturn(bytesList).when(nativeConnection).bLPop(1, fooBytes); + actual.add(connection.bLPop(1, fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testBlPop() { + doReturn(bytesList).when(nativeConnection).bLPop(1, fooBytes); + actual.add(connection.bLPop(1, foo)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testBrPopBytes() { + doReturn(bytesList).when(nativeConnection).bRPop(1, fooBytes); + actual.add(connection.bRPop(1, fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testBrPop() { + doReturn(bytesList).when(nativeConnection).bRPop(1, fooBytes); + actual.add(connection.bRPop(1, foo)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testBrPopLPushBytes() { + doReturn(barBytes).when(nativeConnection).bRPopLPush(1, fooBytes, barBytes); + actual.add(connection.bRPopLPush(1, fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testBrPopLPush() { + doReturn(barBytes).when(nativeConnection).bRPopLPush(1, fooBytes, barBytes); + actual.add(connection.bRPopLPush(1, foo, bar)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testDbSize() { + doReturn(3l).when(nativeConnection).dbSize(); + actual.add(connection.dbSize()); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testDecrBytes() { + doReturn(3l).when(nativeConnection).decr(fooBytes); + actual.add(connection.decr(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testDecr() { + doReturn(3l).when(nativeConnection).decr(fooBytes); + actual.add(connection.decr(foo)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testDecrByBytes() { + doReturn(3l).when(nativeConnection).decrBy(fooBytes, 2l); + actual.add(connection.decrBy(fooBytes, 2l)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testDecrBy() { + doReturn(3l).when(nativeConnection).decrBy(fooBytes, 2l); + actual.add(connection.decrBy(foo, 2l)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testDelBytes() { + doReturn(1l).when(nativeConnection).del(fooBytes); + actual.add(connection.del(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testDel() { + doReturn(1l).when(nativeConnection).del(fooBytes); + actual.add(connection.del(foo)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testEchoBytes() { + doReturn(barBytes).when(nativeConnection).echo(fooBytes); + actual.add(connection.echo(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testEcho() { + doReturn(barBytes).when(nativeConnection).echo(fooBytes); + actual.add(connection.echo(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testExec() { + List results = Arrays.asList(new Object[] { barBytes }); + doReturn(results).when(nativeConnection).exec(); + actual.add(connection.exec()); + verifyResults(Arrays.asList(new Object[] { results })); + } + + @Test + public void testExistsBytes() { + doReturn(true).when(nativeConnection).exists(fooBytes); + actual.add(connection.exists(fooBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testExists() { + doReturn(true).when(nativeConnection).exists(fooBytes); + actual.add(connection.exists(foo)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testExpireBytes() { + doReturn(true).when(nativeConnection).expire(fooBytes, 1l); + actual.add(connection.expire(fooBytes, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testExpire() { + doReturn(true).when(nativeConnection).expire(fooBytes, 1l); + actual.add(connection.expire(foo, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testExpireAtBytes() { + doReturn(true).when(nativeConnection).expireAt(fooBytes, 1l); + actual.add(connection.expireAt(fooBytes, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testExpireAt() { + doReturn(true).when(nativeConnection).expireAt(fooBytes, 1l); + actual.add(connection.expireAt(foo, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testGetBytes() { + doReturn(barBytes).when(nativeConnection).get(fooBytes); + actual.add(connection.get(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testGet() { + doReturn(barBytes).when(nativeConnection).get(fooBytes); + actual.add(connection.get(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testGetBitBytes() { + doReturn(true).when(nativeConnection).getBit(fooBytes, 1l); + actual.add(connection.getBit(fooBytes, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testGetBit() { + doReturn(true).when(nativeConnection).getBit(fooBytes, 1l); + actual.add(connection.getBit(foo, 1l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testGetConfig() { + List results = Collections.singletonList("bar"); + doReturn(results).when(nativeConnection).getConfig("foo"); + actual.add(connection.getConfig("foo")); + verifyResults(Arrays.asList(new Object[] { results })); + } + + @Test + public void testGetNativeConnection() { + doReturn("foo").when(nativeConnection).getNativeConnection(); + actual.add(connection.getNativeConnection()); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testGetRangeBytes() { + doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1l, 2l); + actual.add(connection.getRange(fooBytes, 1l, 2l)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testGetRange() { + doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1l, 2l); + actual.add(connection.getRange(foo, 1l, 2l)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testGetSetBytes() { + doReturn(barBytes).when(nativeConnection).getSet(fooBytes, barBytes); + actual.add(connection.getSet(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testGetSet() { + doReturn(barBytes).when(nativeConnection).getSet(fooBytes, barBytes); + actual.add(connection.getSet(foo, bar)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testHDelBytes() { + doReturn(true).when(nativeConnection).hDel(fooBytes, barBytes); + actual.add(connection.hDel(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHDel() { + doReturn(true).when(nativeConnection).hDel(fooBytes, barBytes); + actual.add(connection.hDel(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHExistsBytes() { + doReturn(true).when(nativeConnection).hExists(fooBytes, barBytes); + actual.add(connection.hExists(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHExists() { + doReturn(true).when(nativeConnection).hExists(fooBytes, barBytes); + actual.add(connection.hExists(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHGetBytes() { + doReturn(barBytes).when(nativeConnection).hGet(fooBytes, barBytes); + actual.add(connection.hGet(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testHGet() { + doReturn(barBytes).when(nativeConnection).hGet(fooBytes, barBytes); + actual.add(connection.hGet(foo, bar)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testHGetAllBytes() { + doReturn(bytesMap).when(nativeConnection).hGetAll(barBytes); + actual.add(connection.hGetAll(barBytes)); + verifyResults(Arrays.asList(new Object[] { bytesMap })); + } + + @Test + public void testHGetAll() { + doReturn(bytesMap).when(nativeConnection).hGetAll(barBytes); + actual.add(connection.hGetAll(bar)); + verifyResults(Arrays.asList(new Object[] { stringMap })); + } + + @Test + public void testHIncrByBytes() { + doReturn(3l).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1l); + actual.add(connection.hIncrBy(fooBytes, barBytes, 1l)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testHIncrBy() { + doReturn(3l).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1l); + actual.add(connection.hIncrBy(foo, bar, 1l)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testHIncrByDoubleBytes() { + doReturn(3d).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1d); + actual.add(connection.hIncrBy(fooBytes, barBytes, 1d)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testHIncrByDouble() { + doReturn(3d).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1d); + actual.add(connection.hIncrBy(foo, bar, 1d)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testHKeysBytes() { + doReturn(bytesSet).when(nativeConnection).hKeys(fooBytes); + actual.add(connection.hKeys(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testHKeys() { + doReturn(bytesSet).when(nativeConnection).hKeys(fooBytes); + actual.add(connection.hKeys(foo)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testHLenBytes() { + doReturn(3l).when(nativeConnection).hLen(fooBytes); + actual.add(connection.hLen(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testHLen() { + doReturn(3l).when(nativeConnection).hLen(fooBytes); + actual.add(connection.hLen(foo)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testHMGetBytes() { + doReturn(bytesList).when(nativeConnection).hMGet(fooBytes, barBytes); + actual.add(connection.hMGet(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testHMGet() { + doReturn(bytesList).when(nativeConnection).hMGet(fooBytes, barBytes); + actual.add(connection.hMGet(foo, bar)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testHSetBytes() { + doReturn(true).when(nativeConnection).hSet(fooBytes, barBytes, fooBytes); + actual.add(connection.hSet(fooBytes, barBytes, fooBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHSet() { + doReturn(true).when(nativeConnection).hSet(fooBytes, barBytes, fooBytes); + actual.add(connection.hSet(foo, bar, foo)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHSetNXBytes() { + doReturn(true).when(nativeConnection).hSetNX(fooBytes, barBytes, fooBytes); + actual.add(connection.hSetNX(fooBytes, barBytes, fooBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHSetNX() { + doReturn(true).when(nativeConnection).hSetNX(fooBytes, barBytes, fooBytes); + actual.add(connection.hSetNX(foo, bar, foo)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testHValsBytes() { + doReturn(bytesList).when(nativeConnection).hVals(fooBytes); + actual.add(connection.hVals(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testHVals() { + doReturn(bytesList).when(nativeConnection).hVals(fooBytes); + actual.add(connection.hVals(foo)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testIncrBytes() { + doReturn(2l).when(nativeConnection).incr(fooBytes); + actual.add(connection.incr(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testIncr() { + doReturn(2l).when(nativeConnection).incr(fooBytes); + actual.add(connection.incr(foo)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testIncrByBytes() { + doReturn(2l).when(nativeConnection).incrBy(fooBytes, 1l); + actual.add(connection.incrBy(fooBytes, 1l)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testIncrBy() { + doReturn(2l).when(nativeConnection).incrBy(fooBytes, 1l); + actual.add(connection.incrBy(foo, 1l)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testIncrByDoubleBytes() { + doReturn(2d).when(nativeConnection).incrBy(fooBytes, 1d); + actual.add(connection.incrBy(fooBytes, 1d)); + verifyResults(Arrays.asList(new Object[] { 2d })); + } + + @Test + public void testIncrByDouble() { + doReturn(2d).when(nativeConnection).incrBy(fooBytes, 1d); + actual.add(connection.incrBy(foo, 1d)); + verifyResults(Arrays.asList(new Object[] { 2d })); + } + + @Test + public void testInfo() { + Properties props = new Properties(); + props.put("foo", "bar"); + doReturn(props).when(nativeConnection).info(); + actual.add(connection.info()); + verifyResults(Arrays.asList(new Object[] { props })); + } + + @Test + public void testInfoBySection() { + Properties props = new Properties(); + props.put("foo", "bar"); + doReturn(props).when(nativeConnection).info("foo"); + actual.add(connection.info("foo")); + verifyResults(Arrays.asList(new Object[] { props })); + } + + @Test + public void testKeysBytes() { + doReturn(bytesSet).when(nativeConnection).keys(fooBytes); + actual.add(connection.keys(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testKeys() { + doReturn(bytesSet).when(nativeConnection).keys(fooBytes); + actual.add(connection.keys(foo)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testLastSave() { + doReturn(6l).when(nativeConnection).lastSave(); + actual.add(connection.lastSave()); + verifyResults(Arrays.asList(new Object[] { 6l })); + } + + @Test + public void testLIndexBytes() { + doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8l); + actual.add(connection.lIndex(fooBytes, 8l)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testLIndex() { + doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8l); + actual.add(connection.lIndex(foo, 8l)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testLInsertBytes() { + doReturn(8l).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); + actual.add(connection.lInsert(fooBytes, Position.AFTER, fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLInsert() { + doReturn(8l).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); + actual.add(connection.lInsert(foo, Position.AFTER, foo, bar)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLLenBytes() { + doReturn(8l).when(nativeConnection).lLen(fooBytes); + actual.add(connection.lLen(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLLen() { + doReturn(8l).when(nativeConnection).lLen(fooBytes); + actual.add(connection.lLen(foo)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLPopBytes() { + doReturn(barBytes).when(nativeConnection).lPop(fooBytes); + actual.add(connection.lPop(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testLPop() { + doReturn(barBytes).when(nativeConnection).lPop(fooBytes); + actual.add(connection.lPop(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testLPushBytes() { + doReturn(8l).when(nativeConnection).lPush(fooBytes, barBytes); + actual.add(connection.lPush(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLPush() { + doReturn(8l).when(nativeConnection).lPush(fooBytes, barBytes); + actual.add(connection.lPush(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLPushXBytes() { + doReturn(8l).when(nativeConnection).lPushX(fooBytes, barBytes); + actual.add(connection.lPushX(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLPushX() { + doReturn(8l).when(nativeConnection).lPushX(fooBytes, barBytes); + actual.add(connection.lPushX(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLRangeBytes() { + doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1l, 2l); + actual.add(connection.lRange(fooBytes, 1l, 2l)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testLRange() { + doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1l, 2l); + actual.add(connection.lRange(foo, 1l, 2l)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testLRemBytes() { + doReturn(8l).when(nativeConnection).lRem(fooBytes, 1l, barBytes); + actual.add(connection.lRem(fooBytes, 1l, barBytes)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testLRem() { + doReturn(8l).when(nativeConnection).lRem(fooBytes, 1l, barBytes); + actual.add(connection.lRem(foo, 1l, bar)); + verifyResults(Arrays.asList(new Object[] { 8l })); + } + + @Test + public void testMGetBytes() { + doReturn(bytesList).when(nativeConnection).mGet(fooBytes); + actual.add(connection.mGet(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testMGet() { + doReturn(bytesList).when(nativeConnection).mGet(fooBytes); + actual.add(connection.mGet(foo)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testMSetNXBytes() { + doReturn(true).when(nativeConnection).mSetNX(bytesMap); + actual.add(connection.mSetNX(bytesMap)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @SuppressWarnings("unchecked") + @Test + public void testMSetNXString() { + doReturn(true).when(nativeConnection).mSetNX(anyMap()); + actual.add(connection.mSetNXString(stringMap)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPersistBytes() { + doReturn(true).when(nativeConnection).persist(fooBytes); + actual.add(connection.persist(fooBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPersist() { + doReturn(true).when(nativeConnection).persist(fooBytes); + actual.add(connection.persist(foo)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testMoveBytes() { + doReturn(true).when(nativeConnection).move(fooBytes, 1); + actual.add(connection.move(fooBytes, 1)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testMove() { + doReturn(true).when(nativeConnection).move(fooBytes, 1); + actual.add(connection.move(foo, 1)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPing() { + doReturn("pong").when(nativeConnection).ping(); + actual.add(connection.ping()); + verifyResults(Arrays.asList(new Object[] { "pong" })); + } + + @Test + public void testPublishBytes() { + doReturn(2l).when(nativeConnection).publish(fooBytes, barBytes); + actual.add(connection.publish(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testPublish() { + doReturn(2l).when(nativeConnection).publish(fooBytes, barBytes); + actual.add(connection.publish(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 2l })); + } + + @Test + public void testRandomKey() { + doReturn(fooBytes).when(nativeConnection).randomKey(); + actual.add(connection.randomKey()); + verifyResults(Arrays.asList(new Object[] { fooBytes })); + } + + @Test + public void testRenameNXBytes() { + doReturn(true).when(nativeConnection).renameNX(fooBytes, barBytes); + actual.add(connection.renameNX(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testRenameNX() { + doReturn(true).when(nativeConnection).renameNX(fooBytes, barBytes); + actual.add(connection.renameNX(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testRPopBytes() { + doReturn(barBytes).when(nativeConnection).rPop(fooBytes); + actual.add(connection.rPop(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testRPop() { + doReturn(barBytes).when(nativeConnection).rPop(fooBytes); + actual.add(connection.rPop(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testRPopLPushBytes() { + doReturn(barBytes).when(nativeConnection).rPopLPush(fooBytes, barBytes); + actual.add(connection.rPopLPush(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testRPopLPush() { + doReturn(barBytes).when(nativeConnection).rPopLPush(fooBytes, barBytes); + actual.add(connection.rPopLPush(foo, bar)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testRPushBytes() { + doReturn(4l).when(nativeConnection).rPush(fooBytes, barBytes); + actual.add(connection.rPush(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testRPush() { + doReturn(4l).when(nativeConnection).rPush(fooBytes, barBytes); + actual.add(connection.rPush(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testRPushXBytes() { + doReturn(4l).when(nativeConnection).rPushX(fooBytes, barBytes); + actual.add(connection.rPushX(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testRPushX() { + doReturn(4l).when(nativeConnection).rPushX(fooBytes, barBytes); + actual.add(connection.rPushX(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testSAddBytes() { + doReturn(true).when(nativeConnection).sAdd(fooBytes, barBytes); + actual.add(connection.sAdd(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSAdd() { + doReturn(true).when(nativeConnection).sAdd(fooBytes, barBytes); + actual.add(connection.sAdd(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSCardBytes() { + doReturn(4l).when(nativeConnection).sCard(fooBytes); + actual.add(connection.sCard(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testSCard() { + doReturn(4l).when(nativeConnection).sCard(fooBytes); + actual.add(connection.sCard(foo)); + verifyResults(Arrays.asList(new Object[] { 4l })); + } + + @Test + public void testSDiffBytes() { + doReturn(bytesSet).when(nativeConnection).sDiff(fooBytes); + actual.add(connection.sDiff(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testSDiff() { + doReturn(bytesSet).when(nativeConnection).sDiff(fooBytes); + actual.add(connection.sDiff(foo)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testSDiffStoreBytes() { + doReturn(3l).when(nativeConnection).sDiffStore(fooBytes, barBytes); + actual.add(connection.sDiffStore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSDiffStore() { + doReturn(3l).when(nativeConnection).sDiffStore(fooBytes, barBytes); + actual.add(connection.sDiffStore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSetNXBytes() { + doReturn(true).when(nativeConnection).setNX(fooBytes, barBytes); + actual.add(connection.setNX(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSetNX() { + doReturn(true).when(nativeConnection).setNX(fooBytes, barBytes); + actual.add(connection.setNX(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSInterBytes() { + doReturn(bytesSet).when(nativeConnection).sInter(fooBytes, barBytes); + actual.add(connection.sInter(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testSInter() { + doReturn(bytesSet).when(nativeConnection).sInter(fooBytes, barBytes); + actual.add(connection.sInter(foo, bar)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testSInterStoreBytes() { + doReturn(3l).when(nativeConnection).sInterStore(fooBytes, barBytes); + actual.add(connection.sInterStore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSInterStore() { + doReturn(3l).when(nativeConnection).sInterStore(fooBytes, barBytes); + actual.add(connection.sInterStore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSIsMemberBytes() { + doReturn(true).when(nativeConnection).sIsMember(fooBytes, barBytes); + actual.add(connection.sIsMember(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSIsMember() { + doReturn(true).when(nativeConnection).sIsMember(fooBytes, barBytes); + actual.add(connection.sIsMember(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSMembersBytes() { + doReturn(bytesSet).when(nativeConnection).sMembers(fooBytes); + actual.add(connection.sMembers(fooBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testSMembers() { + doReturn(bytesSet).when(nativeConnection).sMembers(fooBytes); + actual.add(connection.sMembers(foo)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testSMoveBytes() { + doReturn(true).when(nativeConnection).sMove(fooBytes, barBytes, fooBytes); + actual.add(connection.sMove(fooBytes, barBytes, fooBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSMove() { + doReturn(true).when(nativeConnection).sMove(fooBytes, barBytes, fooBytes); + actual.add(connection.sMove(foo, bar, foo)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSortStoreBytes() { + doReturn(3l).when(nativeConnection).sort(fooBytes, null, barBytes); + actual.add(connection.sort(fooBytes, null, barBytes)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSortStore() { + doReturn(3l).when(nativeConnection).sort(fooBytes, null, barBytes); + actual.add(connection.sort(foo, null, bar)); + verifyResults(Arrays.asList(new Object[] { 3l })); + } + + @Test + public void testSortBytes() { + doReturn(bytesList).when(nativeConnection).sort(fooBytes, null); + actual.add(connection.sort(fooBytes, null)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testSort() { + doReturn(bytesList).when(nativeConnection).sort(fooBytes, null); + actual.add(connection.sort(foo, null)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testSPopBytes() { + doReturn(barBytes).when(nativeConnection).sPop(fooBytes); + actual.add(connection.sPop(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testSPop() { + doReturn(barBytes).when(nativeConnection).sPop(fooBytes); + actual.add(connection.sPop(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testSRandMemberBytes() { + doReturn(barBytes).when(nativeConnection).sRandMember(fooBytes); + actual.add(connection.sRandMember(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testSRandMember() { + doReturn(barBytes).when(nativeConnection).sRandMember(fooBytes); + actual.add(connection.sRandMember(foo)); + verifyResults(Arrays.asList(new Object[] { bar })); + } + + @Test + public void testSRandMemberCountBytes() { + doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5l); + actual.add(connection.sRandMember(fooBytes, 5l)); + verifyResults(Arrays.asList(new Object[] { bytesList })); + } + + @Test + public void testSRandMemberCount() { + doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5l); + actual.add(connection.sRandMember(foo, 5l)); + verifyResults(Arrays.asList(new Object[] { stringList })); + } + + @Test + public void testSRemBytes() { + doReturn(true).when(nativeConnection).sRem(fooBytes, barBytes); + actual.add(connection.sRem(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testSRem() { + doReturn(true).when(nativeConnection).sRem(fooBytes, barBytes); + actual.add(connection.sRem(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testStrLenBytes() { + doReturn(5l).when(nativeConnection).strLen(fooBytes); + actual.add(connection.strLen(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testStrLen() { + doReturn(5l).when(nativeConnection).strLen(fooBytes); + actual.add(connection.strLen(foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitCountBytes() { + doReturn(5l).when(nativeConnection).bitCount(fooBytes); + actual.add(connection.bitCount(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitCount() { + doReturn(5l).when(nativeConnection).bitCount(fooBytes); + actual.add(connection.bitCount(foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitCountRangeBytes() { + doReturn(5l).when(nativeConnection).bitCount(fooBytes, 2l, 5l); + actual.add(connection.bitCount(fooBytes, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitCountRange() { + doReturn(5l).when(nativeConnection).bitCount(fooBytes, 2l, 5l); + actual.add(connection.bitCount(foo, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitOpBytes() { + doReturn(5l).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); + actual.add(connection.bitOp(BitOperation.AND, fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testBitOp() { + doReturn(5l).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); + actual.add(connection.bitOp(BitOperation.AND, foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testSUnionBytes() { + doReturn(bytesSet).when(nativeConnection).sUnion(fooBytes, barBytes); + actual.add(connection.sUnion(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testSUnion() { + doReturn(bytesSet).when(nativeConnection).sUnion(fooBytes, barBytes); + actual.add(connection.sUnion(foo, bar)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testSUnionStoreBytes() { + doReturn(5l).when(nativeConnection).sUnionStore(fooBytes, barBytes); + actual.add(connection.sUnionStore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testSUnionStore() { + doReturn(5l).when(nativeConnection).sUnionStore(fooBytes, barBytes); + actual.add(connection.sUnionStore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testTtlBytes() { + doReturn(5l).when(nativeConnection).ttl(fooBytes); + actual.add(connection.ttl(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testTtl() { + doReturn(5l).when(nativeConnection).ttl(fooBytes); + actual.add(connection.ttl(foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testTypeBytes() { + doReturn(DataType.HASH).when(nativeConnection).type(fooBytes); + actual.add(connection.type(fooBytes)); + verifyResults(Arrays.asList(new Object[] { DataType.HASH })); + } + + @Test + public void testType() { + doReturn(DataType.HASH).when(nativeConnection).type(fooBytes); + actual.add(connection.type(foo)); + verifyResults(Arrays.asList(new Object[] { DataType.HASH })); + } + + @Test + public void testZAddBytes() { + doReturn(true).when(nativeConnection).zAdd(fooBytes, 3d, barBytes); + actual.add(connection.zAdd(fooBytes, 3d, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testZAdd() { + doReturn(true).when(nativeConnection).zAdd(fooBytes, 3d, barBytes); + actual.add(connection.zAdd(foo, 3d, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testZCardBytes() { + doReturn(5l).when(nativeConnection).zCard(fooBytes); + actual.add(connection.zCard(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZCard() { + doReturn(5l).when(nativeConnection).zCard(fooBytes); + actual.add(connection.zCard(foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZCountBytes() { + doReturn(5l).when(nativeConnection).zCount(fooBytes, 2d, 3d); + actual.add(connection.zCount(fooBytes, 2d, 3d)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZCount() { + doReturn(5l).when(nativeConnection).zCount(fooBytes, 2d, 3d); + actual.add(connection.zCount(foo, 2d, 3d)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZIncrByBytes() { + doReturn(3d).when(nativeConnection).zIncrBy(fooBytes, 2d, barBytes); + actual.add(connection.zIncrBy(fooBytes, 2d, barBytes)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testZIncrBy() { + doReturn(3d).when(nativeConnection).zIncrBy(fooBytes, 2d, barBytes); + actual.add(connection.zIncrBy(foo, 2d, bar)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testZInterStoreAggWeightsBytes() { + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], + fooBytes); + actual.add(connection.zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZInterStoreAggWeights() { + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], + fooBytes); + actual.add(connection.zInterStore(foo, Aggregate.MAX, new int[0], foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZInterStoreBytes() { + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, barBytes); + actual.add(connection.zInterStore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZInterStore() { + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, barBytes); + actual.add(connection.zInterStore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRangeBytes() { + doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1l, 3l); + actual.add(connection.zRange(fooBytes, 1l, 3l)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRange() { + doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1l, 3l); + actual.add(connection.zRange(foo, 1l, 3l)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testZRangeByScoreOffsetCountBytes() { + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5l, 7l); + actual.add(connection.zRangeByScore(fooBytes, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRangeByScoreOffsetCount() { + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5l, 7l); + actual.add(connection.zRangeByScore(foo, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testZRangeByScoreBytes() { + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d); + actual.add(connection.zRangeByScore(fooBytes, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRangeByScore() { + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d); + actual.add(connection.zRangeByScore(foo, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testZRangeByScoreWithScoresOffsetCountBytes() { + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); + actual.add(connection.zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRangeByScoreWithScoresOffsetCount() { + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); + actual.add(connection.zRangeByScoreWithScores(foo, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + } + + @Test + public void testZRangeByScoreWithScoresBytes() { + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d); + actual.add(connection.zRangeByScoreWithScores(fooBytes, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRangeByScoreWithScores() { + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d); + actual.add(connection.zRangeByScoreWithScores(foo, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + } + + @Test + public void testZRangeWithScoresBytes() { + doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1l, 3l); + actual.add(connection.zRangeWithScores(fooBytes, 1l, 3l)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRangeWithScores() { + doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1l, 3l); + actual.add(connection.zRangeWithScores(foo, 1l, 3l)); + verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + } + + @Test + public void testZRevRangeByScoreOffsetCountBytes() { + doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d, 5l, 7l); + actual.add(connection.zRevRangeByScore(fooBytes, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRevRangeByScoreBytes() { + doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d); + actual.add(connection.zRevRangeByScore(fooBytes, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRevRangeByScoreWithScoresOffsetCountBytes() { + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, + 7l); + actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRevRangeByScoreWithScoresBytes() { + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d); + actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRankBytes() { + doReturn(5l).when(nativeConnection).zRank(fooBytes, barBytes); + actual.add(connection.zRank(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRank() { + doReturn(5l).when(nativeConnection).zRank(fooBytes, barBytes); + actual.add(connection.zRank(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRemBytes() { + doReturn(true).when(nativeConnection).zRem(fooBytes, barBytes); + actual.add(connection.zRem(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testZRem() { + doReturn(true).when(nativeConnection).zRem(fooBytes, barBytes); + actual.add(connection.zRem(foo, bar)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testZRemRangeBytes() { + doReturn(5l).when(nativeConnection).zRemRange(fooBytes, 2l, 5l); + actual.add(connection.zRemRange(fooBytes, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRemRange() { + doReturn(5l).when(nativeConnection).zRemRange(fooBytes, 2l, 5l); + actual.add(connection.zRemRange(foo, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRemRangeByScoreBytes() { + doReturn(5l).when(nativeConnection).zRemRangeByScore(fooBytes, 2l, 5l); + actual.add(connection.zRemRangeByScore(fooBytes, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRemRangeByScore() { + doReturn(5l).when(nativeConnection).zRemRangeByScore(fooBytes, 2l, 5l); + actual.add(connection.zRemRangeByScore(foo, 2l, 5l)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRevRangeBytes() { + doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3l, 4l); + actual.add(connection.zRevRange(fooBytes, 3l, 4l)); + verifyResults(Arrays.asList(new Object[] { bytesSet })); + } + + @Test + public void testZRevRange() { + doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3l, 4l); + actual.add(connection.zRevRange(foo, 3l, 4l)); + verifyResults(Arrays.asList(new Object[] { stringSet })); + } + + @Test + public void testZRevRangeWithScoresBytes() { + doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3l, 4l); + actual.add(connection.zRevRangeWithScores(fooBytes, 3l, 4l)); + verifyResults(Arrays.asList(new Object[] { tupleSet })); + } + + @Test + public void testZRevRangeWithScores() { + doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3l, 4l); + actual.add(connection.zRevRangeWithScores(foo, 3l, 4l)); + verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + } + + @Test + public void testZRevRankBytes() { + doReturn(5l).when(nativeConnection).zRevRank(fooBytes, barBytes); + actual.add(connection.zRevRank(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZRevRank() { + doReturn(5l).when(nativeConnection).zRevRank(fooBytes, barBytes); + actual.add(connection.zRevRank(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZScoreBytes() { + doReturn(3d).when(nativeConnection).zScore(fooBytes, barBytes); + actual.add(connection.zScore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testZScore() { + doReturn(3d).when(nativeConnection).zScore(fooBytes, barBytes); + actual.add(connection.zScore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 3d })); + } + + @Test + public void testZUnionStoreAggWeightsBytes() { + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], + fooBytes); + actual.add(connection.zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZUnionStoreAggWeights() { + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], + fooBytes); + actual.add(connection.zUnionStore(foo, Aggregate.MAX, new int[0], foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZUnionStoreBytes() { + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, barBytes); + actual.add(connection.zUnionStore(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testZUnionStore() { + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, barBytes); + actual.add(connection.zUnionStore(foo, bar)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testPExpireBytes() { + doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); + actual.add(connection.pExpire(fooBytes, 34l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPExpire() { + doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); + actual.add(connection.pExpire(foo, 34l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPExpireAtBytes() { + doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34l); + actual.add(connection.pExpireAt(fooBytes, 34l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPExpireAt() { + doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34l); + actual.add(connection.pExpireAt(foo, 34l)); + verifyResults(Arrays.asList(new Object[] { true })); + } + + @Test + public void testPTtlBytes() { + doReturn(5l).when(nativeConnection).pTtl(fooBytes); + actual.add(connection.pTtl(fooBytes)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testPTtl() { + doReturn(5l).when(nativeConnection).pTtl(fooBytes); + actual.add(connection.pTtl(foo)); + verifyResults(Arrays.asList(new Object[] { 5l })); + } + + @Test + public void testDump() { + doReturn(barBytes).when(nativeConnection).dump(fooBytes); + actual.add(connection.dump(fooBytes)); + verifyResults(Arrays.asList(new Object[] { barBytes })); + } + + @Test + public void testScriptLoadBytes() { + doReturn("foo").when(nativeConnection).scriptLoad(fooBytes); + actual.add(connection.scriptLoad(fooBytes)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testScriptLoad() { + doReturn("foo").when(nativeConnection).scriptLoad(fooBytes); + actual.add(connection.scriptLoad(foo)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testScriptExists() { + List results = Collections.singletonList(true); + doReturn(results).when(nativeConnection).scriptExists("456"); + actual.add(connection.scriptExists("456")); + verifyResults(Arrays.asList(new Object[] { results })); + } + + @Test + public void testEvalBytes() { + doReturn("foo").when(nativeConnection).eval(fooBytes, ReturnType.VALUE, 3, fooBytes); + actual.add(connection.eval(fooBytes, ReturnType.VALUE, 3, fooBytes)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testEval() { + doReturn("foo").when(nativeConnection).eval(fooBytes, ReturnType.VALUE, 3, fooBytes); + actual.add(connection.eval(foo, ReturnType.VALUE, 3, foo)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testEvalShaBytes() { + doReturn("foo").when(nativeConnection).evalSha("456", ReturnType.VALUE, 3, fooBytes); + actual.add(connection.evalSha("456", ReturnType.VALUE, 3, fooBytes)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testEvalSha() { + doReturn("foo").when(nativeConnection).evalSha("456", ReturnType.VALUE, 3, fooBytes); + actual.add(connection.evalSha("456", ReturnType.VALUE, 3, foo)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testExecute() { + doReturn("foo").when(nativeConnection).execute("something", (byte[][]) null); + actual.add(connection.execute("something")); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testExecuteByteArgs() { + doReturn("foo").when(nativeConnection).execute("something", fooBytes); + actual.add(connection.execute("something", fooBytes)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + @Test + public void testExecuteStringArgs() { + doReturn("foo").when(nativeConnection).execute("something", fooBytes); + actual.add(connection.execute("something", foo)); + verifyResults(Arrays.asList(new Object[] { "foo" })); + } + + protected List getResults() { + return actual; + } + + protected void verifyResults(List expected) { + assertEquals(expected, getResults()); + } +} diff --git a/src/test/java/org/springframework/data/redis/core/StringRedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/StringRedisTemplateTests.java index 3b310d747..6e677a456 100644 --- a/src/test/java/org/springframework/data/redis/core/StringRedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/StringRedisTemplateTests.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.springframework.data.redis.SpinBarrier.waitFor; +import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -111,4 +112,38 @@ public class StringRedisTemplateTests { }); assertEquals(value,"it"); } + + @Test + public void testStringTemplateExecutePipelineResultsConverted() { + String result = redisTemplate.execute(new RedisCallback() { + public String doInRedis(RedisConnection connection) { + StringRedisConnection stringConn = (StringRedisConnection) connection; + stringConn.openPipeline(); + stringConn.set("foo", "bar"); + stringConn.get("foo"); + List results = stringConn.closePipeline(); + return (String) results.get(0); + } + }); + assertEquals("bar",result); + } + + @Test + public void testStringTemplateExecutePipelineResultsNotConverted() { + final StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory()); + template2.setDeserializePipelineResults(false); + template2.afterPropertiesSet(); + String result = template2.execute(new RedisCallback() { + public String doInRedis(RedisConnection connection) { + StringRedisConnection stringConn = (StringRedisConnection) connection; + stringConn.openPipeline(); + stringConn.set("foo", "bar"); + stringConn.get("foo"); + List results = stringConn.closePipeline(); + // Results should be in byte[], not deserialized to String + return template2.getStringSerializer().deserialize((byte[]) results.get(0)); + } + }); + assertEquals("bar",result); + } }