T - the concrete builder type for method chainingC - the client type that this builder createspublic abstract class AbstractClientBuilder<T extends AbstractClientBuilder<T,C>,C>
extends java.lang.Object
This class contains shared configuration fields and methods that are common across different Redis client builders (RedisClient.Builder, RedisSentinelClient.Builder, etc.). It helps eliminate code duplication and provides a consistent API for common features.
Common features provided:
| Modifier and Type | Field and Description |
|---|---|
protected Cache |
cache |
protected CacheConfig |
cacheConfig |
protected JedisClientConfig |
clientConfig |
protected CommandExecutor |
commandExecutor |
protected CommandObjects |
commandObjects |
protected ConnectionProvider |
connectionProvider |
protected JsonObjectMapper |
jsonObjectMapper |
protected CommandKeyArgumentPreProcessor |
keyPreProcessor |
protected org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> |
poolConfig |
protected int |
searchDialect |
| Constructor and Description |
|---|
AbstractClientBuilder() |
| Modifier and Type | Method and Description |
|---|---|
void |
applyCommandObjectsConfiguration(CommandObjects commandObjects)
Applies common configuration to the CommandObjects instance.
|
C |
build()
Builds the Redis client instance using the common build pattern.
|
T |
cache(Cache cache)
Sets the client-side cache for caching Redis responses.
|
T |
cacheConfig(CacheConfig cacheConfig)
Sets the cache configuration for client-side caching.
|
T |
clientConfig(JedisClientConfig clientConfig)
Sets the client configuration for Redis connections.
|
T |
commandExecutor(CommandExecutor commandExecutor)
Sets a custom command executor for executing Redis commands.
|
T |
connectionProvider(ConnectionProvider connectionProvider)
Sets a custom connection provider.
|
protected abstract C |
createClient()
Creates the specific client instance with the provided components.
|
protected JedisClientConfig |
createDefaultClientConfig()
Creates a default client configuration based on the current configuration.
|
protected CommandExecutor |
createDefaultCommandExecutor()
Creates a default command executor based on the current configuration.
|
protected CommandObjects |
createDefaultCommandObjects()
Factory method for creating CommandObjects.
|
protected abstract ConnectionProvider |
createDefaultConnectionProvider()
Creates a default connection provider based on the current configuration.
|
T |
jsonObjectMapper(JsonObjectMapper jsonObjectMapper)
Sets a custom JSON object mapper for JSON operations.
|
T |
keyPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
Sets a key preprocessor for transforming Redis keys before sending commands.
|
T |
poolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
Sets the connection pool configuration.
|
T |
searchDialect(int searchDialect)
Sets the default search dialect for RediSearch operations.
|
protected abstract T |
self()
Returns the concrete builder instance for method chaining.
|
protected void |
validateCommonConfiguration()
Validates common configuration parameters.
|
protected abstract void |
validateSpecificConfiguration()
Validates the builder-specific configuration.
|
protected org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig
protected Cache cache
protected CacheConfig cacheConfig
protected CommandExecutor commandExecutor
protected CommandObjects commandObjects
protected ConnectionProvider connectionProvider
protected CommandKeyArgumentPreProcessor keyPreProcessor
protected JsonObjectMapper jsonObjectMapper
protected int searchDialect
protected JedisClientConfig clientConfig
public T clientConfig(JedisClientConfig clientConfig)
The client configuration includes authentication, timeouts, SSL settings, and other connection-specific parameters.
clientConfig - the client configurationprotected abstract T self()
protected abstract ConnectionProvider createDefaultConnectionProvider()
protected CommandExecutor createDefaultCommandExecutor()
protected JedisClientConfig createDefaultClientConfig()
protected CommandObjects createDefaultCommandObjects()
protected abstract C createClient()
This method is called by the generic build() method to instantiate the concrete client type. Each builder implementation should create their specific client type (JedisPooled, JedisCluster, etc.) using the parameters provided to the builder.
protected abstract void validateSpecificConfiguration()
This method is called by the generic build() method to validate configuration specific to each builder type. Implementations should call validateCommonConfiguration() and then perform their own specific validation.
java.lang.IllegalArgumentException - if the configuration is invalidpublic C build()
This method implements the common build pattern shared across all builder types:
public T poolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
The pool configuration controls how connections are managed, including maximum number of connections, idle timeout, and other pooling parameters.
poolConfig - the pool configurationpublic T cache(Cache cache)
Client-side caching can improve performance by storing frequently accessed data locally, reducing the number of round trips to the Redis server.
cache - the cache instancepublic T cacheConfig(CacheConfig cacheConfig)
Client-side caching can improve performance by storing frequently accessed data locally. The cache will be created from this configuration during the build process.
cacheConfig - the cache configurationpublic T connectionProvider(ConnectionProvider connectionProvider)
When a custom connection provider is set, other connection-related configuration may be ignored as the provider is responsible for managing connections. The specific behavior depends on the concrete builder implementation.
connectionProvider - the connection providerpublic T commandExecutor(CommandExecutor commandExecutor)
The command executor is responsible for sending commands to Redis and processing the responses.
commandExecutor - the command executorpublic T keyPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
The key preprocessor allows you to modify keys before they are sent to Redis, for example to add prefixes, apply transformations, or implement key routing logic.
Example usage:
CommandKeyArgumentPreProcessor keyProcessor = key -> "myapp:" + key;
builder.keyPreProcessor(keyProcessor);
keyPreProcessor - the key preprocessorpublic T jsonObjectMapper(JsonObjectMapper jsonObjectMapper)
The JSON object mapper is used for serializing and deserializing objects in JSON commands (RedisJSON module). If not set, a default Gson-based mapper will be used.
Example usage:
{
@code
JsonObjectMapper customMapper = new MyCustomJsonMapper();
builder.jsonObjectMapper(customMapper);
}
jsonObjectMapper - the JSON object mapperpublic T searchDialect(int searchDialect)
The search dialect determines the query syntax and features available for RediSearch commands. Different dialects support different query features and syntax variations.
Default is 2.
searchDialect - the search dialect versionjava.lang.IllegalArgumentException - if dialect is 0 (not allowed)public void applyCommandObjectsConfiguration(CommandObjects commandObjects)
This method is called by concrete builders to configure the CommandObjects with the common settings like key preprocessor, JSON mapper, and search dialect.
commandObjects - the CommandObjects instance to configureprotected void validateCommonConfiguration()
This method can be called by concrete builders to validate the common configuration before building the client.
java.lang.IllegalArgumentException - if any common configuration is invalidCopyright © 2025. All rights reserved.