Skip to content

Add support for new operations of BITOP command in Redis Community Edition 8.2 #3334

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

Merged
merged 3 commits into from
Jul 7, 2025
Merged
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
20 changes: 20 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ public RedisFuture<Long> bitopXor(K destination, K... keys) {
return dispatch(commandBuilder.bitopXor(destination, keys));
}

@Override
public RedisFuture<Long> bitopDiff(K destination, K sourceKey, K... keys) {
return dispatch(commandBuilder.bitopDiff(destination, sourceKey, keys));
}

@Override
public RedisFuture<Long> bitopDiff1(K destination, K sourceKey, K... keys) {
return dispatch(commandBuilder.bitopDiff1(destination, sourceKey, keys));
}

@Override
public RedisFuture<Long> bitopAndor(K destination, K sourceKey, K... keys) {
return dispatch(commandBuilder.bitopAndor(destination, sourceKey, keys));
}

@Override
public RedisFuture<Long> bitopOne(K destination, K... keys) {
return dispatch(commandBuilder.bitopOne(destination, keys));
}

@Override
public RedisFuture<Long> bitpos(K key, boolean state) {
return dispatch(commandBuilder.bitpos(key, state));
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ public Mono<Long> bitopXor(K destination, K... keys) {
return createMono(() -> commandBuilder.bitopXor(destination, keys));
}

@Override
public Mono<Long> bitopDiff(K destination, K sourceKey, K... keys) {
return createMono(() -> commandBuilder.bitopDiff(destination, sourceKey, keys));
}

@Override
public Mono<Long> bitopDiff1(K destination, K sourceKey, K... keys) {
return createMono(() -> commandBuilder.bitopDiff1(destination, sourceKey, keys));
}

@Override
public Mono<Long> bitopAndor(K destination, K sourceKey, K... keys) {
return createMono(() -> commandBuilder.bitopAndor(destination, sourceKey, keys));
}

@Override
public Mono<Long> bitopOne(K destination, K... keys) {
return createMono(() -> commandBuilder.bitopOne(destination, keys));
}

@Override
public Mono<Long> bitpos(K key, boolean state) {
return createMono(() -> commandBuilder.bitpos(key, state));
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,45 @@ Command<K, V, Long> bitopXor(K destination, K... keys) {
return createCommand(BITOP, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitopDiff(K destination, K sourceKey, K... keys) {
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(DIFF).addKey(destination).addKey(sourceKey).addKeys(keys);
return createCommand(BITOP, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitopDiff1(K destination, K sourceKey, K... keys) {
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(DIFF1).addKey(destination).addKey(sourceKey).addKeys(keys);
return createCommand(BITOP, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitopAndor(K destination, K sourceKey, K... keys) {
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(ANDOR).addKey(destination).addKey(sourceKey).addKeys(keys);
return createCommand(BITOP, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitopOne(K destination, K... keys) {
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(ONE).addKey(destination).addKeys(keys);
return createCommand(BITOP, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitpos(K key, boolean state) {
notNullKey(key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,53 @@ public interface RedisStringAsyncCommands<K, V> {
*/
RedisFuture<Long> bitopXor(K destination, K... keys);

/**
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
RedisFuture<Long> bitopDiff(K destination, K sourceKey, K... keys);

/**
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
RedisFuture<Long> bitopDiff1(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
RedisFuture<Long> bitopAndor(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
* For more than two keys, returns members that appear in exactly one key.
*
* @param destination result key of the operation.
* @param keys operation input key names.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
RedisFuture<Long> bitopOne(K destination, K... keys);

/**
* Decrement the integer value of a key by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,53 @@ public interface RedisStringReactiveCommands<K, V> {
*/
Mono<Long> bitopXor(K destination, K... keys);

/**
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Mono<Long> bitopDiff(K destination, K sourceKey, K... keys);

/**
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Mono<Long> bitopDiff1(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Mono<Long> bitopAndor(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
* For more than two keys, returns members that appear in exactly one key.
*
* @param destination result key of the operation.
* @param keys operation input key names.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Mono<Long> bitopOne(K destination, K... keys);

/**
* Decrement the integer value of a key by one.
*
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,53 @@ public interface RedisStringCommands<K, V> {
*/
Long bitopXor(K destination, K... keys);

/**
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Long bitopDiff(K destination, K sourceKey, K... keys);

/**
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Long bitopDiff1(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Long bitopAndor(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
* For more than two keys, returns members that appear in exactly one key.
*
* @param destination result key of the operation.
* @param keys operation input key names.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Long bitopOne(K destination, K... keys);

/**
* Decrement the integer value of a key by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,53 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
*/
AsyncExecutions<Long> bitopXor(K destination, K... keys);

/**
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
AsyncExecutions<Long> bitopDiff(K destination, K sourceKey, K... keys);

/**
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
AsyncExecutions<Long> bitopDiff1(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
AsyncExecutions<Long> bitopAndor(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
* For more than two keys, returns members that appear in exactly one key.
*
* @param destination result key of the operation.
* @param keys operation input key names.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
AsyncExecutions<Long> bitopOne(K destination, K... keys);

/**
* Decrement the integer value of a key by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,53 @@ public interface NodeSelectionStringCommands<K, V> {
*/
Executions<Long> bitopXor(K destination, K... keys);

/**
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Executions<Long> bitopDiff(K destination, K sourceKey, K... keys);

/**
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Executions<Long> bitopDiff1(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
*
* @param destination result key of the operation.
* @param sourceKey the source key (X) for comparison.
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Executions<Long> bitopAndor(K destination, K sourceKey, K... keys);

/**
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
* For more than two keys, returns members that appear in exactly one key.
*
* @param destination result key of the operation.
* @param keys operation input key names.
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
* input string.
*/
Executions<Long> bitopOne(K destination, K... keys);

/**
* Decrement the integer value of a key by one.
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
*/
public enum CommandKeyword implements ProtocolKeyword {

ABSTTL, ADDR, ADDSLOTS, ADDSLOTSRANGE, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,
ABSTTL, ADDR, ADDSLOTS, ADDSLOTSRANGE, AFTER, AGGREGATE, ALLCHANNELS, ALLCOMMANDS, ALLKEYS, ALPHA, AND, ANDOR, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH,

BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELSLOTSRANGE, DELUSER, DESC, DRYRUN, SOFT, HARD, ENCODING,
BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELSLOTSRANGE, DELUSER, DESC, DIFF, DIFF1, DRYRUN, SOFT, HARD, ENCODING,

FAILOVER, FORGET, FIELDS, FLAGS, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, IDX, INFO,

Expand Down
Loading