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 ConnectionProvider |
connectionProvider |
protected JsonObjectMapper |
jsonObjectMapper
Deprecated.
This field is deprecated and should be set on JedisClientConfig instead.
|
protected CommandKeyArgumentPreProcessor |
keyPreProcessor
Deprecated.
This field is deprecated and should be set on JedisClientConfig instead.
|
protected org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> |
poolConfig |
protected int |
searchDialect
Deprecated.
This field is deprecated and should be set on JedisClientConfig instead.
|
| Constructor and Description |
|---|
AbstractClientBuilder() |
| Modifier and Type | Method and Description |
|---|---|
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 abstract ConnectionProvider |
createDefaultConnectionProvider()
Creates a default connection provider based on the current configuration.
|
T |
jsonObjectMapper(JsonObjectMapper jsonObjectMapper)
Deprecated.
use
DefaultJedisClientConfig.Builder#jsonObjectMapper(JsonObjectMapper) on
the JedisClientConfig passed via clientConfig(JedisClientConfig).
When this setter is used it is folded into the resulting client config at
build() time. |
T |
keyPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
Deprecated.
use
DefaultJedisClientConfig.Builder#commandKeyArgumentPreProcessor(CommandKeyArgumentPreProcessor)
on the JedisClientConfig passed via
clientConfig(JedisClientConfig). When this setter is used it is folded
into the resulting client config at build() time. |
T |
poolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> poolConfig)
Sets the connection pool configuration.
|
T |
searchDialect(int searchDialect)
Deprecated.
use
DefaultJedisClientConfig.Builder#searchDialect(int) on the
JedisClientConfig passed via clientConfig(JedisClientConfig). When
this setter is used it is folded into the resulting client config at
build() time. |
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 ConnectionProvider connectionProvider
@Deprecated protected CommandKeyArgumentPreProcessor keyPreProcessor
@Deprecated protected JsonObjectMapper jsonObjectMapper
@Deprecated 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()
keyPreProcessor, jsonObjectMapper,
searchDialect) are folded into the resulting config so the client constructor sees a
single source of truth.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 (RedisClient, RedisClusterClient, 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:
CommandObjects
construction via its factory hook.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 executor@Deprecated public T keyPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
DefaultJedisClientConfig.Builder#commandKeyArgumentPreProcessor(CommandKeyArgumentPreProcessor)
on the JedisClientConfig passed via
clientConfig(JedisClientConfig). When this setter is used it is folded
into the resulting client config at build() time.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 preprocessor@Deprecated public T jsonObjectMapper(JsonObjectMapper jsonObjectMapper)
DefaultJedisClientConfig.Builder#jsonObjectMapper(JsonObjectMapper) on
the JedisClientConfig passed via clientConfig(JedisClientConfig).
When this setter is used it is folded into the resulting client config at
build() time.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 mapper@Deprecated public T searchDialect(int searchDialect)
DefaultJedisClientConfig.Builder#searchDialect(int) on the
JedisClientConfig passed via clientConfig(JedisClientConfig). When
this setter is used it is folded into the resulting client config at
build() time.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)protected 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 © 2026. All rights reserved.