public class TokenBasedRedisCredentialsProvider extends Object implements RedisCredentialsProvider, AutoCloseable
RedisCredentialsProvider implementation that supports token-based authentication for Redis.
This provider uses a TokenManager to manage and renew tokens, ensuring that the Redis client can authenticate with
Redis using a dynamically updated token. This is particularly useful in scenarios where Redis access is controlled via
token-based authentication, such as when Redis is integrated with an identity provider like EntraID.
The provider supports streaming of credentials and automatically emits new credentials whenever a token is renewed. It must
be used with ClientOptions.ReauthenticateBehavior.ON_NEW_CREDENTIALS to automatically re-authenticate
connections whenever new tokens are emitted by the provider.
The lifecycle of this provider is externally managed. It should be closed when there are no longer any connections using it, to stop the token management process and release resources.
RedisCredentialsProvider.ImmediateRedisCredentialsProvider| Modifier and Type | Method and Description |
|---|---|
void |
close()
Stop the credentials provider and clean up resources.
|
static TokenBasedRedisCredentialsProvider |
create(redis.clients.authentication.core.TokenAuthConfig tokenAuthConfig) |
static TokenBasedRedisCredentialsProvider |
create(redis.clients.authentication.core.TokenManager tokenManager) |
Flux<RedisCredentials> |
credentials()
Expose the Flux for all credential updates.
|
Mono<RedisCredentials> |
resolveCredentials()
Resolve the latest available credentials as a Mono.
|
boolean |
supportsStreaming()
Some implementations of the
RedisCredentialsProvider may support streaming new credentials, based on some event
that originates outside the driver. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfrompublic Mono<RedisCredentials> resolveCredentials()
This method returns a Mono that emits the most recent set of Redis credentials. The Mono will complete once the credentials are emitted. If no credentials are available at the time of subscription, the Mono will wait until credentials are available.
resolveCredentials in interface RedisCredentialsProviderpublic Flux<RedisCredentials> credentials()
This method returns a Flux that emits all updates to the Redis credentials. Subscribers will receive the latest credentials whenever they are updated. The Flux will continue to emit updates until the provider is shut down.
credentials in interface RedisCredentialsProviderpublic boolean supportsStreaming()
RedisCredentialsProviderRedisCredentialsProvider may support streaming new credentials, based on some event
that originates outside the driver. In this case they should indicate that so the RedisAuthenticationHandler is
able to process these new credentials.supportsStreaming in interface RedisCredentialsProviderRedisCredentialsProvider supports streaming credentials.public void close()
This method stops the TokenManager and completes the credentials sink, ensuring that all resources are properly released. It should be called when the credentials provider is no longer needed.
close in interface AutoCloseablepublic static TokenBasedRedisCredentialsProvider create(redis.clients.authentication.core.TokenAuthConfig tokenAuthConfig)
public static TokenBasedRedisCredentialsProvider create(redis.clients.authentication.core.TokenManager tokenManager)
Copyright © 2025 lettuce.io. All rights reserved.