diff --git a/src/main/java/io/lettuce/core/output/BooleanOutput.java b/src/main/java/io/lettuce/core/output/BooleanOutput.java index 469713611b..d0e7ccae69 100644 --- a/src/main/java/io/lettuce/core/output/BooleanOutput.java +++ b/src/main/java/io/lettuce/core/output/BooleanOutput.java @@ -16,6 +16,7 @@ package io.lettuce.core.output; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import io.lettuce.core.codec.RedisCodec; @@ -41,7 +42,7 @@ public void set(long integer) { @Override public void set(ByteBuffer bytes) { - output = (bytes != null) ? Boolean.TRUE : Boolean.FALSE; + output = (bytes != null) ? Boolean.parseBoolean(StandardCharsets.UTF_8.decode(bytes).toString()) : Boolean.FALSE; } @Override diff --git a/src/main/java/io/lettuce/core/output/IntegerOutput.java b/src/main/java/io/lettuce/core/output/IntegerOutput.java index 826b8f7cc7..5a1d566e4f 100644 --- a/src/main/java/io/lettuce/core/output/IntegerOutput.java +++ b/src/main/java/io/lettuce/core/output/IntegerOutput.java @@ -16,6 +16,7 @@ package io.lettuce.core.output; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import io.lettuce.core.codec.RedisCodec; @@ -40,7 +41,12 @@ public void set(long integer) { @Override public void set(ByteBuffer bytes) { - output = null; + if (bytes == null) { + output = null; + } else { + // fallback for long as ByteBuffer + output = Long.parseLong(StandardCharsets.UTF_8.decode(bytes).toString()); + } } } diff --git a/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java index dfd4338395..7bf383b649 100644 --- a/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java @@ -44,6 +44,8 @@ import io.lettuce.test.condition.EnabledOnCommand; /** + * Integration tests for scripting commands. + * * @author Will Glozer * @author Mark Paluch * @author dengliming @@ -53,6 +55,7 @@ public class ScriptingCommandIntegrationTests extends TestSupport { private final RedisClient client; + private final RedisCommands redis; @Inject @@ -77,13 +80,21 @@ void tearDown() { } redis.ping(); }).waitOrTimeout(); - } @Test void eval() { + + redis.set(key, "true"); + assertThat((Boolean) redis.eval("return 1 + 1 == 4", BOOLEAN)).isEqualTo(false); + assertThat((Boolean) redis.eval("return redis.call('GET', KEYS[1])", BOOLEAN, key)).isEqualTo(true); + + redis.set(key, "1"); + assertThat((Boolean) redis.eval("return 1 + 1 == 4", BOOLEAN)).isEqualTo(false); assertThat((Number) redis.eval("return 1 + 1", INTEGER)).isEqualTo(2L); + assertThat((String) redis.eval("return redis.call('GET', KEYS[1])", VALUE, key)).isEqualTo("1"); + assertThat((Long) redis.eval("return redis.call('GET', KEYS[1])", INTEGER, key)).isEqualTo(1L); assertThat((String) redis.eval("return {ok='status'}", STATUS)).isEqualTo("status"); assertThat((String) redis.eval("return 'one'", VALUE)).isEqualTo("one"); assertThat((List) redis.eval("return {1, 'one', {2}}", MULTI)).isEqualTo(list(1L, "one", list(2L))); @@ -132,8 +143,9 @@ void evalsha() { assertThat((Number) redis.eval(script, INTEGER)).isEqualTo(2L); assertThat((Number) redis.evalsha(digest, INTEGER)).isEqualTo(2L); - assertThatThrownBy(() -> redis.evalsha(redis.digest("return 1 + 1 == 4"), INTEGER)).isInstanceOf( - RedisNoScriptException.class).hasMessageContaining("NOSCRIPT No matching script. Please use EVAL."); + assertThatThrownBy(() -> redis.evalsha(redis.digest("return 1 + 1 == 4"), INTEGER)) + .isInstanceOf(RedisNoScriptException.class) + .hasMessageContaining("NOSCRIPT No matching script. Please use EVAL."); } @Test @@ -141,8 +153,8 @@ void evalshaWithMulti() { redis.scriptFlush(); String digest = redis.digest("return {1234, 5678}"); - assertThatThrownBy(() -> redis.evalsha(digest, MULTI)).isInstanceOf(RedisNoScriptException.class).hasMessageContaining( - "NOSCRIPT No matching script. Please use EVAL."); + assertThatThrownBy(() -> redis.evalsha(digest, MULTI)).isInstanceOf(RedisNoScriptException.class) + .hasMessageContaining("NOSCRIPT No matching script. Please use EVAL."); } @Test @@ -227,4 +239,5 @@ void scriptFlushSync() { assertThat(redis.scriptFlush(FlushMode.SYNC)).isEqualTo("OK"); assertThat(redis.scriptExists(digest1)).isEqualTo(list(false)); } + }