Feature - reactive interface for RListMultimapCache & RSetMultimapCache objects. #3885

pull/3951/head
Nikita Koksharov 3 years ago
parent 841c9353ab
commit fdcb943828

@ -268,6 +268,34 @@ public class RedissonReactive implements RedissonReactiveClient {
new RedissonSetMultimapReactive<K, V>(codec, commandExecutor, name, this), RSetMultimapReactive.class);
}
@Override
public <K, V> RListMultimapCacheReactive<K, V> getListMultimapCache(String name) {
RedissonListMultimapCache<K, V> listMultimap = new RedissonListMultimapCache<>(evictionScheduler, commandExecutor, name);
return ReactiveProxyBuilder.create(commandExecutor, listMultimap,
new RedissonListMultimapCacheReactive<K, V>(listMultimap, commandExecutor), RListMultimapCacheReactive.class);
}
@Override
public <K, V> RListMultimapCacheReactive<K, V> getListMultimapCache(String name, Codec codec) {
RedissonListMultimapCache<K, V> listMultimap = new RedissonListMultimapCache<>(evictionScheduler, codec, commandExecutor, name);
return ReactiveProxyBuilder.create(commandExecutor, listMultimap,
new RedissonListMultimapCacheReactive<>(listMultimap, commandExecutor), RListMultimapCacheReactive.class);
}
@Override
public <K, V> RSetMultimapCacheReactive<K, V> getSetMultimapCache(String name) {
RedissonSetMultimapCache<K, V> setMultimap = new RedissonSetMultimapCache<>(evictionScheduler, commandExecutor, name);
return ReactiveProxyBuilder.create(commandExecutor, setMultimap,
new RedissonSetMultimapCacheReactive<K, V>(setMultimap, commandExecutor, this), RSetMultimapCacheReactive.class);
}
@Override
public <K, V> RSetMultimapCacheReactive<K, V> getSetMultimapCache(String name, Codec codec) {
RedissonSetMultimapCache<K, V> setMultimap = new RedissonSetMultimapCache<>(evictionScheduler, codec, commandExecutor, name);
return ReactiveProxyBuilder.create(commandExecutor, setMultimap,
new RedissonSetMultimapCacheReactive<K, V>(setMultimap, commandExecutor, this), RSetMultimapCacheReactive.class);
}
@Override
public <K, V> RMapReactive<K, V> getMap(String name) {
RedissonMap<K, V> map = new RedissonMap<K, V>(commandExecutor, name, null, null, null);

@ -0,0 +1,28 @@
/**
* Copyright (c) 2013-2021 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.api;
/**
* Reactive interface for {@link RListMultimapCache} object.
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public interface RListMultimapCacheReactive<K, V> extends RListMultimapReactive<K, V>, RMultimapCacheReactive<K, V> {
}

@ -0,0 +1,42 @@
/**
* Copyright (c) 2013-2021 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.api;
import io.reactivex.rxjava3.core.Single;
import java.util.concurrent.TimeUnit;
/**
* Reactive interface of {@link RMultimapCache} object.
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public interface RMultimapCacheReactive<K, V> {
/**
* Set a timeout for key. After the timeout has expired, the key and its values will automatically be deleted.
*
* @param key - map key
* @param timeToLive - timeout before key will be deleted
* @param timeUnit - timeout time unit
* @return A Single that will emit <code>true</code> if key exists and the timeout was set and <code>false</code>
* if key not exists
*/
Single<Boolean> expireKey(K key, long timeToLive, TimeUnit timeUnit);
}

