Skip to content

Commit

Permalink
Expose codec/uri methods on RedisClient #108
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jul 31, 2015
1 parent 297445c commit 6ac6a1c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
41 changes: 35 additions & 6 deletions src/main/java/com/lambdaworks/redis/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ 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.
*
* @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 <K> Key type.
* @param <V> Value type.
* @return A new connection.
Expand Down Expand Up @@ -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 <K, V> RedisConnection connect(RedisCodec<K, V> 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 <K, V> RedisConnection connect(RedisCodec<K, V> codec, RedisURI redisURI) {
return (RedisConnection<K, V>) syncHandler((RedisChannelHandler<K, V>) connectAsync(codec, redisURI),
RedisConnection.class, RedisClusterConnection.class);
}

/**
Expand Down Expand Up @@ -295,7 +303,18 @@ public RedisAsyncConnection<String, String> connectAsync(RedisURI redisURI) {
return connectAsync(newStringStringCodec(), redisURI);
}

private <K, V> RedisAsyncConnectionImpl<K, V> connectAsync(RedisCodec<K, V> 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 <K, V> RedisAsyncConnection<K, V> connectAsync(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, ?>>();

CommandHandler<K, V> handler = new CommandHandler<K, V>(clientOptions, queue);
Expand Down Expand Up @@ -365,9 +384,19 @@ public <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec)
return connectPubSub(codec, redisURI);
}

protected <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> 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 <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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public interface RedisClusterAsyncConnection<K, V> extends RedisHashesAsyncConne
RedisFuture<List<Object>> 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<String> asking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public interface RedisClusterConnection<K, V> extends RedisHashesConnection<K, V
List<Object> 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();
Expand Down

0 comments on commit 6ac6a1c

Please sign in to comment.