com.github.lontime.extredisson.provider.RedissonProvider Maven / Gradle / Ivy
The newest version!
package com.github.lontime.extredisson.provider;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.github.lontime.extredisson.codec.StringBytesMapCodec;
import com.github.lontime.shaded.org.redisson.api.BatchOptions;
import com.github.lontime.shaded.org.redisson.api.MapOptions;
import com.github.lontime.shaded.org.redisson.api.RBatch;
import com.github.lontime.shaded.org.redisson.api.RBlockingQueue;
import com.github.lontime.shaded.org.redisson.api.RBucket;
import com.github.lontime.shaded.org.redisson.api.RList;
import com.github.lontime.shaded.org.redisson.api.RLock;
import com.github.lontime.shaded.org.redisson.api.RMap;
import com.github.lontime.shaded.org.redisson.api.RMapCache;
import com.github.lontime.shaded.org.redisson.api.RScoredSortedSet;
import com.github.lontime.shaded.org.redisson.api.RScript;
import com.github.lontime.shaded.org.redisson.api.RStream;
import com.github.lontime.shaded.org.redisson.api.RedissonClient;
import com.github.lontime.shaded.org.redisson.client.codec.Codec;
import static com.github.lontime.base.commonj.constants.Consts.DEFAULT_OBJECT_NAME;
/**
* RedissonProvider.
* @author lontime
* @since 1.0
*/
public interface RedissonProvider {
/**
* resolve.
* @param name name
* @return name
*/
String resolve(String name);
/**
* resolveConnectionName.
* @param name name
* @return actual name
*/
default String resolveConnectionName(String name) {
if (name == null || name.isEmpty()) {
return DEFAULT_OBJECT_NAME;
}
return resolveConnectionName(Collections.singletonList(name));
}
/**
* resolveConnectionName.
* @param name1 name1
* @param name2 name2
* @return name
*/
default String resolveConnectionName(String name1, String name2) {
return resolveConnectionName(Arrays.asList(name1, name2));
}
/**
* resolveConnectionName.
* @param names names
* @return name
*/
String resolveConnectionName(List names);
/**
* getClient.
* @return Redisson client
*/
default RedissonClient client() {
return client(DEFAULT_OBJECT_NAME);
}
/**
* getClient.
* @param name name
* @return Redisson client
*/
default RedissonClient client(String name) {
return client(Collections.singletonList(name));
}
/**
* getClient.
* @param name1 name
* @param name2 name2
* @return Redisson client
*/
default RedissonClient client(String name1, String name2) {
return client(Arrays.asList(name1, name2));
}
/**
* client.
* @param names names
* @return Redisson client
*/
RedissonClient client(List names);
/**
* directClient.
* @param name name
* @return Redisson client
*/
RedissonClient directClient(String name);
/**
* getBucket.
* @param name name
* @param V
* @return RBucketReactive
*/
default RBucket getBucket(String name) {
return getBucket(name, null);
}
/**
* getBucket.
* @param name name
* @param codec codec
* @param V
* @return RBucketReactive
*/
default RBucket getBucket(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getBucket(actualName);
}
return client(name).getBucket(actualName, codec);
}
/**
* getScoredSortedSet.
* @param name name
* @param V
* @return RBucketReactive
*/
default RScoredSortedSet getScoredSortedSet(String name) {
return getScoredSortedSet(name, null);
}
/**
* getScoredSortedSet.
* @param name name
* @param codec codec
* @param V
* @return RBucketReactive
*/
default RScoredSortedSet getScoredSortedSet(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getScoredSortedSet(actualName);
}
return client(name).getScoredSortedSet(actualName, codec);
}
/**
* getMap.
* @param name name
* @param V
* @param K
* @return RBucketReactive
*/
default RMap getMap(String name) {
return getMap(name, (Codec) null);
}
/**
* getMap.
* @param name name
* @param codec codec
* @param V
* @param K
* @return RBucketReactive
*/
default RMap getMap(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getMap(actualName);
}
return client(name).getMap(actualName, codec);
}
/**
* getMap.
* @param name name
* @param options options
* @param V
* @param K
* @return RBucketReactive
*/
default RMap getMap(String name, MapOptions options) {
return getMap(name, null, options);
}
/**
* getMap.
* @param name name
* @param codec codec
* @param options options
* @param V
* @param K
* @return RBucketReactive
*/
default RMap getMap(String name, Codec codec, MapOptions options) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getMap(actualName, options);
}
return client(name).getMap(actualName, codec, options);
}
/**
* getMapCache.
* @param name name
* @param V
* @param K
* @return RBucketReactive
*/
default RMapCache getMapCache(String name) {
return getMapCache(name, (Codec) null);
}
/**
* getMapCache.
* @param name name
* @param codec codec
* @param V
* @param K
* @return RBucketReactive
*/
default RMapCache getMapCache(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getMapCache(actualName);
}
return client(name).getMapCache(actualName, codec);
}
/**
* getMapCache.
* @param name name
* @param V
* @param K
* @param options options
* @return RBucketReactive
*/
default RMapCache getMapCache(String name, MapOptions options) {
return getMapCache(name, null, options);
}
/**
* getMapCache.
* @param name name
* @param codec codec
* @param options options
* @param V
* @param K
* @return RBucketReactive
*/
default RMapCache getMapCache(String name, Codec codec, MapOptions options) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getMapCache(actualName, options);
}
return client(name).getMapCache(actualName, codec, options);
}
/**
* getList.
* @param name name
* @param V
* @return RBucketReactive
*/
default RList getList(String name) {
return getList(name, null);
}
/**
* getList.
* @param name name
* @param codec codec
* @param V
* @return RBucketReactive
*/
default RList getList(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getList(actualName);
}
return client(name).getList(actualName, codec);
}
/**
* getScript.
* @param name name
* @return RBucketReactive
*/
default RScript getScript(String name) {
return getScript(name, null);
}
/**
* getScript.
* @param name name
* @param codec codec
* @return RBucketReactive
*/
default RScript getScript(String name, Codec codec) {
if (codec == null) {
return client(name).getScript();
}
return client(name).getScript(codec);
}
/**
* getLock.
* @param name name
* @return getLock
*/
default RLock getLock(String name) {
final String actualName = resolve(name);
return client(name).getLock(actualName);
}
/**
* getStream.
* @param name name
* @param V
* @param K
* @return RBucketReactive
*/
default RStream getStream(String name) {
return getStream(name, null);
}
/**
* getStream.
* @param name name
* @param V
* @param K
* @return RBucketReactive
*/
default RStream getBytesStream(String name) {
return getStream(name, StringBytesMapCodec.INSTANCE);
}
/**
* getStream.
* @param name name
* @param codec codec
* @param V
* @param K
* @return RBucketReactive
*/
default RStream getStream(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getStream(actualName);
}
return client(name).getStream(actualName, codec);
}
/**
* createBatch.
* @param name name
* @return createBatch
*/
default RBatch createBatch(String name) {
return createBatch(name, null);
}
/**
* createBatch.
* @param name name
* @param options options
* @return createBatch
*/
default RBatch createBatch(String name, BatchOptions options) {
if (options == null) {
return client(name).createBatch();
}
return client(name).createBatch(options);
}
/**
* getBlockingQueue.
* @param name name
* @param V
* @return RBlockingQueue
*/
default RBlockingQueue getBlockingQueue(String name) {
return getBlockingQueue(name, null);
}
/**
* getBlockingQueue.
* @param name name
* @param codec codec
* @param V
* @return RBlockingQueue
*/
default RBlockingQueue getBlockingQueue(String name, Codec codec) {
final String actualName = resolve(name);
if (codec == null) {
return client(name).getBlockingQueue(actualName);
}
return client(name).getBlockingQueue(actualName, codec);
}
}