|
|
@ -15,21 +15,20 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.redisson.reactive;
|
|
|
|
package org.redisson.reactive;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.reactivestreams.Publisher;
|
|
|
|
import org.reactivestreams.Publisher;
|
|
|
|
import org.redisson.RedissonListMultimap;
|
|
|
|
import org.redisson.RedissonListMultimap;
|
|
|
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
|
|
|
import org.redisson.api.RList;
|
|
|
|
|
|
|
|
import org.redisson.api.RListMultimap;
|
|
|
|
import org.redisson.api.RListMultimapReactive;
|
|
|
|
import org.redisson.api.RListMultimapReactive;
|
|
|
|
import org.redisson.api.RListReactive;
|
|
|
|
import org.redisson.api.RListReactive;
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
import org.redisson.client.protocol.RedisCommands;
|
|
|
|
|
|
|
|
import org.redisson.command.CommandReactiveExecutor;
|
|
|
|
import org.redisson.command.CommandReactiveExecutor;
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import reactor.fn.Supplier;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -49,95 +48,39 @@ public class RedissonListMultimapReactive<K, V> extends RedissonBaseMultimapReac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RListReactive<V> get(final K key) {
|
|
|
|
public RListReactive<V> get(K key) {
|
|
|
|
final ByteBuf keyState = encodeMapKey(key);
|
|
|
|
RList<V> list = ((RListMultimap<K, V>)instance).get(key);
|
|
|
|
final String keyHash = hashAndRelease(keyState);
|
|
|
|
return new RedissonListReactive<V>(codec, commandExecutor, list.getName(), list);
|
|
|
|
final String setName = getValuesName(keyHash);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new RedissonListReactive<V>(codec, commandExecutor, setName) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Boolean> delete() {
|
|
|
|
|
|
|
|
ByteBuf keyState = encodeMapKey(key);
|
|
|
|
|
|
|
|
return RedissonListMultimapReactive.this.fastRemove(Arrays.<Object>asList(keyState), Arrays.<Object>asList(setName), RedisCommands.EVAL_BOOLEAN_AMOUNT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Boolean> clearExpire() {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Boolean> expire(long timeToLive, TimeUnit timeUnit) {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Boolean> expireAt(long timestamp) {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Long> remainTimeToLive() {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Void> rename(String newName) {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Publisher<Boolean> renamenx(String newName) {
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("This operation is not supported for SetMultimap values Set");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Publisher<List<V>> getAll(K key) {
|
|
|
|
public Publisher<List<V>> getAll(final K key) {
|
|
|
|
ByteBuf keyState = encodeMapKey(key);
|
|
|
|
return reactive(new Supplier<RFuture<List<V>>>() {
|
|
|
|
String keyHash = hashAndRelease(keyState);
|
|
|
|
@Override
|
|
|
|
String setName = getValuesName(keyHash);
|
|
|
|
public RFuture<List<V>> get() {
|
|
|
|
|
|
|
|
return (RFuture<List<V>>)(Object)((RListMultimap<K, V>)instance).getAllAsync(key);
|
|
|
|
return commandExecutor.readReactive(getName(), codec, RedisCommands.LRANGE, setName, 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Publisher<List<V>> removeAll(Object key) {
|
|
|
|
public Publisher<List<V>> removeAll(final Object key) {
|
|
|
|
ByteBuf keyState = encodeMapKey(key);
|
|
|
|
return reactive(new Supplier<RFuture<List<V>>>() {
|
|
|
|
String keyHash = hash(keyState);
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public RFuture<List<V>> get() {
|
|
|
|
String setName = getValuesName(keyHash);
|
|
|
|
return (RFuture<List<V>>)(Object)((RListMultimap<K, V>)instance).removeAllAsync(key);
|
|
|
|
return commandExecutor.evalWriteReactive(getName(), codec, RedisCommands.EVAL_LIST,
|
|
|
|
}
|
|
|
|
"redis.call('hdel', KEYS[1], ARGV[1]); " +
|
|
|
|
});
|
|
|
|
"local members = redis.call('lrange', KEYS[2], 0, -1); " +
|
|
|
|
|
|
|
|
"redis.call('del', KEYS[2]); " +
|
|
|
|
|
|
|
|
"return members; ",
|
|
|
|
|
|
|
|
Arrays.<Object>asList(getName(), setName), keyState);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Publisher<List<V>> replaceValues(K key, Iterable<? extends V> values) {
|
|
|
|
public Publisher<List<V>> replaceValues(final K key, final Iterable<? extends V> values) {
|
|
|
|
List<Object> params = new ArrayList<Object>();
|
|
|
|
return reactive(new Supplier<RFuture<List<V>>>() {
|
|
|
|
ByteBuf keyState = encodeMapKey(key);
|
|
|
|
@Override
|
|
|
|
params.add(keyState);
|
|
|
|
public RFuture<List<V>> get() {
|
|
|
|
String keyHash = hash(keyState);
|
|
|
|
return (RFuture<List<V>>)(Object)((RListMultimap<K, V>)instance).replaceValuesAsync(key, values);
|
|
|
|
params.add(keyHash);
|
|
|
|
}
|
|
|
|
for (Object value : values) {
|
|
|
|
});
|
|
|
|
ByteBuf valueState = encodeMapValue(value);
|
|
|
|
|
|
|
|
params.add(valueState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String setName = getValuesName(keyHash);
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteReactive(getName(), codec, RedisCommands.EVAL_LIST,
|
|
|
|
|
|
|
|
"redis.call('hset', KEYS[1], ARGV[1], ARGV[2]); " +
|
|
|
|
|
|
|
|
"local members = redis.call('lrange', KEYS[2], 0, -1); " +
|
|
|
|
|
|
|
|
"redis.call('del', KEYS[2]); " +
|
|
|
|
|
|
|
|
"redis.call('rpush', KEYS[2], unpack(ARGV, 3, #ARGV)); " +
|
|
|
|
|
|
|
|
"return members; ",
|
|
|
|
|
|
|
|
Arrays.<Object>asList(getName(), setName), params.toArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|