Enable eval and evalsha in Jedis pipeline/transaction.
Original pull request: #2988 Closes #1455
This commit is contained in:
committed by
Mark Paluch
parent
9c5f21b840
commit
b22f1ab84c
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @author Ivan Kripakov
|
||||
* @since 2.0
|
||||
*/
|
||||
class JedisScriptingCommands implements RedisScriptingCommands {
|
||||
@@ -76,11 +77,11 @@ class JedisScriptingCommands implements RedisScriptingCommands {
|
||||
public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
|
||||
|
||||
Assert.notNull(script, "Script must not be null");
|
||||
assertDirectMode();
|
||||
|
||||
JedisScriptReturnConverter converter = new JedisScriptReturnConverter(returnType);
|
||||
return (T) connection.invoke().from(it -> it.eval(script, numKeys, keysAndArgs)).getOrElse(converter,
|
||||
() -> converter.convert(null));
|
||||
return (T) connection.invoke()
|
||||
.from(it -> it.eval(script, numKeys, keysAndArgs), t -> t.eval(script, numKeys, keysAndArgs))
|
||||
.getOrElse(converter, () -> converter.convert(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,11 +94,12 @@ class JedisScriptingCommands implements RedisScriptingCommands {
|
||||
public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
|
||||
|
||||
Assert.notNull(scriptSha, "Script digest must not be null");
|
||||
assertDirectMode();
|
||||
|
||||
JedisScriptReturnConverter converter = new JedisScriptReturnConverter(returnType);
|
||||
return (T) connection.invoke().from(it -> it.evalsha(scriptSha, numKeys, keysAndArgs)).getOrElse(converter,
|
||||
() -> converter.convert(null));
|
||||
return (T) connection.invoke()
|
||||
.from(it -> it.evalsha(scriptSha, numKeys, keysAndArgs), t -> t.evalsha(scriptSha, numKeys, keysAndArgs))
|
||||
.getOrElse(converter, () -> converter.convert(null)
|
||||
);
|
||||
}
|
||||
|
||||
private void assertDirectMode() {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
* @author Ivan Kripakov
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
|
||||
@@ -75,83 +76,6 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
|
||||
}
|
||||
|
||||
// Unsupported Ops
|
||||
@Test
|
||||
public void testScriptLoadEvalSha() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testScriptLoadEvalSha);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalShaArrayStrings() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalShaArrayStrings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalShaArrayBytes() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalShaArrayBytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalShaNotFound() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalShaArrayError() {}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnString() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnNumber() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnNumber);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnSingleOK() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnSingleOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnSingleError() {}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnFalse() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnFalse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnTrue() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnTrue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnArrayStrings() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnArrayStrings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnArrayNumbers() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnArrayNumbers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnArrayOKs() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnArrayOKs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnArrayFalses() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnArrayFalses);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalReturnArrayTrues() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testEvalReturnArrayTrues);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptExists() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testScriptExists);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Mark Paluch
|
||||
* @author Ivan Kripakov
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
|
||||
@@ -56,79 +57,44 @@ public class JedisConnectionTransactionIntegrationTests extends AbstractConnecti
|
||||
@Disabled("Jedis issue: Transaction tries to return String instead of List<String>")
|
||||
public void testGetConfig() {}
|
||||
|
||||
// Unsupported Ops
|
||||
@Test
|
||||
@Disabled
|
||||
public void testScriptLoadEvalSha() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalShaArrayStrings() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalShaArrayBytes() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalShaNotFound() {}
|
||||
public void testEvalShaNotFound() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> {
|
||||
connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2");
|
||||
getResults();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalShaArrayError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"));
|
||||
.isThrownBy(() -> {
|
||||
connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1");
|
||||
getResults();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalArrayScriptError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar"));
|
||||
.isThrownBy(() -> {
|
||||
connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar");
|
||||
getResults();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnString() {}
|
||||
public void testEvalReturnSingleError() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(()-> {
|
||||
connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0);
|
||||
getResults();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnNumber() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnSingleOK() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnSingleError() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnFalse() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnTrue() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnArrayStrings() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnArrayNumbers() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnArrayOKs() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnArrayFalses() {}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testEvalReturnArrayTrues() {}
|
||||
|
||||
// Unsupported Ops
|
||||
@Test
|
||||
@Disabled
|
||||
public void testScriptExists() {}
|
||||
|
||||
Reference in New Issue
Block a user