DATAREDIS-334 - Add binary alternative for RedisScriptingCommands.evalSha.

Introduced new evalSha method that accepts a byte[] as scriptSha as well
as a variable number of byte[] as keyValueArgs.

Original pull request: #99.
This commit is contained in:
David Liu
2014-08-30 07:33:24 +08:00
committed by Thomas Darimont
parent 9ecad07587
commit 4711693669
15 changed files with 150 additions and 3 deletions

View File

@@ -188,6 +188,20 @@ public abstract class AbstractConnectionIntegrationTests {
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
@Test(expected = RedisSystemException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {

View File

@@ -35,6 +35,7 @@ import org.springframework.util.ObjectUtils;
/**
* @author Christoph Strobl
* @author David Liu
*/
public class RedisConnectionUnitTests {
@@ -784,5 +785,10 @@ public class RedisConnectionUnitTests {
}
return null;
}
@Override
public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return delegate.evalSha(scriptSha, returnType, numKeys, keysAndArgs);
}
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -87,6 +88,20 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection = null;
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
@Test
public void testCreateConnectionWithDb() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();

View File

@@ -135,6 +135,12 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
super.testEvalShaArrayBytes();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")

View File

@@ -19,6 +19,7 @@ import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
@@ -66,6 +67,12 @@ public class JedisConnectionTransactionIntegrationTests extends AbstractConnecti
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
super.testEvalShaArrayBytes();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")

View File

@@ -435,6 +435,12 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
public void testEvalShaArrayStrings() {
super.testEvalShaArrayStrings();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
super.testEvalShaArrayBytes();
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")

View File

@@ -297,4 +297,19 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
}

View File

@@ -16,7 +16,10 @@
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsInstanceOf;
@@ -99,4 +102,19 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
Assert.assertThat(replies[1].data(), Is.<Object> is("cool".getBytes()));
Assert.assertThat(replies[2].data(), Is.<Object> is("supercalifragilisticexpialidocious".getBytes()));
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
}

View File

@@ -15,7 +15,10 @@
*/
package org.springframework.data.redis.connection.srp;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,4 +71,19 @@ public class SrpConnectionPipelineIntegrationTests extends AbstractConnectionPip
public void testZUnionStoreAggWeights() {
super.testZUnionStoreAggWeights();
}
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
initConnection();
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
}
}