Merge branch 'master' of github.com:redisson/redisson

pull/5045/head
Nikita Koksharov 2 years ago
commit 792fb792b8

@ -263,6 +263,11 @@ public class RedissonBitSet extends RedissonExpirable implements RBitSet {
get(setAsync(bs));
}
@Override
public void set(long[] indexArray, boolean value) {
get(setAsync(indexArray, value));
}
@Override
public boolean get(long bitIndex) {
return get(getAsync(bitIndex));
@ -303,6 +308,21 @@ public class RedissonBitSet extends RedissonExpirable implements RBitSet {
return Boolean.compare(value, false);
}
@Override
public RFuture<Void> setAsync(long[] indexArray, boolean value) {
int val = toInt(value);
Object[] paramArray = new Object[indexArray.length * 4 + 1];
int j = 0;
paramArray[j++] = getRawName();
for (int i = 0; i < indexArray.length; i++) {
paramArray[j++] = "set";
paramArray[j++] = "u1";
paramArray[j++] = indexArray[i];
paramArray[j++] = val;
}
return commandExecutor.writeAsync(getRawName(), RedisCommands.BITFIELD_VOID, paramArray);
}
@Override
public byte[] toByteArray() {
return get(toByteArrayAsync());

@ -239,6 +239,14 @@ public interface RBitSet extends RExpirable, RBitSetAsync {
*/
void set(BitSet bs);
/**
* Set all bits to <code>value</code> which index in indexArray
*
* @param indexArray The index array of bits that needs to be set to <code>value</code>
* @param value true = 1, false = 0
*/
void set(long[] indexArray, boolean value);
/**
* Executes NOT operation over all bits
*/

@ -294,6 +294,14 @@ public interface RBitSetAsync extends RExpirableAsync {
*/
RFuture<Boolean> setAsync(long bitIndex, boolean value);
/**
* Set all bits to <code>value</code> which index in indexArray
*
* @param indexArray The index array of bits that needs to be set to <code>value</code>
* @param value true = 1, false = 0
*/
RFuture<Void> setAsync(long[] indexArray, boolean value);
/**
* Returns the number of bits set to one.
*

@ -63,6 +63,7 @@ public interface RedisCommands {
new ListFirstObjectDecoder(), new ByteReplayConvertor());
RedisStrictCommand<Object> BITFIELD_SHORT = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new ShortReplayConvertor());
RedisStrictCommand<Void> BITFIELD_VOID = new RedisStrictCommand<>("BITFIELD", new VoidReplayConvertor());
RedisStrictCommand<Boolean> GETBIT = new RedisStrictCommand<Boolean>("GETBIT", new BooleanReplayConvertor());
RedisStrictCommand<Long> BITS_SIZE = new RedisStrictCommand<Long>("STRLEN", new BitsSizeReplayConvertor());

@ -2,8 +2,10 @@ package org.redisson;
import org.junit.jupiter.api.Test;
import org.redisson.api.RBitSet;
import org.springframework.util.StopWatch;
import java.util.BitSet;
import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
@ -123,6 +125,15 @@ public class RedissonBitSetTest extends BaseTest {
bs = redisson.getBitSet("testbitset");
assertThat(bs.toString()).isEqualTo("{1, 10}");
RBitSet bs2 = redisson.getBitSet("testbitset2");
bs2.set(new long[]{1L,3L,5L,7L}, true);
bs2 = redisson.getBitSet("testbitset2");
assertThat(bs2.toString()).isEqualTo("{1, 3, 5, 7}");
bs2.set(new long[]{3L,5L}, false);
bs2 = redisson.getBitSet("testbitset2");
assertThat(bs2.toString()).isEqualTo("{1, 7}");
}
@Test

Loading…
Cancel
Save