org.redisson.RedissonBitSet Maven / Gradle / Ivy
/**
* Copyright 2018 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;
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;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.command.CommandBatchService;
/**
*
* @author Nikita Koksharov
*
*/
public class RedissonBitSet extends RedissonExpirable implements RBitSet {
public RedissonBitSet(CommandAsyncExecutor connectionManager, String name) {
super(null, connectionManager, name);
}
@Override
public long length() {
return get(lengthAsync());
}
@Override
public void set(BitSet bs) {
get(setAsync(bs));
}
@Override
public boolean get(long bitIndex) {
return get(getAsync(bitIndex));
}
@Override
public RFuture getAsync(long bitIndex) {
return commandExecutor.readAsync(getName(), LongCodec.INSTANCE, RedisCommands.GETBIT, getName(), bitIndex);
}
@Override
public boolean set(long bitIndex) {
return get(setAsync(bitIndex, true));
}
@Override
public void set(long fromIndex, long toIndex, boolean value) {
get(setAsync(fromIndex, toIndex, value));
}
@Override
public void set(long fromIndex, long toIndex) {
get(setAsync(fromIndex, toIndex));
}
@Override
public void set(long bitIndex, boolean value) {
get(setAsync(bitIndex, value));
}
@Override
public RFuture setAsync(long bitIndex, boolean value) {
return commandExecutor.writeAsync(getName(), LongCodec.INSTANCE, RedisCommands.SETBIT, getName(), bitIndex, value ? 1 : 0);
}
@Override
public byte[] toByteArray() {
return get(toByteArrayAsync());
}
@Override
public RFuture toByteArrayAsync() {
return commandExecutor.readAsync(getName(), ByteArrayCodec.INSTANCE, RedisCommands.GET, getName());
}
@Override
public long cardinality() {
return get(cardinalityAsync());
}
@Override
public long size() {
return get(sizeAsync());
}
@Override
public void clear(long fromIndex, long toIndex) {
get(clearAsync(fromIndex, toIndex));
}
@Override
public boolean clear(long bitIndex) {
return get(clearAsync(bitIndex));
}
@Override
public void clear() {
get(clearAsync());
}
@Override
public void or(String... bitSetNames) {
get(orAsync(bitSetNames));
}
@Override
public void and(String... bitSetNames) {
get(andAsync(bitSetNames));
}
@Override
public void xor(String... bitSetNames) {
get(xorAsync(bitSetNames));
}
@Override
public void not() {
get(notAsync());
}
private RFuture opAsync(String op, String... bitSetNames) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy