Skip to content

Use correct bitfield offset for INCRBY using Lettuce #2901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,6 +45,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 @@ -110,6 +112,7 @@
* @author Andrey Shlykov
* @author Hendrik Duerkop
* @author Shyngys Sapraliyev
* @author Roman Osadchuk
*/
public abstract class AbstractConnectionIntegrationTests {

Expand Down Expand Up @@ -3577,6 +3580,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