Code: Select all
org.springframework.boot
spring-boot-starter-parent
2.6.6
org.springframework.boot
spring-boot-starter-data-redis
< /code>
Unten finden Sie die Konfigurationsklasse, die ich zur Verbindung zu Redis verwendet: < /p>
@Configuration
@RequiredArgsConstructor
public class RedisConfigurationBuilder {
private final RedisProperties redisProperties;
@Bean
public RedisConnectionFactory redisConnectionFactory() {
try {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(redisProperties.getHost());
redisStandaloneConfiguration.setPort(redisProperties.getPort());
redisStandaloneConfiguration.setUsername(redisProperties.getUsername());
redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().useSsl().and()
.commandTimeout(Duration.ofSeconds(2)).build();
return new LettuceConnectionFactory(redisStandaloneConfiguration, clientConfig);
} catch (Exception e) {
throw new RuntimeException("Failed to configure Redis", e);
}
}
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(connectionFactory);
template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}
< /code>
Dies ist die RediSProperties -Klasse, die die Eigenschaften aus meiner application.yml -Datei liest: < /p>
@Component
@Getter
public class RedisProperties {
@Value("${spring.data.redis.host}")
private String host;
@Value("${spring.data.redis.port}")
private int port;
@Value("${spring.data.redis.username}")
private String username;
@Value("${spring.data.redis.password}")
private String password;
}
< /code>
Und schließlich ist dies meine Anwendung.yml: < /p>
spring:
application:
name: "application-name"
data:
redis:
host: {hostName}
port: 6379
username: {myUsername}
password: {myPassword}
ssl:
enabled: true
org.springframework.data.redis.RedisconnectionFailureException: Eine Verbindung zu Redis kann nicht hergestellt werden; Eine verschachtelte Ausnahme ist io.lettuce.core.redisconnectionException: Eine Verbindung zu {Hostname}: 6379/: 6379
und dies ist die Stapelverfolgung des Fehlers, das ich immer wieder bekomme:
org.springframework.data.redis.redisconNectionFailureException: Eine Verbindung zu Redis kann nicht hergestellt werden; Eine verschachtelte Ausnahme ist io.lettuce.core.redisconnectionException: Eine Verbindung zu {Hostname}: 6379/: 6379 at org.springframework.data.redis.connection.lettuce.lettuceConnectionFactory $ exceptiontranslatingConnectionProvider.TranslateException ( org.springframework.data.redis.connection.lettuce.lettuceConnectionFactory $ AusnahmetranslatingConnectionProvider.getConnection ( org.springframework.data.redis.connection.lettuce.lettuceConnectionFactory $ SharedConnection.getNativeConnection ( java.base/java.lang.thread.run (thread.java:833) verursacht durch: io.lettuce.core.redisconnectionException: nicht in der Lage, mit {Hostname}/: 6379 bei io.lettuce.core.Reconnection.CREATE.CREATE (REDICECONNECTION.CORNECECECEPECTE.RECTEI) zu verbinden. io.lettuce.core.redisconnectionException.create (redisconnectionException.java:56) at io.lettuce.core.abstractRedisclient.getConnection (AbstractRedisclient.java:330) at io.lettuce.core.Redisclient.connect.Connnect (redisclient.java:216). org.springframework.data.redis.connection.lettuce.standaloneconnectionProvider.lambda $ GetConnection $ 1 (StandaloneconnectionProvider.java:115) auf Java.base/java.util.optional.orelseget (optional.java org.springframework.data.redis.connection.lettuce.standaloneConnectionProvider.getConnection (StandaloneConnectionProvider.java:115) at org.springframework.data.redis.connection.lettuce.lettuceconnectionFactory $ exceptionTranslatingConnectionProvider.getConnection (lettuceConnectionFactory.java:1595) ... 77 Common Frames ausgelöst durch: java.lang.ILLEGUGUMEL: {Java.Lang.ILLEGUGUGUMEL: {Java.Lang.ILLEGUGUGUMEL: {Hostname ash ash ash}}: {{Lang.ILLEGALEGALEGUMEL: {Hostname}}. io.lettuce.core.internal.lettuceassert.istrue (lettuceassert.java:222) unter io.lettuce.core.internal.hostandport.of (Hostandport.java:57) unter io.lettuce.core.slconnectionbuilder.tohostport (SslconNection.-10.10.10.10.10.-109Por. io.lettuce.core.slConnectionBuilder.build (sslConnectionBuilder.java:99) bei