DATAREDIS-791 - Disable ifValueNotExists() flag in ReactiveHashCommands.hMSet.

We now no longer set ifValueNotExists() in ReactiveHashCommands.hMSet to always upsert hash entries. Previously, we called HSETNX if hMSet was called with a single tuple which did not overwrite existing entries.

Align return value of hMSet to return always true as calling internally HSET returns 1 only on newly set hash fields and setting an existing field resulted previously in false.

Original Pull Request: #325
This commit is contained in:
Mark Paluch
2018-03-22 14:44:34 +01:00
committed by Christoph Strobl
parent e2e01ae1b6
commit 2d6a9d08ab
2 changed files with 16 additions and 2 deletions

View File

@@ -195,8 +195,7 @@ public interface ReactiveHashCommands {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fieldValueMap, "Field must not be null!");
return hSet(Mono.just(HSetCommand.fieldValues(fieldValueMap).forKey(key).ifValueNotExists())).next()
.map(BooleanResponse::getOutput);
return hSet(Mono.just(HSetCommand.fieldValues(fieldValueMap).forKey(key))).next().map(it -> true);
}
/**

View File

@@ -120,6 +120,21 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
assertThat(nativeCommands.hget(KEY_1, FIELD_2), is(equalTo(VALUE_2)));
}
@Test // DATAREDIS-791
public void hMSetShouldOverwriteValuesCorrectly() {
Map<ByteBuffer, ByteBuffer> fieldValues = new LinkedHashMap<>();
fieldValues.put(FIELD_1_BBUFFER, VALUE_1_BBUFFER);
connection.hashCommands().hMSet(KEY_1_BBUFFER, fieldValues).block();
Map<ByteBuffer, ByteBuffer> overwriteFieldValues = new LinkedHashMap<>();
overwriteFieldValues.put(FIELD_1_BBUFFER, VALUE_2_BBUFFER);
connection.hashCommands().hMSet(KEY_1_BBUFFER, overwriteFieldValues).block();
assertThat(nativeCommands.hget(KEY_1, FIELD_1), is(equalTo(VALUE_2)));
}
@Test // DATAREDIS-525
public void hExistsShouldReturnTrueForExistingField() {