Add support for BitFieldSubCommands that generate multiple bit operations using non-chaining methods.

Original pull request: #2060.
Closes #2055
This commit is contained in:
yanam
2021-05-07 21:51:44 +08:00
committed by Mark Paluch
parent 7cd0669e86
commit 1750b2a2d4
2 changed files with 105 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -29,6 +30,7 @@ import org.springframework.util.Assert;
*
* @author Christoph Strobl
* @author Qiang Lee
* @author Yanam
* @since 2.1
*/
public class BitFieldSubCommands implements Iterable<BitFieldSubCommand> {
@@ -56,6 +58,15 @@ public class BitFieldSubCommands implements Iterable<BitFieldSubCommand> {
return new BitFieldSubCommands(Collections.emptyList());
}
/**
* Creates a new {@link BitFieldSubCommands} with Multiple BitFieldSubCommand.
*
* @return
*/
public static BitFieldSubCommands create(BitFieldSubCommand... subCommands) {
return new BitFieldSubCommands(Arrays.asList(subCommands));
}
/**
* Obtain a new {@link BitFieldGetBuilder} for creating and adding a {@link BitFieldGet} sub command.
*
@@ -533,6 +544,21 @@ public class BitFieldSubCommands implements Iterable<BitFieldSubCommand> {
private long value;
/**
* Creates a new {@link BitFieldSet}.
* @param type must not be {@literal null}.
* @param offset must not be {@literal null}.
* @param value must not be {@literal null}.
* @return
*/
public static BitFieldSet create(BitFieldType type,Offset offset,long value){
BitFieldSet instance = new BitFieldSet();
instance.type = type;
instance.offset = offset;
instance.value = value;
return instance;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection.BitFieldSubCommand#getCommand()
@@ -561,6 +587,19 @@ public class BitFieldSubCommands implements Iterable<BitFieldSubCommand> {
*/
public static class BitFieldGet extends AbstractBitFieldSubCommand {
/**
* Creates a new {@link BitFieldGet}.
* @param type must not be {@literal null}.
* @param offset must not be {@literal null}.
* @return
*/
public static BitFieldGet create(BitFieldType type,Offset offset){
BitFieldGet instance = new BitFieldGet();
instance.type = type;
instance.offset = offset;
return instance;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection.BitFieldSubCommand#getCommand()
@@ -583,6 +622,38 @@ public class BitFieldSubCommands implements Iterable<BitFieldSubCommand> {
private long value;
private @Nullable Overflow overflow;
/**
* Creates a new {@link BitFieldIncrBy}.
* @param type must not be {@literal null}.
* @param offset must not be {@literal null}.
* @param value must not be {@literal null}.
* @return
*/
public static BitFieldIncrBy create(BitFieldType type,Offset offset,long value){
BitFieldIncrBy instance = new BitFieldIncrBy();
instance.type = type;
instance.offset = offset;
instance.value = value;
return instance;
}
/**
* Creates a new {@link BitFieldIncrBy}.
* @param type must not be {@literal null}.
* @param offset must not be {@literal null}.
* @param value must not be {@literal null}.
* @param overflow Can be {@literal null} to use redis defaults.
* @return
*/
public static BitFieldIncrBy create(BitFieldType type,Offset offset,long value,Overflow overflow){
BitFieldIncrBy instance = new BitFieldIncrBy();
instance.type = type;
instance.offset = offset;
instance.value = value;
instance.overflow = overflow;
return instance;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection.BitFieldSubCommand#getCommand()