Skip to content

Commit

Permalink
Fix set with args method signature #159
Browse files Browse the repository at this point in the history
Signature of the set method with SetArgs returned the value instead of the string status response. This mismatch gets obvious when using custom codes with value types other than String.

This commit changes the API to fix the mismatch.
  • Loading branch information
mp911de committed Dec 10, 2015
1 parent 071da1a commit 0413002
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public RedisFuture<String> set(K key, V value) {
}

@Override
public RedisFuture<V> set(K key, V value, SetArgs setArgs) {
public RedisFuture<String> set(K key, V value, SetArgs setArgs) {
return dispatch(commandBuilder.set(key, value, setArgs));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,10 @@ public Command<K, V, String> set(K key, V value) {
return createCommand(SET, new StatusOutput<K, V>(codec), key, value);
}

public Command<K, V, V> set(K key, V value, SetArgs setArgs) {
public Command<K, V, String> set(K key, V value, SetArgs setArgs) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).addValue(value);
setArgs.build(args);
return createCommand(SET, new ValueOutput<K, V>(codec), args);
return createCommand(SET, new StatusOutput<K, V>(codec), args);
}

public Command<K, V, Long> setbit(K key, long offset, int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public interface RedisStringsAsyncConnection<K, V> {
*
* @return RedisFuture&lt;V&gt; simple-string-reply {@code OK} if {@code SET} was executed correctly.
*/
RedisFuture<V> set(K key, V value, SetArgs setArgs);
RedisFuture<String> set(K key, V value, SetArgs setArgs);

/**
* Sets or clears the bit at offset in the string value stored at key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ public interface RedisStringsConnection<K, V> {
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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();
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/com/lambdaworks/redis/CustomCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
import java.util.List;

import com.lambdaworks.redis.codec.ByteArrayCodec;
import com.lambdaworks.redis.protocol.SetArgs;
import org.junit.Test;

import com.lambdaworks.redis.codec.RedisCodec;

public class CustomCodecTest extends AbstractCommandTest {
@Test
public void test() throws Exception {
public void testJavaSerializer() throws Exception {
RedisConnection<String, Object> connection = client.connect(new SerializedObjectCodec());

List<String> list = list("one", "two");
connection.set(key, list);

assertThat(connection.get(key)).isEqualTo(list);
assertThat(connection.set(key, list)).isEqualTo("OK");
assertThat(connection.set(key, list, SetArgs.Builder.ex(1))).isEqualTo("OK");

connection.close();
}

@Test
Expand Down

0 comments on commit 0413002

Please sign in to comment.