Add Redis 2.6 bitop and bitcount commands to Connections
DATAREDIS-179
This commit is contained in:
@@ -49,6 +49,7 @@ import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.TestCondition;
|
||||
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.SortParameters.Order;
|
||||
@@ -227,6 +228,77 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
verifyResults(Arrays.asList(new Object[] { false, true }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitCount() {
|
||||
String key = "bitset-test";
|
||||
connection.setBit(key, 0, false);
|
||||
connection.setBit(key, 1, true);
|
||||
connection.setBit(key, 2, true);
|
||||
actual.add(connection.bitCount(key));
|
||||
verifyResults(new ArrayList<Object>(Collections.singletonList(2l)), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitCountInterval() {
|
||||
connection.set("mykey", "foobar");
|
||||
actual.add(connection.bitCount("mykey", 1, 1));
|
||||
verifyResults(new ArrayList<Object>(Collections.singletonList(26l)), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitCountNonExistentKey() {
|
||||
actual.add(connection.bitCount("mykey"));
|
||||
verifyResults(new ArrayList<Object>(Collections.singletonList(0l)), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpAnd() {
|
||||
connection.set("key1", "foo");
|
||||
connection.set("key2", "bar");
|
||||
actual.add(connection.bitOp(BitOperation.AND, "key3", "key1", "key2"));
|
||||
actual.add(connection.get("key3"));
|
||||
verifyResults(Arrays.asList(new Object[] { 3l, "bab" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpOr() {
|
||||
connection.set("key1", "foo");
|
||||
connection.set("key2", "ugh");
|
||||
actual.add(connection.bitOp(BitOperation.OR, "key3", "key1", "key2"));
|
||||
actual.add(connection.get("key3"));
|
||||
verifyResults(Arrays.asList(new Object[] { 3l, "woo" }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpXOr() {
|
||||
connection.set("key1", "abcd");
|
||||
connection.set("key2", "efgh");
|
||||
actual.add(connection.bitOp(BitOperation.XOR, "key3", "key1", "key2"));
|
||||
verifyResults(Arrays.asList(new Object[] { 4l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNot() {
|
||||
connection.set("key1", "abcd");
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1"));
|
||||
verifyResults(Arrays.asList(new Object[] { 4l }), actual);
|
||||
}
|
||||
|
||||
@Test(expected=RedisSystemException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNotMultipleSources() {
|
||||
connection.set("key1", "abcd");
|
||||
connection.set("key2", "efgh");
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInfo() throws Exception {
|
||||
Properties info = connection.info();
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.TestCondition;
|
||||
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;
|
||||
@@ -262,6 +263,26 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends
|
||||
verifyResults(Arrays.asList(new Object[] { 0l, 0l, 0l, 1l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitCount() {
|
||||
String key = "bitset-test";
|
||||
connection.setBit(key, 0, false);
|
||||
connection.setBit(key, 1, true);
|
||||
connection.setBit(key, 2, true);
|
||||
actual.add(connection.bitCount(key));
|
||||
verifyResults(Arrays.asList(new Object[] { 0l, 0l, 0l, 2l }), actual);
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNotMultipleSources() {
|
||||
connection.set("key1", "abcd");
|
||||
connection.set("key2", "efgh");
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
getResults();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
connection.set("dbparam", "foo");
|
||||
|
||||
@@ -105,6 +105,46 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
super.testRestoreTtl();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCount() {
|
||||
super.testBitCount();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountInterval() {
|
||||
super.testBitCountInterval();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountNonExistentKey() {
|
||||
super.testBitCountNonExistentKey();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpAnd() {
|
||||
super.testBitOpAnd();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpOr() {
|
||||
super.testBitOpOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpXOr() {
|
||||
super.testBitOpXOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNot() {
|
||||
super.testBitOpNot();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNotMultipleSources() {
|
||||
super.testBitOpNotMultipleSources();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrDecrByLong() {
|
||||
String key = "test.count";
|
||||
|
||||
@@ -152,6 +152,46 @@ public class JedisConnectionPipelineIntegrationTests extends
|
||||
super.testBitSet();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCount() {
|
||||
connection.bitCount("foo");
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountInterval() {
|
||||
super.testBitCountInterval();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountNonExistentKey() {
|
||||
super.testBitCountNonExistentKey();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpAnd() {
|
||||
super.testBitOpAnd();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpOr() {
|
||||
super.testBitOpOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpXOr() {
|
||||
super.testBitOpXOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNot() {
|
||||
super.testBitOpNot();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNotMultipleSources() {
|
||||
super.testBitOpNotMultipleSources();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
public void testRandomKey() {
|
||||
super.testRandomKey();
|
||||
|
||||
@@ -343,6 +343,46 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
super.testRestoreTtl();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCount() {
|
||||
super.testBitCount();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountInterval() {
|
||||
super.testBitCountInterval();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitCountNonExistentKey() {
|
||||
super.testBitCountNonExistentKey();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpAnd() {
|
||||
super.testBitOpAnd();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpOr() {
|
||||
super.testBitOpOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpXOr() {
|
||||
super.testBitOpXOr();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNot() {
|
||||
super.testBitOpNot();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testBitOpNotMultipleSources() {
|
||||
super.testBitOpNotMultipleSources();
|
||||
}
|
||||
|
||||
// Jredis returns null for rPush
|
||||
@Test
|
||||
public void testSort() {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -125,4 +126,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
public void testSelect() {
|
||||
connection.select(1);
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNotMultipleSources() {
|
||||
connection.set("key1", "abcd");
|
||||
connection.set("key2", "efgh");
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.data.redis.SpinBarrier.waitFor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -36,6 +37,7 @@ import org.springframework.data.redis.TestCondition;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -337,6 +339,19 @@ public class LettuceConnectionPipelineIntegrationTests extends
|
||||
}, 1000l));
|
||||
}
|
||||
|
||||
// LettuceConnection throws an UnsupportedOpException before we close the pipeline
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNotMultipleSources() {
|
||||
connection.set("key1", "abcd");
|
||||
connection.set("key2", "efgh");
|
||||
try {
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
}finally {
|
||||
getResults();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Object convertResult(Object result) {
|
||||
Object convertedResult = super.convertResult(result);
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -111,6 +111,14 @@ public class SrpConnectionTransactionIntegrationTests extends SrpConnectionPipel
|
||||
// as Exceptions
|
||||
}
|
||||
|
||||
@Ignore("https://github.com/spullara/redis-protocol/issues/24")
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testBitOpNotMultipleSources() {
|
||||
// SRP issue exec does not report individual ErrorReplys in a MultiBulkReply
|
||||
// as Exceptions
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
connection.multi();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user