Skip to content

Commit 9a08998

Browse files
authored
Add support for new operations of BITOP command in Redis Community Edition 8.2 (#3334)
* bitop new operations * polish * update new API signatures in NodeSelectionCommands
1 parent 9ecee24 commit 9a08998

12 files changed

+644
-2
lines changed

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ public RedisFuture<Long> bitopXor(K destination, K... keys) {
286286
return dispatch(commandBuilder.bitopXor(destination, keys));
287287
}
288288

289+
@Override
290+
public RedisFuture<Long> bitopDiff(K destination, K sourceKey, K... keys) {
291+
return dispatch(commandBuilder.bitopDiff(destination, sourceKey, keys));
292+
}
293+
294+
@Override
295+
public RedisFuture<Long> bitopDiff1(K destination, K sourceKey, K... keys) {
296+
return dispatch(commandBuilder.bitopDiff1(destination, sourceKey, keys));
297+
}
298+
299+
@Override
300+
public RedisFuture<Long> bitopAndor(K destination, K sourceKey, K... keys) {
301+
return dispatch(commandBuilder.bitopAndor(destination, sourceKey, keys));
302+
}
303+
304+
@Override
305+
public RedisFuture<Long> bitopOne(K destination, K... keys) {
306+
return dispatch(commandBuilder.bitopOne(destination, keys));
307+
}
308+
289309
@Override
290310
public RedisFuture<Long> bitpos(K key, boolean state) {
291311
return dispatch(commandBuilder.bitpos(key, state));

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ public Mono<Long> bitopXor(K destination, K... keys) {
308308
return createMono(() -> commandBuilder.bitopXor(destination, keys));
309309
}
310310

311+
@Override
312+
public Mono<Long> bitopDiff(K destination, K sourceKey, K... keys) {
313+
return createMono(() -> commandBuilder.bitopDiff(destination, sourceKey, keys));
314+
}
315+
316+
@Override
317+
public Mono<Long> bitopDiff1(K destination, K sourceKey, K... keys) {
318+
return createMono(() -> commandBuilder.bitopDiff1(destination, sourceKey, keys));
319+
}
320+
321+
@Override
322+
public Mono<Long> bitopAndor(K destination, K sourceKey, K... keys) {
323+
return createMono(() -> commandBuilder.bitopAndor(destination, sourceKey, keys));
324+
}
325+
326+
@Override
327+
public Mono<Long> bitopOne(K destination, K... keys) {
328+
return createMono(() -> commandBuilder.bitopOne(destination, keys));
329+
}
330+
311331
@Override
312332
public Mono<Long> bitpos(K key, boolean state) {
313333
return createMono(() -> commandBuilder.bitpos(key, state));

src/main/java/io/lettuce/core/RedisCommandBuilder.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,45 @@ Command<K, V, Long> bitopXor(K destination, K... keys) {
321321
return createCommand(BITOP, new IntegerOutput<>(codec), args);
322322
}
323323

324+
Command<K, V, Long> bitopDiff(K destination, K sourceKey, K... keys) {
325+
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
326+
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
327+
notEmpty(keys);
328+
329+
CommandArgs<K, V> args = new CommandArgs<>(codec);
330+
args.add(DIFF).addKey(destination).addKey(sourceKey).addKeys(keys);
331+
return createCommand(BITOP, new IntegerOutput<>(codec), args);
332+
}
333+
334+
Command<K, V, Long> bitopDiff1(K destination, K sourceKey, K... keys) {
335+
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
336+
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
337+
notEmpty(keys);
338+
339+
CommandArgs<K, V> args = new CommandArgs<>(codec);
340+
args.add(DIFF1).addKey(destination).addKey(sourceKey).addKeys(keys);
341+
return createCommand(BITOP, new IntegerOutput<>(codec), args);
342+
}
343+
344+
Command<K, V, Long> bitopAndor(K destination, K sourceKey, K... keys) {
345+
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
346+
LettuceAssert.notNull(sourceKey, "Source key " + MUST_NOT_BE_NULL);
347+
notEmpty(keys);
348+
349+
CommandArgs<K, V> args = new CommandArgs<>(codec);
350+
args.add(ANDOR).addKey(destination).addKey(sourceKey).addKeys(keys);
351+
return createCommand(BITOP, new IntegerOutput<>(codec), args);
352+
}
353+
354+
Command<K, V, Long> bitopOne(K destination, K... keys) {
355+
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
356+
notEmpty(keys);
357+
358+
CommandArgs<K, V> args = new CommandArgs<>(codec);
359+
args.add(ONE).addKey(destination).addKeys(keys);
360+
return createCommand(BITOP, new IntegerOutput<>(codec), args);
361+
}
362+
324363
Command<K, V, Long> bitpos(K key, boolean state) {
325364
notNullKey(key);
326365

src/main/java/io/lettuce/core/api/async/RedisStringAsyncCommands.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,53 @@ public interface RedisStringAsyncCommands<K, V> {
184184
*/
185185
RedisFuture<Long> bitopXor(K destination, K... keys);
186186

187+
/**
188+
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
189+
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
190+
*
191+
* @param destination result key of the operation.
192+
* @param sourceKey the source key (X) for comparison.
193+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
194+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
195+
* input string.
196+
*/
197+
RedisFuture<Long> bitopDiff(K destination, K sourceKey, K... keys);
198+
199+
/**
200+
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
201+
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
202+
*
203+
* @param destination result key of the operation.
204+
* @param sourceKey the source key (X) for comparison.
205+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
206+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
207+
* input string.
208+
*/
209+
RedisFuture<Long> bitopDiff1(K destination, K sourceKey, K... keys);
210+
211+
/**
212+
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
213+
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
214+
*
215+
* @param destination result key of the operation.
216+
* @param sourceKey the source key (X) for comparison.
217+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
218+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
219+
* input string.
220+
*/
221+
RedisFuture<Long> bitopAndor(K destination, K sourceKey, K... keys);
222+
223+
/**
224+
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
225+
* For more than two keys, returns members that appear in exactly one key.
226+
*
227+
* @param destination result key of the operation.
228+
* @param keys operation input key names.
229+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
230+
* input string.
231+
*/
232+
RedisFuture<Long> bitopOne(K destination, K... keys);
233+
187234
/**
188235
* Decrement the integer value of a key by one.
189236
*

src/main/java/io/lettuce/core/api/reactive/RedisStringReactiveCommands.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,53 @@ public interface RedisStringReactiveCommands<K, V> {
185185
*/
186186
Mono<Long> bitopXor(K destination, K... keys);
187187

188+
/**
189+
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
190+
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
191+
*
192+
* @param destination result key of the operation.
193+
* @param sourceKey the source key (X) for comparison.
194+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
195+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
196+
* input string.
197+
*/
198+
Mono<Long> bitopDiff(K destination, K sourceKey, K... keys);
199+
200+
/**
201+
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
202+
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
203+
*
204+
* @param destination result key of the operation.
205+
* @param sourceKey the source key (X) for comparison.
206+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
207+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
208+
* input string.
209+
*/
210+
Mono<Long> bitopDiff1(K destination, K sourceKey, K... keys);
211+
212+
/**
213+
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
214+
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
215+
*
216+
* @param destination result key of the operation.
217+
* @param sourceKey the source key (X) for comparison.
218+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
219+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
220+
* input string.
221+
*/
222+
Mono<Long> bitopAndor(K destination, K sourceKey, K... keys);
223+
224+
/**
225+
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
226+
* For more than two keys, returns members that appear in exactly one key.
227+
*
228+
* @param destination result key of the operation.
229+
* @param keys operation input key names.
230+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
231+
* input string.
232+
*/
233+
Mono<Long> bitopOne(K destination, K... keys);
234+
188235
/**
189236
* Decrement the integer value of a key by one.
190237
*

src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,53 @@ public interface RedisStringCommands<K, V> {
183183
*/
184184
Long bitopXor(K destination, K... keys);
185185

186+
/**
187+
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
188+
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
189+
*
190+
* @param destination result key of the operation.
191+
* @param sourceKey the source key (X) for comparison.
192+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
193+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
194+
* input string.
195+
*/
196+
Long bitopDiff(K destination, K sourceKey, K... keys);
197+
198+
/**
199+
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
200+
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
201+
*
202+
* @param destination result key of the operation.
203+
* @param sourceKey the source key (X) for comparison.
204+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
205+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
206+
* input string.
207+
*/
208+
Long bitopDiff1(K destination, K sourceKey, K... keys);
209+
210+
/**
211+
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
212+
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
213+
*
214+
* @param destination result key of the operation.
215+
* @param sourceKey the source key (X) for comparison.
216+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
217+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
218+
* input string.
219+
*/
220+
Long bitopAndor(K destination, K sourceKey, K... keys);
221+
222+
/**
223+
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
224+
* For more than two keys, returns members that appear in exactly one key.
225+
*
226+
* @param destination result key of the operation.
227+
* @param keys operation input key names.
228+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
229+
* input string.
230+
*/
231+
Long bitopOne(K destination, K... keys);
232+
186233
/**
187234
* Decrement the integer value of a key by one.
188235
*

src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionStringAsyncCommands.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,53 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
183183
*/
184184
AsyncExecutions<Long> bitopXor(K destination, K... keys);
185185

186+
/**
187+
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
188+
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
189+
*
190+
* @param destination result key of the operation.
191+
* @param sourceKey the source key (X) for comparison.
192+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
193+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
194+
* input string.
195+
*/
196+
AsyncExecutions<Long> bitopDiff(K destination, K sourceKey, K... keys);
197+
198+
/**
199+
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
200+
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
201+
*
202+
* @param destination result key of the operation.
203+
* @param sourceKey the source key (X) for comparison.
204+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
205+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
206+
* input string.
207+
*/
208+
AsyncExecutions<Long> bitopDiff1(K destination, K sourceKey, K... keys);
209+
210+
/**
211+
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
212+
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
213+
*
214+
* @param destination result key of the operation.
215+
* @param sourceKey the source key (X) for comparison.
216+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
217+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
218+
* input string.
219+
*/
220+
AsyncExecutions<Long> bitopAndor(K destination, K sourceKey, K... keys);
221+
222+
/**
223+
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
224+
* For more than two keys, returns members that appear in exactly one key.
225+
*
226+
* @param destination result key of the operation.
227+
* @param keys operation input key names.
228+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
229+
* input string.
230+
*/
231+
AsyncExecutions<Long> bitopOne(K destination, K... keys);
232+
186233
/**
187234
* Decrement the integer value of a key by one.
188235
*

src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionStringCommands.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,53 @@ public interface NodeSelectionStringCommands<K, V> {
183183
*/
184184
Executions<Long> bitopXor(K destination, K... keys);
185185

186+
/**
187+
* Perform bitwise DIFF between strings. Members of the source key that are not members of any of the other keys. Equivalent
188+
* to: X ∧ ¬(Y1 ∨ Y2 ∨ …)
189+
*
190+
* @param destination result key of the operation.
191+
* @param sourceKey the source key (X) for comparison.
192+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
193+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
194+
* input string.
195+
*/
196+
Executions<Long> bitopDiff(K destination, K sourceKey, K... keys);
197+
198+
/**
199+
* Perform bitwise DIFF1 between strings. Members of one or more of the keys that are not members of the source key.
200+
* Equivalent to: ¬X ∧ (Y1 ∨ Y2 ∨ …)
201+
*
202+
* @param destination result key of the operation.
203+
* @param sourceKey the source key (X) for comparison.
204+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
205+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
206+
* input string.
207+
*/
208+
Executions<Long> bitopDiff1(K destination, K sourceKey, K... keys);
209+
210+
/**
211+
* Perform bitwise ANDOR between strings. Members of the source key that are also members of one or more of the other keys.
212+
* Equivalent to: X ∧ (Y1 ∨ Y2 ∨ …)
213+
*
214+
* @param destination result key of the operation.
215+
* @param sourceKey the source key (X) for comparison.
216+
* @param keys one or more additional keys (Y1, Y2, ...). At least one key is required.
217+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
218+
* input string.
219+
*/
220+
Executions<Long> bitopAndor(K destination, K sourceKey, K... keys);
221+
222+
/**
223+
* Perform bitwise ONE between strings. Members of exactly one of the given keys. For two keys this is equivalent to XOR.
224+
* For more than two keys, returns members that appear in exactly one key.
225+
*
226+
* @param destination result key of the operation.
227+
* @param keys operation input key names.
228+
* @return Long integer-reply The size of the string stored in the destination key, that is equal to the size of the longest
229+
* input string.
230+
*/
231+
Executions<Long> bitopOne(K destination, K... keys);
232+
186233
/**
187234
* Decrement the integer value of a key by one.
188235
*

src/main/java/io/lettuce/core/protocol/CommandKeyword.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
*/
3434
public enum CommandKeyword implements ProtocolKeyword {
3535

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

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

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

0 commit comments

Comments
 (0)