Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAREDIS-667 - Introduce LettuceConnectionProvider.
We now create and release Lettuce connections using LettuceConnectionProvider. Connection providers encapsulate the underlying client and expose only creation and release methods. A connection provider can provide connections for Standalone or Cluster connections or wrap a LettucePool. Previously we used RedisClient and RedisClusterClient directly which required context propagation (pooling/non-pooling) conditional code to obtain the appropriate connection type. Original Pull Request: #262
- Loading branch information
1 parent
5c37948
commit 5ac7f8e
Showing
11 changed files
with
546 additions
and
175 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...ain/java/org/springframework/data/redis/connection/lettuce/ClusterConnectionProvider.java
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* 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.springframework.data.redis.connection.lettuce; | ||
|
||
import io.lettuce.core.api.StatefulConnection; | ||
import io.lettuce.core.cluster.RedisClusterClient; | ||
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; | ||
import io.lettuce.core.codec.RedisCodec; | ||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; | ||
|
||
/** | ||
* Connection provider for Cluster connections. | ||
* | ||
* @author Mark Paluch | ||
* @since 2.0 | ||
*/ | ||
class ClusterConnectionProvider implements LettuceConnectionProvider { | ||
|
||
private final RedisClusterClient client; | ||
private final RedisCodec<?, ?> codec; | ||
|
||
ClusterConnectionProvider(RedisClusterClient client, RedisCodec<?, ?> codec) { | ||
|
||
this.client = client; | ||
this.codec = codec; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.redis.connection.lettuce.LettuceConnectionProvider#getConnection(java.lang.Class) | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public StatefulConnection<?, ?> getConnection(Class<? extends StatefulConnection> connectionType) { | ||
|
||
if (connectionType.equals(StatefulRedisPubSubConnection.class)) { | ||
return client.connectPubSub(codec); | ||
} | ||
|
||
if (StatefulRedisClusterConnection.class.isAssignableFrom(connectionType) | ||
|| connectionType.equals(StatefulConnection.class)) { | ||
return client.connect(codec); | ||
} | ||
|
||
throw new UnsupportedOperationException("Connection type " + connectionType + " not supported!"); | ||
} | ||
|
||
public RedisClusterClient getClient() { | ||
return client; | ||
} | ||
} |
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.