Skip to content

Commit

Permalink
Use correct bitfield offset for INCRBY using Lettuce.
Browse files Browse the repository at this point in the history
Closes #2903
Original pull request: #2901
  • Loading branch information
osadchuk-roman authored and mp911de committed May 13, 2024
1 parent 0948d0d commit 9c3f4f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* @author Chris Bono
* @author Vikas Garg
* @author John Blum
* @author Roman Osadchuk
*/
@SuppressWarnings("ConstantConditions")
public abstract class LettuceConverters extends Converters {
Expand Down Expand Up @@ -720,7 +721,7 @@ public static BitFieldArgs toBitFieldArgs(BitFieldSubCommands subCommands) {
args = args.overflow(type);
}

args = args.incrBy(bitFieldType, (int) subCommand.getOffset().getValue(), ((BitFieldIncrBy) subCommand).getValue());
args = args.incrBy(bitFieldType, offset, ((BitFieldIncrBy) subCommand).getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Range;
Expand Down Expand Up @@ -108,6 +110,7 @@
* @author Andrey Shlykov
* @author Hendrik Duerkop
* @author Shyngys Sapraliyev
* @author Roman Osadchuk
*/
public abstract class AbstractConnectionIntegrationTests {

Expand Down Expand Up @@ -3574,6 +3577,23 @@ void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
assertThat(results.get(3)).isNotNull();
}

@ParameterizedTest // DATAREDIS-2903
@ValueSource(booleans = {false, true})
void bitFieldIncrByAndThenGetShouldWorkCorrectly(boolean isMultipliedByTypeLengthOffset) {
var offset = isMultipliedByTypeLengthOffset
? BitFieldSubCommands.Offset.offset(300L).multipliedByTypeLength()
: BitFieldSubCommands.Offset.offset(400L);

actual.add(connection.bitfield(KEY_1, create().incr(INT_8).valueAt(offset).by(1L)));
actual.add(connection.bitfield(KEY_1, create().get(INT_8).valueAt(offset)));

List<Object> results = getResults();

assertThat(results).hasSize(2)
// should return same results after INCRBY and GET operations for bitfield with same offset
.containsExactly(List.of(1L), List.of(1L));
}

@Test // DATAREDIS-562
void bitfieldShouldAllowMultipleSubcommands() {

Expand Down

0 comments on commit 9c3f4f5

Please sign in to comment.