From 6ac6a1cc1db0a52c86b487496ae3a138d42b04ac Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 31 Jul 2015 13:15:52 +0200 Subject: [PATCH] Expose codec/uri methods on RedisClient #108 --- .../com/lambdaworks/redis/RedisClient.java | 41 ++++++++++++++++--- .../redis/RedisClusterAsyncConnection.java | 4 +- .../redis/RedisClusterConnection.java | 4 +- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/lambdaworks/redis/RedisClient.java b/src/main/java/com/lambdaworks/redis/RedisClient.java index 5058205468..b471c60026 100644 --- a/src/main/java/com/lambdaworks/redis/RedisClient.java +++ b/src/main/java/com/lambdaworks/redis/RedisClient.java @@ -227,7 +227,7 @@ public RedisConnection connect() { * Open a new synchronous connection to the 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 note be {@literal null} + * @param codec Use this codec to encode/decode keys and values, must not be {@literal null} * @param Key type. * @param Value type. * @return A new connection. @@ -255,9 +255,17 @@ private void checkValidRedisURI(RedisURI redisURI) { checkArgument(redisURI != null && isNotEmpty(redisURI.getHost()), "A valid RedisURI with a host is needed"); } - @SuppressWarnings({ "rawtypes" }) - private RedisConnection connect(RedisCodec codec, RedisURI redisURI) { - return (RedisConnection) syncHandler(connectAsync(codec, redisURI), RedisConnection.class, RedisClusterConnection.class); + /** + * Open a new synchronous connection to 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} + * @return A new connection. + */ + public RedisConnection connect(RedisCodec codec, RedisURI redisURI) { + return (RedisConnection) syncHandler((RedisChannelHandler) connectAsync(codec, redisURI), + RedisConnection.class, RedisClusterConnection.class); } /** @@ -295,7 +303,18 @@ public RedisAsyncConnection connectAsync(RedisURI redisURI) { return connectAsync(newStringStringCodec(), redisURI); } - private RedisAsyncConnectionImpl connectAsync(RedisCodec codec, RedisURI redisURI) { + /** + * Open a new asynchronous connection to 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} + * @return A new connection. + */ + public RedisAsyncConnection connectAsync(RedisCodec codec, RedisURI redisURI) { + checkArgument(codec != null, "RedisCodec must not be null"); + checkArgument(redisURI != null, "RedisURI must not be null"); + Queue> queue = new ArrayDeque>(); CommandHandler handler = new CommandHandler(clientOptions, queue); @@ -365,9 +384,19 @@ public RedisPubSubConnection connectPubSub(RedisCodec codec) return connectPubSub(codec, redisURI); } - protected RedisPubSubConnection connectPubSub(RedisCodec codec, RedisURI redisURI) { + /** + * Open a new pub/sub connection to 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} + * @return A new connection. + */ + public RedisPubSubConnection connectPubSub(RedisCodec codec, RedisURI redisURI) { checkArgument(codec != null, "RedisCodec must not be null"); + checkArgument(redisURI != null, "RedisURI must not be null"); Queue> queue = new ArrayDeque>(); PubSubCommandHandler handler = new PubSubCommandHandler(clientOptions, queue, codec); RedisPubSubConnectionImpl connection = newRedisPubSubConnectionImpl(handler, codec, timeout, unit); diff --git a/src/main/java/com/lambdaworks/redis/RedisClusterAsyncConnection.java b/src/main/java/com/lambdaworks/redis/RedisClusterAsyncConnection.java index 8b17af7883..ae2b54aee1 100644 --- a/src/main/java/com/lambdaworks/redis/RedisClusterAsyncConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisClusterAsyncConnection.java @@ -139,7 +139,9 @@ public interface RedisClusterAsyncConnection extends RedisHashesAsyncConne RedisFuture> clusterSlots(); /** - * + * The asking command is required after a {@code -ASK} redirection. The client should issue {@code ASKING} before to actually send the + * command to the target instance. See the Redis Cluster specification for more information. + * * @return String simple-string-reply */ RedisFuture asking(); diff --git a/src/main/java/com/lambdaworks/redis/RedisClusterConnection.java b/src/main/java/com/lambdaworks/redis/RedisClusterConnection.java index 33e4320293..64be4caa22 100644 --- a/src/main/java/com/lambdaworks/redis/RedisClusterConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisClusterConnection.java @@ -138,7 +138,9 @@ public interface RedisClusterConnection extends RedisHashesConnection clusterSlots(); /** - * + * The asking command is required after a {@code -ASK} redirection. The client should issue {@code ASKING} before to actually send the + * command to the target instance. See the Redis Cluster specification for more information. + * * @return String simple-string-reply */ String asking();