Feature - Bitset add method get(Long ...x1)

Signed-off-by: seakider <seakider@gmail.com>
pull/6425/head
seakider 2 weeks ago
parent 7dc4d31d7b
commit 981653ed6c

@ -278,6 +278,24 @@ public class RedissonBitSet extends RedissonExpirable implements RBitSet {
return commandExecutor.readAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.GETBIT, getRawName(), bitIndex);
}
@Override
public boolean[] get(long... bitIndexes) {
return get(getAsync(bitIndexes));
}
@Override
public RFuture<boolean[]> getAsync(long... bitIndexes) {
Object[] indexes = new Object[bitIndexes.length * 3 + 1];
int j = 0;
indexes[j++] = getRawName();
for (long l : bitIndexes) {
indexes[j++] = "get";
indexes[j++] = "u1";
indexes[j++] = l;
}
return commandExecutor.readAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_BOOLEANS, indexes);
}
@Override
public boolean set(long bitIndex) {
return get(setAsync(bitIndex, true));

@ -275,6 +275,14 @@ public interface RBitSet extends RExpirable, RBitSetAsync {
* @return <code>true</code> if bit set to one and <code>false</code> overwise.
*/
boolean get(long bitIndex);
/**
* Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*
* @param bitIndexes indexes of bit
* @return Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*/
boolean[] get(long... bitIndexes);
/**
* Set bit to one at specified bitIndex

@ -274,6 +274,14 @@ public interface RBitSetAsync extends RExpirableAsync {
* @return <code>true</code> if bit set to one and <code>false</code> overwise.
*/
RFuture<Boolean> getAsync(long bitIndex);
/**
* Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*
* @param bitIndexes indexes of bit
* @return Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*/
RFuture<boolean[]> getAsync(long... bitIndexes);
/**
* Set bit to one at specified bitIndex

@ -276,6 +276,14 @@ public interface RBitSetReactive extends RExpirableReactive {
* @return <code>true</code> if bit set to one and <code>false</code> overwise.
*/
Mono<Boolean> get(long bitIndex);
/**
* Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*
* @param bitIndexes indexes of bit
* @return Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*/
Mono<boolean[]> get(long... bitIndexes);
/**
* Set bit to one at specified bitIndex

@ -278,6 +278,14 @@ public interface RBitSetRx extends RExpirableRx {
* @return <code>true</code> if bit set to one and <code>false</code> overwise.
*/
Single<Boolean> get(long bitIndex);
/**
* Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*
* @param bitIndexes indexes of bit
* @return Returns a boolean array where each element of the array corresponds to the query result of the input parameters.
*/
Single<boolean[]> get(long... bitIndexes);
/**
* Set bit to one at specified bitIndex

@ -64,6 +64,9 @@ public interface RedisCommands {
RedisStrictCommand<Object> BITFIELD_SHORT = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new ShortReplayConvertor());
RedisStrictCommand<Void> BITFIELD_VOID = new RedisStrictCommand<>("BITFIELD", new VoidReplayConvertor());
RedisStrictCommand<boolean[]> BITFIELD_BOOLEANS = new RedisStrictCommand<>("BITFIELD", null,
new ArrayBooleanDecoder(), new BooleanReplayConvertor());
RedisStrictCommand<Boolean> GETBIT = new RedisStrictCommand<Boolean>("GETBIT", new BooleanReplayConvertor());
RedisStrictCommand<Long> BITS_SIZE = new RedisStrictCommand<Long>("STRLEN", new BitsSizeReplayConvertor());

@ -0,0 +1,46 @@
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client.protocol.decoder;
import org.redisson.client.handler.State;
import java.util.List;
/**
*
* @author seakider
*
*/
public class ArrayBooleanDecoder implements MultiDecoder<boolean[]> {
@Override
public boolean[] decode(List<Object> parts, State state) {
if (parts.isEmpty()) {
return new boolean[0];
}
boolean[] result = new boolean[parts.size()];
for (int i = 0; i < parts.size(); i++) {
Object part = parts.get(i);
if (part instanceof Boolean) {
result[i] = (boolean) part;
} else {
result[i] = false;
}
}
return result;
}
}

@ -6,6 +6,8 @@ import org.redisson.api.RBitSetReactive;
import java.util.BitSet;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonBitSetReactiveTest extends BaseReactiveTest {
@Test
@ -112,6 +114,17 @@ public class RedissonBitSetReactiveTest extends BaseReactiveTest {
Assertions.assertEquals(1, sync(bs1.cardinality()).intValue());
Assertions.assertEquals(16, sync(bs1.size()).intValue());
}
@Test
public void testGetWithIndexes() {
RBitSetReactive bitset = redisson.getBitSet("testbitset");
sync(bitset.set(4, 10));
boolean[] result = sync(bitset.get(2, 4, 7, 8));
assertThat(result[0]).isFalse();
assertThat(result[1]).isTrue();
assertThat(result[2]).isTrue();
assertThat(result[3]).isTrue();
}
}

@ -210,5 +210,16 @@ public class RedissonBitSetTest extends RedisDockerTest {
assertThat(bs1.size()).isEqualTo(16);
}
@Test
public void testGetWithIndexes() {
RBitSet bitset = redisson.getBitSet("testbitset");
bitset.set(4, 10);
boolean[] result = bitset.get(2, 4, 7, 8);
assertThat(result[0]).isFalse();
assertThat(result[1]).isTrue();
assertThat(result[2]).isTrue();
assertThat(result[3]).isTrue();
}
}

Loading…
Cancel
Save