
org.redisson.reactive.RedissonSetReactive Maven / Gradle / Ivy
/**
* Copyright 2016 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.reactive;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import org.reactivestreams.Publisher;
import org.redisson.RedissonSet;
import org.redisson.api.RFuture;
import org.redisson.api.RSetReactive;
import org.redisson.client.RedisClient;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.ScanCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.client.protocol.decoder.ScanObjectEntry;
import org.redisson.command.CommandReactiveExecutor;
import reactor.core.publisher.Flux;
/**
* Distributed and concurrent implementation of {@link java.util.Set}
*
* @author Nikita Koksharov
*
* @param value
*/
public class RedissonSetReactive extends RedissonExpirableReactive implements RSetReactive {
private final RedissonSet instance;
public RedissonSetReactive(CommandReactiveExecutor commandExecutor, String name) {
super(commandExecutor, name);
instance = new RedissonSet(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name, null);
}
public RedissonSetReactive(Codec codec, CommandReactiveExecutor commandExecutor, String name) {
super(codec, commandExecutor, name);
instance = new RedissonSet(codec, commandExecutor, name, null);
}
@Override
public Publisher addAll(Publisher extends V> c) {
return new PublisherAdder(this).addAll(c);
}
@Override
public Publisher size() {
return commandExecutor.readReactive(getName(), codec, RedisCommands.SCARD_INT, getName());
}
@Override
public Publisher contains(final Object o) {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.containsAsync(o);
}
});
}
private Publisher> scanIteratorReactive(RedisClient client, long startPos) {
return commandExecutor.readReactive(client, getName(), new ScanCodec(codec), RedisCommands.SSCAN, getName(), startPos);
}
@Override
public Publisher add(V e) {
return commandExecutor.writeReactive(getName(), codec, RedisCommands.SADD, getName(), encode(e));
}
@Override
public Publisher removeRandom() {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.removeRandomAsync();
}
});
}
@Override
public Publisher random() {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.randomAsync();
}
});
}
@Override
public Publisher remove(final Object o) {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.removeAsync(o);
}
});
}
@Override
public Publisher move(final String destination, final V member) {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.moveAsync(destination, member);
}
});
}
@Override
public Publisher containsAll(final Collection> c) {
return reactive(new Supplier>() {
@Override
public RFuture get() {
return instance.containsAllAsync(c);
}
});
}
@Override
public Publisher addAll(Collection extends V> c) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy