-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose codec/uri methods on RedisClient #108
- Loading branch information
Showing
3 changed files
with
222 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ | |
import com.lambdaworks.redis.pubsub.RedisPubSubConnectionImpl; | ||
|
||
/** | ||
* A scalable thread-safe <a href="http://redis.io/">Redis</a> client. Multiple threads may share one connection provided they | ||
* avoid blocking and transactional operations such as BLPOP and MULTI/EXEC. | ||
* | ||
* A scalable thread-safe <a href="http://redis.io/">Redis</a> client. Multiple threads may share one connection if they avoid | ||
* blocking and transactional operations such as BLPOP and MULTI/EXEC. | ||
* | ||
* @author Will Glozer | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
*/ | ||
|
@@ -33,7 +33,7 @@ public class RedisClient extends AbstractRedisClient { | |
private final RedisURI redisURI; | ||
|
||
/** | ||
* Creates a uri-less RedisClient. You can connect to different redis servers but you must supply a {@link RedisURI} on | ||
* Creates a uri-less RedisClient. You can connect to different Redis servers but you must supply a {@link RedisURI} on | ||
* connecting. Methods without having a {@link RedisURI} will fail with a {@link java.lang.IllegalStateException}. | ||
*/ | ||
public RedisClient() { | ||
|
@@ -103,8 +103,8 @@ public RedisConnectionPool<RedisConnection<String, String>> pool(int maxIdle, in | |
* @param codec the codec to use | ||
* @param maxIdle max idle connections in pool | ||
* @param maxActive max active connections in pool | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return a new {@link RedisConnectionPool} instance | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
|
@@ -178,8 +178,8 @@ public RedisConnectionPool<RedisAsyncConnection<String, String>> asyncPool(int m | |
* @param codec the codec to use | ||
* @param maxIdle max idle connections in pool | ||
* @param maxActive max active connections in pool | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return a new {@link RedisConnectionPool} instance | ||
*/ | ||
public <K, V> RedisConnectionPool<RedisAsyncConnection<K, V>> asyncPool(final RedisCodec<K, V> codec, int maxIdle, | ||
|
@@ -214,7 +214,7 @@ public void resourceClosed(Object resource) { | |
} | ||
|
||
/** | ||
* Open a new synchronous connection to the redis server that treats keys and values as UTF-8 strings. | ||
* Open a connection to a Redis server that treats keys and values as UTF-8 strings. | ||
* | ||
* @return A new connection. | ||
*/ | ||
|
@@ -224,25 +224,24 @@ public RedisConnection<String, String> connect() { | |
} | ||
|
||
/** | ||
* Open a new synchronous connection to the redis server. Use the supplied {@link RedisCodec codec} to encode/decode keys | ||
* and values. | ||
* Open a new synchronous connection to a Redis server. Use the supplied {@link RedisCodec codec} to encode/decode keys and | ||
* values. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @return A new connection. | ||
* @param codec Use this codec to encode/decode keys and values, must note be {@literal null} | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new Redis connection. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <K, V> RedisConnection<K, V> connect(RedisCodec<K, V> codec) { | ||
checkForRedisURI(); | ||
checkArgument(codec != null, "RedisCodec must not be null"); | ||
return connect(codec, this.redisURI); | ||
} | ||
|
||
/** | ||
* Open a new synchronous connection to the supplied {@link RedisURI} that treats keys and values as UTF-8 strings. | ||
* Open a new synchronous to a Redis server using the supplied {@link RedisURI} that treats keys and values as UTF-8 | ||
* strings. | ||
* | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @return A new connection. | ||
*/ | ||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
|
@@ -256,11 +255,13 @@ private void checkValidRedisURI(RedisURI redisURI) { | |
} | ||
|
||
/** | ||
* Open a new synchronous connection to the supplied {@link RedisURI} and the supplied {@link RedisCodec codec} to | ||
* encode/decode keys. | ||
* Open a new synchronous connection to a Redis server using the supplied {@link RedisURI} and the supplied | ||
* {@link RedisCodec codec} to encode/decode keys. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new connection. | ||
*/ | ||
public <K, V> RedisConnection connect(RedisCodec<K, V> codec, RedisURI redisURI) { | ||
|
@@ -269,7 +270,7 @@ public <K, V> RedisConnection connect(RedisCodec<K, V> codec, RedisURI redisURI) | |
} | ||
|
||
/** | ||
* Open a new asynchronous connection to the redis server that treats keys and values as UTF-8 strings. | ||
* Open a new asynchronous connection to a Redis server that treats keys and values as UTF-8 strings. | ||
* | ||
* @return A new connection. | ||
*/ | ||
|
@@ -278,24 +279,24 @@ public RedisAsyncConnection<String, String> connectAsync() { | |
} | ||
|
||
/** | ||
* Open a new asynchronous connection to the redis server. Use the supplied {@link RedisCodec codec} to encode/decode keys | ||
* and values. | ||
* Open a new asynchronous connection to a Redis server. Use the supplied {@link RedisCodec codec} to encode/decode keys and | ||
* values. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new connection. | ||
*/ | ||
public <K, V> RedisAsyncConnection<K, V> connectAsync(RedisCodec<K, V> codec) { | ||
checkForRedisURI(); | ||
checkArgument(codec != null, "RedisCodec must not be null"); | ||
return connectAsync(codec, redisURI); | ||
} | ||
|
||
/** | ||
* Open a new asynchronous connection to the supplied {@link RedisURI} that treats keys and values as UTF-8 strings. | ||
* Open a new asynchronous connection to a Redis server using the supplied {@link RedisURI} that treats keys and values as | ||
* UTF-8 strings. | ||
* | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @return A new connection. | ||
*/ | ||
public RedisAsyncConnection<String, String> connectAsync(RedisURI redisURI) { | ||
|
@@ -304,11 +305,13 @@ public RedisAsyncConnection<String, String> connectAsync(RedisURI redisURI) { | |
} | ||
|
||
/** | ||
* Open a new asynchronous connection to the supplied {@link RedisURI} and the supplied {@link RedisCodec codec} to | ||
* encode/decode keys. | ||
* Open a new asynchronous connection to a Redis server using the supplied {@link RedisURI} and the supplied | ||
* {@link RedisCodec codec} to encode/decode keys. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new connection. | ||
*/ | ||
public <K, V> RedisAsyncConnection<K, V> connectAsync(RedisCodec<K, V> codec, RedisURI redisURI) { | ||
|
@@ -351,52 +354,54 @@ private <K, V> void connectAsync(CommandHandler<K, V> handler, RedisAsyncConnect | |
} | ||
|
||
/** | ||
* Open a new pub/sub connection to the redis server that treats keys and values as UTF-8 strings. | ||
* Open a new pub/sub connection to the Redis server that treats keys and values as UTF-8 strings. | ||
* | ||
* @return A new connection. | ||
* @return A new connection | ||
*/ | ||
public RedisPubSubConnection<String, String> connectPubSub() { | ||
return connectPubSub(newStringStringCodec()); | ||
} | ||
|
||
/** | ||
* Open a new pub/sub connection to the supplied {@link RedisURI} that treats keys and values as UTF-8 strings. | ||
* Open a new pub/sub connection to the Redis server using the supplied {@link RedisURI} that treats keys and values as | ||
* UTF-8 strings. | ||
* | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @return A new connection. | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @return A new pub/sub connection | ||
*/ | ||
public RedisPubSubConnection<String, String> connectPubSub(RedisURI redisURI) { | ||
checkValidRedisURI(redisURI); | ||
return connectPubSub(newStringStringCodec(), redisURI); | ||
} | ||
|
||
/** | ||
* Open a new pub/sub connection to the redis server. Use the supplied {@link RedisCodec codec} to encode/decode keys and | ||
* values. | ||
* Open a new pub/sub connection to the Redis server using the supplied {@link RedisURI} and use the supplied | ||
* {@link RedisCodec codec} to encode/decode keys and values. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @return A new pub/sub connection. | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new pub/sub connection | ||
*/ | ||
public <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) { | ||
checkForRedisURI(); | ||
return connectPubSub(codec, redisURI); | ||
} | ||
|
||
/** | ||
* Open a new pub/sub connection to the supplied {@link RedisURI} and the supplied {@link RedisCodec codec} to encode/decode | ||
* keys. | ||
* | ||
* Open a new pub/sub connection to the Redis server using the supplied {@link RedisURI} and use the supplied | ||
* {@link RedisCodec codec} to encode/decode keys and values. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new connection. | ||
*/ | ||
public <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec, RedisURI redisURI) { | ||
|
||
checkArgument(codec != null, "RedisCodec must not be null"); | ||
checkArgument(redisURI != null, "RedisURI must not be null"); | ||
|
||
Queue<RedisCommand<K, V, ?>> queue = new ArrayDeque<RedisCommand<K, V, ?>>(); | ||
PubSubCommandHandler<K, V> handler = new PubSubCommandHandler<K, V>(clientOptions, queue, codec); | ||
RedisPubSubConnectionImpl<K, V> connection = newRedisPubSubConnectionImpl(handler, codec, timeout, unit); | ||
|
@@ -407,7 +412,8 @@ public <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec, | |
} | ||
|
||
/** | ||
* Creates an asynchronous connection to Sentinel. You must supply a valid RedisURI containing one or more sentinels. | ||
* Creates an asynchronous connection to Redis Sentinel that treats keys and values as UTF-8 strings. You must supply a | ||
* valid RedisURI containing one or more sentinels. | ||
* | ||
* @return a new connection. | ||
*/ | ||
|
@@ -416,31 +422,50 @@ public RedisSentinelAsyncConnection<String, String> connectSentinelAsync() { | |
} | ||
|
||
/** | ||
* Creates an asynchronous connection to Sentinel. You must supply a valid RedisURI containing one or more sentinels. | ||
* Creates an asynchronous connection to Redis Sentinela nd use the supplied {@link RedisCodec codec} to encode/decode keys | ||
* and values. You must supply a valid RedisURI containing one or more sentinels. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return a new connection. | ||
*/ | ||
public <K, V> RedisSentinelAsyncConnection<K, V> connectSentinelAsync(RedisCodec<K, V> codec) { | ||
checkForRedisURI(); | ||
checkArgument(codec != null, "RedisCodec must not be null"); | ||
return connectSentinelAsyncImpl(codec, redisURI); | ||
} | ||
|
||
/** | ||
* Creates an asynchronous connection to Sentinel. You must supply a valid RedisURI containing a redis host or one or more | ||
* sentinels. | ||
* Creates an asynchronous connection to Redis Sentinel using the supplied {@link RedisURI} that treats keys and values as | ||
* UTF-8 strings. You must supply a valid RedisURI containing a redis host or one or more sentinels. | ||
* | ||
* @param redisURI the redis server to connect to, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @return A new connection. | ||
*/ | ||
public RedisSentinelAsyncConnection<String, String> connectSentinelAsync(RedisURI redisURI) { | ||
return connectSentinelAsyncImpl(newStringStringCodec(), redisURI); | ||
} | ||
|
||
/** | ||
* Creates an asynchronous connection to Redis Sentinel using the supplied {@link RedisURI} and use the supplied | ||
* {@link RedisCodec codec} to encode/decode keys and values. You must supply a valid RedisURI containing a redis host or | ||
* one or more sentinels. | ||
* | ||
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null} | ||
* @param redisURI the Redis server to connect to, must not be {@literal null} | ||
* @param <K> Key type | ||
* @param <V> Value type | ||
* @return A new connection. | ||
*/ | ||
public <K, V> RedisSentinelAsyncConnection<K, V> connectSentinelAsync(RedisCodec<K, V> codec, RedisURI redisURI) { | ||
return connectSentinelAsyncImpl(codec, redisURI); | ||
} | ||
|
||
private <K, V> RedisSentinelAsyncConnection<K, V> connectSentinelAsyncImpl(RedisCodec<K, V> codec, RedisURI redisURI) { | ||
|
||
checkArgument(codec != null, "RedisCodec must not be null"); | ||
checkArgument(redisURI != null, "RedisURI must not be null"); | ||
|
||
Queue<RedisCommand<K, V, ?>> queue = new ArrayDeque<RedisCommand<K, V, ?>>(); | ||
|
||
ConnectionBuilder connectionBuilder = ConnectionBuilder.connectionBuilder(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.