Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2022 the original author or authors.
*
* 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
*
* https://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.springframework.data.redis.core;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.springframework.data.redis.connection.ReactiveSetCommands;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.util.Assert;
/**
* Default implementation of {@link ReactiveSetOperations}.
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Roman Bezpalko
* @since 2.0
*/
class DefaultReactiveSetOperations implements ReactiveSetOperations {
private final ReactiveRedisTemplate template;
private final RedisSerializationContext serializationContext;
DefaultReactiveSetOperations(ReactiveRedisTemplate template,
RedisSerializationContext serializationContext) {
this.template = template;
this.serializationContext = serializationContext;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#add(java.lang.Object, java.lang.Object[])
*/
@Override
public Mono add(K key, V... values) {
Assert.notNull(key, "Key must not be null!");
if (values.length == 1) {
return createMono(connection -> connection.sAdd(rawKey(key), rawValue(values[0])));
}
return createMono(connection -> Flux.fromArray(values) //
.map(this::rawValue) //
.collectList() //
.flatMap(serialized -> connection.sAdd(rawKey(key), serialized)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#remove(java.lang.Object, java.lang.Object[])
*/
@Override
@SuppressWarnings("unchecked")
public Mono remove(K key, Object... values) {
Assert.notNull(key, "Key must not be null!");
if (values.length == 1) {
return createMono(connection -> connection.sRem(rawKey(key), rawValue((V) values[0])));
}
return createMono(connection -> Flux.fromArray((V[]) values) //
.map(this::rawValue) //
.collectList() //
.flatMap(serialized -> connection.sRem(rawKey(key), serialized)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#pop(java.lang.Object)
*/
@Override
public Mono pop(K key) {
Assert.notNull(key, "Key must not be null!");
return createMono(connection -> connection.sPop(rawKey(key)).map(this::readValue));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#pop(java.lang.Object, long)
*/
@Override
public Flux pop(K key, long count) {
Assert.notNull(key, "Key must not be null!");
return createFlux(connection -> connection.sPop(rawKey(key), count).map(this::readValue));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#move(java.lang.Object, java.lang.Object, java.lang.Object)
*/
@Override
public Mono move(K sourceKey, V value, K destKey) {
Assert.notNull(sourceKey, "Source key must not be null!");
Assert.notNull(destKey, "Destination key must not be null!");
return createMono(connection -> connection.sMove(rawKey(sourceKey), rawKey(destKey), rawValue(value)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#size(java.lang.Object)
*/
@Override
public Mono size(K key) {
Assert.notNull(key, "Key must not be null!");
return createMono(connection -> connection.sCard(rawKey(key)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#isMember(java.lang.Object, java.lang.Object)
*/
@Override
@SuppressWarnings("unchecked")
public Mono isMember(K key, Object o) {
Assert.notNull(key, "Key must not be null!");
return createMono(connection -> connection.sIsMember(rawKey(key), rawValue((V) o)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ReactiveSetOperations#isMember(java.lang.Object, java.lang.Object...)
*/
@Override
public Mono