Feature - BITFIELD command support

pull/970/merge
Nikita Koksharov 5 years ago
parent 990ae29b22
commit 88b8c19eb9

@ -15,12 +15,6 @@
*/
package org.redisson;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import org.redisson.api.RBitSet;
import org.redisson.api.RFuture;
import org.redisson.client.codec.ByteArrayCodec;
@ -30,6 +24,8 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.command.CommandBatchService;
import java.util.*;
/**
*
* @author Nikita Koksharov
@ -41,6 +37,138 @@ public class RedissonBitSet extends RedissonExpirable implements RBitSet {
super(null, connectionManager, name);
}
@Override
public byte getByte(long offset) {
return get(getByteAsync(offset));
}
@Override
public byte setByte(long offset, byte value) {
return get(setByteAsync(offset, value));
}
@Override
public byte incrementAndGetByte(long offset, byte increment) {
return get(incrementAndGetByteAsync(offset, increment));
}
@Override
public short getShort(long offset) {
return get(getShortAsync(offset));
}
@Override
public short setShort(long offset, short value) {
return get(setShortAsync(offset, value));
}
@Override
public short incrementAndGetShort(long offset, short increment) {
return get(incrementAndGetShortAsync(offset, increment));
}
@Override
public int getInteger(long offset) {
return get(getIntegerAsync(offset));
}
@Override
public int setInteger(long offset, int value) {
return get(setIntegerAsync(offset, value));
}
@Override
public int incrementAndGetInteger(long offset, int increment) {
return get(incrementAndGetIntegerAsync(offset, increment));
}
@Override
public long getLong(long offset) {
return get(getLongAsync(offset));
}
@Override
public long setLong(long offset, long value) {
return get(setLongAsync(offset, value));
}
@Override
public long incrementAndGetLong(long offset, long increment) {
return get(incrementAndGetLongAsync(offset, increment));
}
@Override
public RFuture<Byte> getByteAsync(long offset) {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_BYTE,
getName(), "GET", "i8", offset);
}
@Override
public RFuture<Byte> setByteAsync(long offset, byte value) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_BYTE,
getName(), "SET", "i8", offset, value);
}
@Override
public RFuture<Byte> incrementAndGetByteAsync(long offset, byte increment) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_BYTE,
getName(), "INCRBY", "i8", offset, increment);
}
@Override
public RFuture<Short> getShortAsync(long offset) {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_SHORT,
getName(), "GET", "i16", offset);
}
@Override
public RFuture<Short> setShortAsync(long offset, short value) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_SHORT,
getName(), "SET", "i16", offset, value);
}
@Override
public RFuture<Short> incrementAndGetShortAsync(long offset, short increment) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_SHORT,
getName(), "INCRBY", "i16", offset, increment);
}
@Override
public RFuture<Integer> getIntegerAsync(long offset) {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_INT,
getName(), "GET", "i32", offset);
}
@Override
public RFuture<Integer> setIntegerAsync(long offset, int value) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_INT,
getName(), "SET", "i32", offset, value);
}
@Override
public RFuture<Integer> incrementAndGetIntegerAsync(long offset, int increment) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_INT,
getName(), "INCRBY", "i32", offset, increment);
}
@Override
public RFuture<Long> getLongAsync(long offset) {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_LONG,
getName(), "GET", "i64", offset);
}
@Override
public RFuture<Long> setLongAsync(long offset, long value) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_LONG,
getName(), "SET", "i64", offset, value);
}
@Override
public RFuture<Long> incrementAndGetLongAsync(long offset, long increment) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.BITFIELD_LONG,
getName(), "INCRBY", "i64", offset, increment);
}
@Override
public long length() {
return get(lengthAsync());

@ -25,6 +25,118 @@ import java.util.BitSet;
*/
public interface RBitSet extends RExpirable, RBitSetAsync {
/**
* Returns byte number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
byte getByte(long offset);
/**
* Returns previous value of byte number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
byte setByte(long offset, byte value);
/**
* Increments current byte value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
byte incrementAndGetByte(long offset, byte increment);
/**
* Returns short number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
short getShort(long offset);
/**
* Returns previous value of short number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
short setShort(long offset, short value);
/**
* Increments current short value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
short incrementAndGetShort(long offset, short increment);
/**
* Returns integer number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
int getInteger(long offset);
/**
* Returns previous value of integer number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
int setInteger(long offset, int value);
/**
* Increments current integer value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
int incrementAndGetInteger(long offset, int increment);
/**
* Returns long number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
long getLong(long offset);
/**
* Returns previous value of long number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
long setLong(long offset, long value);
/**
* Increments current long value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
long incrementAndGetLong(long offset, long increment);
/**
* Returns "logical size" = index of highest set bit plus one.
* Returns zero if there are no any set bit.

@ -25,40 +25,152 @@ import java.util.BitSet;
*/
public interface RBitSetAsync extends RExpirableAsync {
/**
* Returns byte number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
RFuture<Byte> getByteAsync(long offset);
/**
* Returns previous value of byte number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
RFuture<Byte> setByteAsync(long offset, byte value);
/**
* Increments current byte value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
RFuture<Byte> incrementAndGetByteAsync(long offset, byte increment);
/**
* Returns short number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
RFuture<Short> getShortAsync(long offset);
/**
* Returns previous value of short number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
RFuture<Short> setShortAsync(long offset, short value);
/**
* Increments current short value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
RFuture<Short> incrementAndGetShortAsync(long offset, short increment);
/**
* Returns integer number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
RFuture<Integer> getIntegerAsync(long offset);
/**
* Returns previous value of integer number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
RFuture<Integer> setIntegerAsync(long offset, int value);
/**
* Increments current integer value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
RFuture<Integer> incrementAndGetIntegerAsync(long offset, int increment);
/**
* Returns long number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
RFuture<Long> getLongAsync(long offset);
/**
* Returns previous value of long number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
RFuture<Long> setLongAsync(long offset, long value);
/**
* Increments current long value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
RFuture<Long> incrementAndGetLongAsync(long offset, long increment);
RFuture<byte[]> toByteArrayAsync();
/**
* Returns "logical size" = index of highest set bit plus one.
* Returns zero if there are no any set bit.
*
*
* @return "logical size" = index of highest set bit plus one
*/
RFuture<Long> lengthAsync();
/**
* Set all bits to <code>value</code> from <code>fromIndex</code> (inclusive) to <code>toIndex</code> (exclusive)
*
*
* @param fromIndex inclusive
* @param toIndex exclusive
* @param value true = 1, false = 0
* @return void
*
*
*/
RFuture<Void> setAsync(long fromIndex, long toIndex, boolean value);
/**
* Set all bits to zero from <code>fromIndex</code> (inclusive) to <code>toIndex</code> (exclusive)
*
*
* @param fromIndex inclusive
* @param toIndex exclusive
* @return void
*
*
*/
RFuture<Void> clearAsync(long fromIndex, long toIndex);
/**
* Copy bits state of source BitSet object to this object
*
*
* @param bs - BitSet source
* @return void
*/
@ -66,14 +178,14 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Executes NOT operation over all bits
*
*
* @return void
*/
RFuture<Void> notAsync();
/**
* Set all bits to one from <code>fromIndex</code> (inclusive) to <code>toIndex</code> (exclusive)
*
*
* @param fromIndex inclusive
* @param toIndex exclusive
* @return void
@ -82,14 +194,14 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Returns number of set bits.
*
*
* @return number of set bits.
*/
RFuture<Long> sizeAsync();
/**
* Returns <code>true</code> if bit set to one and <code>false</code> overwise.
*
*
* @param bitIndex - index of bit
* @return <code>true</code> if bit set to one and <code>false</code> overwise.
*/
@ -97,26 +209,26 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Set bit to one at specified bitIndex
*
*
* @param bitIndex - index of bit
* @return <code>true</code> - if previous value was true,
* @return <code>true</code> - if previous value was true,
* <code>false</code> - if previous value was false
*/
RFuture<Boolean> setAsync(long bitIndex);
/**
* Set bit to <code>value</code> at specified <code>bitIndex</code>
*
*
* @param bitIndex - index of bit
* @param value true = 1, false = 0
* @return <code>true</code> - if previous value was true,
* @return <code>true</code> - if previous value was true,
* <code>false</code> - if previous value was false
*/
RFuture<Boolean> setAsync(long bitIndex, boolean value);
/**
* Returns the number of bits set to one.
*
*
* @return number of bits
*/
RFuture<Long> cardinalityAsync();
@ -125,14 +237,14 @@ public interface RBitSetAsync extends RExpirableAsync {
* Set bit to zero at specified <code>bitIndex</code>
*
* @param bitIndex - index of bit
* @return <code>true</code> - if previous value was true,
* @return <code>true</code> - if previous value was true,
* <code>false</code> - if previous value was false
*/
RFuture<Boolean> clearAsync(long bitIndex);
/**
* Set all bits to zero
*
*
* @return void
*/
RFuture<Void> clearAsync();
@ -140,7 +252,7 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Executes OR operation over this object and specified bitsets.
* Stores result into this object.
*
*
* @param bitSetNames - name of stored bitsets
* @return void
*/
@ -149,7 +261,7 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Executes AND operation over this object and specified bitsets.
* Stores result into this object.
*
*
* @param bitSetNames - name of stored bitsets
* @return void
*/
@ -158,7 +270,7 @@ public interface RBitSetAsync extends RExpirableAsync {
/**
* Executes XOR operation over this object and specified bitsets.
* Stores result into this object.
*
*
* @param bitSetNames - name of stored bitsets
* @return void
*/

@ -15,10 +15,10 @@
*/
package org.redisson.api;
import java.util.BitSet;
import reactor.core.publisher.Mono;
import java.util.BitSet;
/**
* Reactive interface for BitSet object
*
@ -27,6 +27,118 @@ import reactor.core.publisher.Mono;
*/
public interface RBitSetReactive extends RExpirableReactive {
/**
* Returns byte number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Mono<Byte> getByte(long offset);
/**
* Returns previous value of byte number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Mono<Byte> setByte(long offset, byte value);
/**
* Increments current byte value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Mono<Byte> incrementAndGetByte(long offset, byte increment);
/**
* Returns short number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Mono<Short> getShort(long offset);
/**
* Returns previous value of short number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Mono<Short> setShort(long offset, short value);
/**
* Increments current short value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Mono<Short> incrementAndGetShort(long offset, short increment);
/**
* Returns integer number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Mono<Integer> getInteger(long offset);
/**
* Returns previous value of integer number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Mono<Integer> setInteger(long offset, int value);
/**
* Increments current integer value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Mono<Integer> incrementAndGetInteger(long offset, int increment);
/**
* Returns long number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Mono<Long> getLong(long offset);
/**
* Returns previous value of long number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Mono<Long> setLong(long offset, long value);
/**
* Increments current long value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Mono<Long> incrementAndGetLong(long offset, long increment);
Mono<byte[]> toByteArray();
/**

@ -15,11 +15,12 @@
*/
package org.redisson.api;
import java.util.BitSet;
import io.reactivex.Completable;
import io.reactivex.Single;
import java.util.BitSet;
/**
* RxJava2 interface for BitSet object
*
@ -28,6 +29,118 @@ import io.reactivex.Single;
*/
public interface RBitSetRx extends RExpirableRx {
/**
* Returns byte number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Single<Byte> getByte(long offset);
/**
* Returns previous value of byte number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Single<Byte> setByte(long offset, byte value);
/**
* Increments current byte value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Single<Byte> incrementAndGetByte(long offset, byte increment);
/**
* Returns short number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Single<Short> getShort(long offset);
/**
* Returns previous value of short number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Single<Short> setShort(long offset, short value);
/**
* Increments current short value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Single<Short> incrementAndGetShort(long offset, short increment);
/**
* Returns integer number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Single<Integer> getInteger(long offset);
/**
* Returns previous value of integer number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Single<Integer> setInteger(long offset, int value);
/**
* Increments current integer value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Single<Integer> incrementAndGetInteger(long offset, int increment);
/**
* Returns long number at specified <code>offset</code>
*
* @param offset - offset of number
* @return number
*/
Single<Long> getLong(long offset);
/**
* Returns previous value of long number and replaces it
* with defined <code>value</code> at specified <code>offset</code>
*
* @param offset - offset of number
* @param value - value of number
* @return previous value of number
*/
Single<Long> setLong(long offset, long value);
/**
* Increments current long value on defined <code>increment</code> value at specified <code>offset</code>
* and returns result.
*
* @param offset - offset of number
* @param increment - increment value
* @return result value
*/
Single<Long> incrementAndGetLong(long offset, long increment);
Single<byte[]> toByteArray();
/**

@ -15,40 +15,20 @@
*/
package org.redisson.client.protocol;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.redisson.api.RType;
import org.redisson.api.StreamInfo;
import org.redisson.api.StreamMessageId;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.convertor.BitsSizeReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanAmountReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNotNullReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNullReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNullSafeReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanNumberReplayConvertor;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.convertor.DoubleNullSafeReplayConvertor;
import org.redisson.client.protocol.convertor.DoubleReplayConvertor;
import org.redisson.client.protocol.convertor.IntegerReplayConvertor;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.client.protocol.convertor.StreamIdConvertor;
import org.redisson.client.protocol.convertor.StringToListConvertor;
import org.redisson.client.protocol.convertor.TimeObjectDecoder;
import org.redisson.client.protocol.convertor.TrueReplayConvertor;
import org.redisson.client.protocol.convertor.TypeConvertor;
import org.redisson.client.protocol.convertor.VoidReplayConvertor;
import org.redisson.client.protocol.convertor.*;
import org.redisson.client.protocol.decoder.*;
import org.redisson.client.protocol.pubsub.PubSubStatusDecoder;
import org.redisson.cluster.ClusterNodeInfo;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.Map.Entry;
/**
*
* @author Nikita Koksharov
@ -68,6 +48,15 @@ public interface RedisCommands {
RedisStrictCommand<Integer> KEYSLOT = new RedisStrictCommand<Integer>("CLUSTER", "KEYSLOT", new IntegerReplayConvertor());
RedisStrictCommand<RType> TYPE = new RedisStrictCommand<RType>("TYPE", new TypeConvertor());
RedisStrictCommand<Object> BITFIELD_LONG = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new LongReplayConvertor());
RedisStrictCommand<Object> BITFIELD_INT = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new IntegerReplayConvertor(0));
RedisStrictCommand<Object> BITFIELD_BYTE = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new ByteReplayConvertor());
RedisStrictCommand<Object> BITFIELD_SHORT = new RedisStrictCommand<>("BITFIELD", null,
new ListFirstObjectDecoder(), new ShortReplayConvertor());
RedisStrictCommand<Boolean> GETBIT = new RedisStrictCommand<Boolean>("GETBIT", new BooleanReplayConvertor());
RedisStrictCommand<Long> BITS_SIZE = new RedisStrictCommand<Long>("STRLEN", new BitsSizeReplayConvertor());
RedisStrictCommand<Long> STRLEN = new RedisStrictCommand<Long>("STRLEN");

@ -0,0 +1,34 @@
/**
* Copyright (c) 2013-2020 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.convertor;
/**
*
* @author Nikita Koksharov
*
*/
public class ByteReplayConvertor implements Convertor<Byte> {
@Override
public Byte convert(Object obj) {
if (obj == null) {
return 0;
}
return Byte.valueOf(obj.toString());
}
}

@ -0,0 +1,34 @@
/**
* Copyright (c) 2013-2020 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.convertor;
/**
*
* @author Nikita Koksharov
*
*/
public class ShortReplayConvertor implements Convertor<Short> {
@Override
public Short convert(Object obj) {
if (obj == null) {
return 0;
}
return Short.valueOf(obj.toString());
}
}

@ -8,6 +8,35 @@ import org.redisson.api.RBitSet;
public class RedissonBitSetTest extends BaseTest {
@Test
public void testIncrement() {
RBitSet bs2 = redisson.getBitSet("testbitset1");
assertThat(bs2.setByte(2, (byte)12)).isZero();
assertThat(bs2.getByte(2)).isEqualTo((byte)12);
assertThat(bs2.incrementAndGetByte(2, (byte)12)).isEqualTo((byte) 24);
assertThat(bs2.getByte(2)).isEqualTo((byte)24);
}
@Test
public void testSetGetNumber() {
RBitSet bs = redisson.getBitSet("testbitset");
assertThat(bs.setLong(2, 12L)).isZero();
assertThat(bs.getLong(2)).isEqualTo(12);
RBitSet bs2 = redisson.getBitSet("testbitset1");
assertThat(bs2.setByte(2, (byte)12)).isZero();
assertThat(bs2.getByte(2)).isEqualTo((byte)12);
RBitSet bs3 = redisson.getBitSet("testbitset2");
assertThat(bs3.setShort(2, (short)2312)).isZero();
assertThat(bs3.getShort(2)).isEqualTo((short)2312);
RBitSet bs4 = redisson.getBitSet("testbitset3");
assertThat(bs4.setInteger(2, 323241)).isZero();
assertThat(bs4.getInteger(2)).isEqualTo(323241);
}
@Test
public void testIndexRange() {
RBitSet bs = redisson.getBitSet("testbitset");

Loading…
Cancel
Save