@ -0,0 +1,28 @@
/**
* Copyright (c) 2013-2021 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.api;
/**
* Reactive interface for {@link RSetMultimapCache} object.
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public interface RSetMultimapCacheReactive<K, V> extends RSetMultimapReactive<K, V>, RMultimapCacheReactive<K, V> {
}

@ -409,6 +409,31 @@ public interface RedissonReactiveClient {
*/
<K, V> RListMultimapReactive<K, V> getListMultimap(String name, Codec codec);
/**
* Returns List based Multimap cache instance by name.
* Supports key eviction by specifying a time to live.
* If eviction is not required then it's better to use regular list multimap {@link #getListMultimap(String)}.
*
* @param <K> type of key
* @param <V> type of value
* @param name - name of object
* @return RListMultimapCacheReactive object
*/
<K, V> RListMultimapCacheReactive<K, V> getListMultimapCache(String name);
/**
* Returns List based Multimap cache instance by name using provided codec for both map keys and values.
* Supports key eviction by specifying a time to live.
* If eviction is not required then it's better to use regular list multimap {@link #getListMultimap(String, Codec)}.
*
* @param <K> type of key
* @param <V> type of value
* @param name - name of object
* @param codec - codec for keys and values
* @return RListMultimapCacheReactive object
*/
<K, V> RListMultimapCacheReactive<K, V> getListMultimapCache(String name, Codec codec);
/**
* Returns Set based Multimap instance by name.
*
@ -431,7 +456,31 @@ public interface RedissonReactiveClient {
*/
<K, V> RSetMultimapReactive<K, V> getSetMultimap(String name, Codec codec);
/**
* Returns Set based Multimap cache instance by name.
* Supports key eviction by specifying a time to live.
* If eviction is not required then it's better to use regular set multimap {@link #getSetMultimap(String)}.
*
* @param <K> type of key
* @param <V> type of value
* @param name - name of object
* @return RSetMultimapCacheReactive object
*/
<K, V> RSetMultimapCacheReactive<K, V> getSetMultimapCache(String name);
/**
* Returns Set based Multimap cache instance by name using provided codec for both map keys and values.
* Supports key eviction by specifying a time to live.
* If eviction is not required then it's better to use regular set multimap {@link #getSetMultimap(String, Codec)}.
*
* @param <K> type of key
* @param <V> type of value
* @param name - name of object
* @param codec - codec for keys and values
* @return RSetMultimapCacheReactive object
*/
<K, V> RSetMultimapCacheReactive<K, V> getSetMultimapCache(String name, Codec codec);
/**
* Returns map instance by name.
*

@ -0,0 +1,43 @@
/**
* Copyright (c) 2013-2021 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 org.redisson.RedissonList;
import org.redisson.RedissonListMultimapCache;
import org.redisson.api.RListReactive;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public class RedissonListMultimapCacheReactive<K, V> {
private final RedissonListMultimapCache<K, V> instance;
private final CommandReactiveExecutor commandExecutor;
public RedissonListMultimapCacheReactive(RedissonListMultimapCache<K, V> instance, CommandReactiveExecutor commandExecutor) {
this.instance = instance;
this.commandExecutor = commandExecutor;
}
public RListReactive<V> get(K key) {
RedissonList<V> list = (RedissonList<V>) instance.get(key);
return ReactiveProxyBuilder.create(commandExecutor, list, new RedissonListReactive<>(list), RListReactive.class);
}
}

@ -0,0 +1,47 @@
/**
* Copyright (c) 2013-2021 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 org.redisson.RedissonSet;
import org.redisson.RedissonSetMultimapCache;
import org.redisson.api.RSetReactive;
import org.redisson.api.RedissonReactiveClient;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public class RedissonSetMultimapCacheReactive<K, V> {
private final RedissonSetMultimapCache<K, V> instance;
private final CommandReactiveExecutor commandExecutor;
private final RedissonReactiveClient redisson;
public RedissonSetMultimapCacheReactive(RedissonSetMultimapCache<K, V> instance, CommandReactiveExecutor commandExecutor,
RedissonReactiveClient redisson) {
this.instance = instance;
this.redisson = redisson;
this.commandExecutor = commandExecutor;
}
public RSetReactive<V> get(K key) {
RedissonSet<V> set = (RedissonSet<V>) instance.get(key);
return ReactiveProxyBuilder.create(commandExecutor, set, new RedissonSetReactive<>(set, redisson), RSetReactive.class);
}
}
Loading…
Cancel
Save