Jedis is a blazingly small and sane Redis java client.
Jedis provides comprehensive authentication support including traditional Redis AUTH, Redis ACL, and advanced token-based authentication with AuthX integration.
Core authentication management for token-based authentication systems.
/**
* Manager for AuthX token-based authentication
*/
public class AuthXManager {
/**
* Create authentication manager with credentials provider
* @param credentialsProvider Provider for credentials
*/
public AuthXManager(RedisCredentialsProvider credentialsProvider);
/**
* Authenticate a connection
* @param connection Connection to authenticate
* @throws JedisAuthenticationException if authentication fails
*/
public void authenticate(Connection connection);
/**
* Refresh authentication token
* @throws JedisAuthenticationException if refresh fails
*/
public void refreshToken();
/**
* Check if token needs refresh
* @return true if token should be refreshed
*/
public boolean shouldRefreshToken();
/**
* Get current token expiration time
* @return Expiration timestamp in milliseconds
*/
public long getTokenExpiration();
}Implementation of RedisCredentials for token-based authentication.
/**
* Token-based credentials implementation
*/
public class TokenCredentials implements RedisCredentials {
/**
* Create token credentials
* @param token Authentication token
*/
public TokenCredentials(String token);
/**
* Get the authentication token
* @return Authentication token
*/
public String getToken();
/**
* Get user name (may be null for token auth)
* @return User name or null
*/
public String getUser();
/**
* Get password (returns token)
* @return Authentication token
*/
public String getPassword();
}Exception thrown for authentication-related errors.
/**
* Exception for authentication failures
*/
public class JedisAuthenticationException extends JedisException {
/**
* Create authentication exception
* @param message Error message
*/
public JedisAuthenticationException(String message);
/**
* Create authentication exception with cause
* @param message Error message
* @param cause Underlying cause
*/
public JedisAuthenticationException(String message, Throwable cause);
}Interface for handling authentication events.
/**
* Listener for authentication events
*/
public interface AuthXEventListener {
/**
* Called when authentication succeeds
* @param connection Authenticated connection
*/
void onAuthenticationSuccess(Connection connection);
/**
* Called when authentication fails
* @param connection Connection that failed
* @param exception Authentication exception
*/
void onAuthenticationFailure(Connection connection, JedisAuthenticationException exception);
/**
* Called when token is refreshed
* @param newToken New authentication token
*/
void onTokenRefresh(String newToken);
}import redis.clients.jedis.*;
// Traditional AUTH with password
Jedis jedis = new Jedis("localhost", 6379,
DefaultJedisClientConfig.builder()
.password("mypassword")
.build());
// Redis ACL with username and password
Jedis jedis = new Jedis("localhost", 6379,
DefaultJedisClientConfig.builder()
.user("myuser")
.password("mypassword")
.build());import redis.clients.jedis.authentication.*;
// Create token credentials
TokenCredentials tokenCreds = new TokenCredentials("jwt_token_here");
// Create credentials provider
RedisCredentialsProvider provider = new DefaultRedisCredentialsProvider(tokenCreds);
// Create authentication manager
AuthXManager authManager = new AuthXManager(provider);
// Use with Jedis client
JedisClientConfig config = DefaultJedisClientConfig.builder()
.credentialsProvider(provider)
.build();
Jedis jedis = new Jedis("localhost", 6379, config);import redis.clients.jedis.authentication.*;
// Create event listener
AuthXEventListener listener = new AuthXEventListener() {
@Override
public void onAuthenticationSuccess(Connection connection) {
System.out.println("Authentication successful");
}
@Override
public void onAuthenticationFailure(Connection connection, JedisAuthenticationException exception) {
System.err.println("Authentication failed: " + exception.getMessage());
}
@Override
public void onTokenRefresh(String newToken) {
System.out.println("Token refreshed");
}
};
// Configure authentication with event handling
AuthXManager authManager = new AuthXManager(provider);
// Note: Event listener integration depends on implementationJedis includes built-in support for Microsoft EntraID (formerly Azure AD) through the extension library:
// Microsoft EntraID authentication (requires redis-authx-entraid dependency)
// This example shows the general pattern - actual implementation may vary
import redis.clients.authentication.entraid.*;
// Configure EntraID credentials
EntraIDCredentialsProvider entraProvider = new EntraIDCredentialsProvider()
.tenantId("your-tenant-id")
.clientId("your-client-id")
.clientSecret("your-client-secret");
// Use with Jedis
JedisClientConfig config = DefaultJedisClientConfig.builder()
.credentialsProvider(entraProvider)
.build();
Jedis jedis = new Jedis("redis-enterprise-server", 6379, config);// Pool with authentication
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(20);
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
.user("myuser")
.password("mypassword")
.build();
JedisPool pool = new JedisPool(poolConfig, "localhost", 6379, clientConfig);
try (Jedis jedis = pool.getResource()) {
jedis.set("key", "value");
}// SSL connection with authentication
JedisClientConfig sslConfig = DefaultJedisClientConfig.builder()
.ssl(true)
.user("myuser")
.password("mypassword")
.build();
Jedis jedis = new Jedis("redis-ssl-server", 6380, sslConfig);try {
Jedis jedis = new Jedis("localhost", 6379,
DefaultJedisClientConfig.builder()
.password("wrong_password")
.build());
jedis.ping();
} catch (JedisAuthenticationException e) {
System.err.println("Authentication failed: " + e.getMessage());
} catch (JedisConnectionException e) {
System.err.println("Connection failed: " + e.getMessage());
}Install with Tessl CLI
npx tessl i tessl/maven-redis-clients--jedis