diff --git a/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java b/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java index f311727681..1d513e18ed 100644 --- a/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java @@ -817,7 +817,7 @@ public RedisFuture set(K key, V value) { } @Override - public RedisFuture set(K key, V value, SetArgs setArgs) { + public RedisFuture set(K key, V value, SetArgs setArgs) { return dispatch(commandBuilder.set(key, value, setArgs)); } diff --git a/src/main/java/com/lambdaworks/redis/AbstractRedisReactiveCommands.java b/src/main/java/com/lambdaworks/redis/AbstractRedisReactiveCommands.java index f3dd64bdc5..40289a44a4 100644 --- a/src/main/java/com/lambdaworks/redis/AbstractRedisReactiveCommands.java +++ b/src/main/java/com/lambdaworks/redis/AbstractRedisReactiveCommands.java @@ -801,7 +801,7 @@ public Observable set(K key, V value) { } @Override - public Observable set(K key, V value, SetArgs setArgs) { + public Observable set(K key, V value, SetArgs setArgs) { return createObservable(() -> commandBuilder.set(key, value, setArgs)); } diff --git a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java index 3ac6e5e46f..49c0bece74 100644 --- a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java +++ b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java @@ -804,10 +804,10 @@ public Command set(K key, V value) { return createCommand(SET, new StatusOutput(codec), key, value); } - public Command set(K key, V value, SetArgs setArgs) { + public Command set(K key, V value, SetArgs setArgs) { CommandArgs args = new CommandArgs(codec).addKey(key).addValue(value); setArgs.build(args); - return createCommand(SET, new ValueOutput(codec), args); + return createCommand(SET, new StatusOutput(codec), args); } public Command setbit(K key, long offset, int value) { diff --git a/src/main/java/com/lambdaworks/redis/RedisStringsAsyncConnection.java b/src/main/java/com/lambdaworks/redis/RedisStringsAsyncConnection.java index 80cbbe03f8..575f5e87cb 100644 --- a/src/main/java/com/lambdaworks/redis/RedisStringsAsyncConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisStringsAsyncConnection.java @@ -273,7 +273,7 @@ public interface RedisStringsAsyncConnection { * * @return RedisFuture<V> simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - RedisFuture set(K key, V value, SetArgs setArgs); + RedisFuture set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/RedisStringsConnection.java b/src/main/java/com/lambdaworks/redis/RedisStringsConnection.java index 7b11ccb906..631c53936c 100644 --- a/src/main/java/com/lambdaworks/redis/RedisStringsConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisStringsConnection.java @@ -267,9 +267,9 @@ public interface RedisStringsConnection { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - V set(K key, V value, SetArgs setArgs); + String set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/api/async/RedisStringAsyncCommands.java b/src/main/java/com/lambdaworks/redis/api/async/RedisStringAsyncCommands.java index 065a844684..645a7e47c4 100644 --- a/src/main/java/com/lambdaworks/redis/api/async/RedisStringAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/api/async/RedisStringAsyncCommands.java @@ -267,9 +267,9 @@ public interface RedisStringAsyncCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - RedisFuture set(K key, V value, SetArgs setArgs); + RedisFuture set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/api/rx/RedisStringReactiveCommands.java b/src/main/java/com/lambdaworks/redis/api/rx/RedisStringReactiveCommands.java index 9b78f1f18b..43749f4f64 100644 --- a/src/main/java/com/lambdaworks/redis/api/rx/RedisStringReactiveCommands.java +++ b/src/main/java/com/lambdaworks/redis/api/rx/RedisStringReactiveCommands.java @@ -267,9 +267,9 @@ public interface RedisStringReactiveCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - Observable set(K key, V value, SetArgs setArgs); + Observable set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/api/sync/RedisStringCommands.java b/src/main/java/com/lambdaworks/redis/api/sync/RedisStringCommands.java index 76c80b95c7..dc2b7ae81a 100644 --- a/src/main/java/com/lambdaworks/redis/api/sync/RedisStringCommands.java +++ b/src/main/java/com/lambdaworks/redis/api/sync/RedisStringCommands.java @@ -266,9 +266,9 @@ public interface RedisStringCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - V set(K key, V value, SetArgs setArgs); + String set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionStringAsyncCommands.java b/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionStringAsyncCommands.java index 76ba8ea57b..1fd013bcc4 100644 --- a/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionStringAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionStringAsyncCommands.java @@ -267,9 +267,9 @@ public interface NodeSelectionStringAsyncCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - AsyncExecutions set(K key, V value, SetArgs setArgs); + AsyncExecutions set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionStringCommands.java b/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionStringCommands.java index a662c7abe9..77221490f8 100644 --- a/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionStringCommands.java +++ b/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionStringCommands.java @@ -266,9 +266,9 @@ public interface NodeSelectionStringCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - Executions set(K key, V value, SetArgs setArgs); + Executions set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/main/java/com/lambdaworks/redis/output/CommandOutput.java b/src/main/java/com/lambdaworks/redis/output/CommandOutput.java index 565dc2ef4b..265448c73c 100644 --- a/src/main/java/com/lambdaworks/redis/output/CommandOutput.java +++ b/src/main/java/com/lambdaworks/redis/output/CommandOutput.java @@ -110,6 +110,10 @@ public void complete(int depth) { } protected String decodeAscii(ByteBuffer bytes) { + if(bytes == null) { + return null; + } + char[] chars = new char[bytes.remaining()]; for (int i = 0; i < chars.length; i++) { chars[i] = (char) bytes.get(); diff --git a/src/main/templates/com/lambdaworks/redis/api/RedisStringCommands.java b/src/main/templates/com/lambdaworks/redis/api/RedisStringCommands.java index 016c509a8a..a6837aab09 100644 --- a/src/main/templates/com/lambdaworks/redis/api/RedisStringCommands.java +++ b/src/main/templates/com/lambdaworks/redis/api/RedisStringCommands.java @@ -265,9 +265,9 @@ public interface RedisStringCommands { * @param value the value * @param setArgs the setArgs * - * @return V simple-string-reply {@code OK} if {@code SET} was executed correctly. + * @return String simple-string-reply {@code OK} if {@code SET} was executed correctly. */ - V set(K key, V value, SetArgs setArgs); + String set(K key, V value, SetArgs setArgs); /** * Sets or clears the bit at offset in the string value stored at key. diff --git a/src/test/java/com/lambdaworks/redis/CustomCodecTest.java b/src/test/java/com/lambdaworks/redis/CustomCodecTest.java index 7c900d3cf3..31c5284a10 100644 --- a/src/test/java/com/lambdaworks/redis/CustomCodecTest.java +++ b/src/test/java/com/lambdaworks/redis/CustomCodecTest.java @@ -12,26 +12,46 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.List; +import java.util.concurrent.TimeUnit; +import com.lambdaworks.redis.api.StatefulRedisConnection; import com.lambdaworks.redis.api.sync.RedisCommands; -import com.lambdaworks.redis.protocol.RedisCommand; import org.junit.Test; import com.lambdaworks.redis.codec.ByteArrayCodec; import com.lambdaworks.redis.codec.CompressionCodec; import com.lambdaworks.redis.codec.RedisCodec; +import rx.observers.TestSubscriber; public class CustomCodecTest extends AbstractRedisClientTest { @Test - public void test() throws Exception { + public void testJavaSerializer() throws Exception { + StatefulRedisConnection redisConnection = client.connect(new SerializedObjectCodec()); + RedisCommands sync = redisConnection.sync(); + List list = list("one", "two"); + sync.set(key, list); + + assertThat(sync.get(key)).isEqualTo(list); + assertThat(sync.set(key, list)).isEqualTo("OK"); + assertThat(sync.set(key, list, SetArgs.Builder.ex(1))).isEqualTo("OK"); - RedisCommands connection = client.connect(new SerializedObjectCodec()).sync(); + redisConnection.close(); + } + + @Test + public void testJavaSerializerRx() throws Exception { + StatefulRedisConnection redisConnection = client.connect(new SerializedObjectCodec()); List list = list("one", "two"); - connection.set(key, list); - assertThat(connection.get(key)).isEqualTo(list); - connection.close(); + TestSubscriber subscriber = TestSubscriber.create(); + + redisConnection.reactive().set(key, list, SetArgs.Builder.ex(1)).subscribe(subscriber); + subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); + subscriber.assertCompleted(); + subscriber.assertValue("OK"); + + redisConnection.close(); } @Test