У меня есть служба Redis на upstash.io, но я не могу подключиться к ней из приложения весенней загрузки.
Это моя конфигурация Redis
@Configuration
public class RedisConfig {
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName("myhost");
redisStandaloneConfiguration.setPort(6379);
redisStandaloneConfiguration.setPassword(RedisPassword.of("password")); // Uncomment if password is needed
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
@Bean
public RedisTemplate redisTemplate() {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
return template;
}
}
Это мой сервис Redis
@Component
@RequiredArgsConstructor
public class RedisService {
@Autowired
private final RedisTemplate redisTemplate;
@PostConstruct
public void testConnection() {
try {
redisTemplate.getConnectionFactory().getConnection().ping();
System.out.println("Connected to Redis successfully");
} catch (Exception e) {
System.err.println("Unable to connect to Redis: " + e.getMessage());
}
}
public void set(String key, V value, long timeout, TimeUnit timeUnit) {
System.out.println("Storing message to redis cache: Key[" + key + "]");
redisTemplate.opsForValue().set(key, value);
redisTemplate.expire(key, timeout, timeUnit);
}
public V get(String key) {
return (V) redisTemplate.opsForValue().get(key);
}
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
}
Это мой pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.0.6
com.springprojects
realtimechatapp
0.0.1-SNAPSHOT
jar
realtimechatapp
Chat Application using Spring Boot
17
17
17
org.springframework.boot
spring-boot-starter-data-jpa
javax.persistence
javax.persistence-api
2.2
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-websocket
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-validation
com.mysql
mysql-connector-j
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-tomcat
provided
org.apache.tomcat.embed
tomcat-embed-jasper
10.1.18
provided
org.springframework.boot
spring-boot-starter-test
test
javax.servlet
jstl
1.2
javax.servlet
javax.servlet-api
3.1.0
provided
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-security
org.thymeleaf.extras
thymeleaf-extras-springsecurity6
org.springframework.kafka
spring-kafka
com.google.code.gson
gson
io.lettuce
lettuce-core
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-maven-plugin
paketobuildpacks/builder-jammy-base:latest
org.projectlombok
lombok
src/main/resources
true
Журналы:
Вызвано: io.lettuce.core.RedisConnectionException: соединение закрыто преждевременно
I пытался увеличить время ожидания, но не помогло.
Локальное соединение с Redis также дает ту же ошибку
redisStandaloneConfiguration.setHostName("localhost");
redisStandaloneConfiguration .setPort(6379);
Обновлена конфигурация Redis
@Configuration
public class RedisConfig {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
System.out.println("Creating RedisConnectionFactory");
return new LettuceConnectionFactory();
}
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
System.out.println("Creating RedisTemplate");
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... pring-boot
Невозможно подключиться к Redis | Весенние ботинки ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1719033157
Anonymous
У меня есть служба Redis на upstash.io, но я не могу подключиться к ней из приложения весенней загрузки.
Это моя конфигурация Redis
@Configuration
public class RedisConfig {
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName("myhost");
redisStandaloneConfiguration.setPort(6379);
redisStandaloneConfiguration.setPassword(RedisPassword.of("password")); // Uncomment if password is needed
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
@Bean
public RedisTemplate redisTemplate() {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
return template;
}
}
Это мой сервис Redis
@Component
@RequiredArgsConstructor
public class RedisService {
@Autowired
private final RedisTemplate redisTemplate;
@PostConstruct
public void testConnection() {
try {
redisTemplate.getConnectionFactory().getConnection().ping();
System.out.println("Connected to Redis successfully");
} catch (Exception e) {
System.err.println("Unable to connect to Redis: " + e.getMessage());
}
}
public void set(String key, V value, long timeout, TimeUnit timeUnit) {
System.out.println("Storing message to redis cache: Key[" + key + "]");
redisTemplate.opsForValue().set(key, value);
redisTemplate.expire(key, timeout, timeUnit);
}
public V get(String key) {
return (V) redisTemplate.opsForValue().get(key);
}
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
}
Это мой pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.0.6
com.springprojects
realtimechatapp
0.0.1-SNAPSHOT
jar
realtimechatapp
Chat Application using Spring Boot
17
17
17
org.springframework.boot
spring-boot-starter-data-jpa
javax.persistence
javax.persistence-api
2.2
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-websocket
org.springframework.boot
spring-boot-devtools
runtime
true
org.springframework.boot
spring-boot-starter-validation
com.mysql
mysql-connector-j
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-tomcat
provided
org.apache.tomcat.embed
tomcat-embed-jasper
10.1.18
provided
org.springframework.boot
spring-boot-starter-test
test
javax.servlet
jstl
1.2
javax.servlet
javax.servlet-api
3.1.0
provided
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-security
org.thymeleaf.extras
thymeleaf-extras-springsecurity6
org.springframework.kafka
spring-kafka
com.google.code.gson
gson
io.lettuce
lettuce-core
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-maven-plugin
paketobuildpacks/builder-jammy-base:latest
org.projectlombok
lombok
src/main/resources
true
Журналы:
Вызвано: io.lettuce.core.RedisConnectionException: соединение закрыто преждевременно
I пытался увеличить время ожидания, но не помогло.
Локальное соединение с Redis также дает ту же ошибку
redisStandaloneConfiguration.setHostName("localhost");
redisStandaloneConfiguration .setPort(6379);
Обновлена конфигурация Redis
@Configuration
public class RedisConfig {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
System.out.println("Creating RedisConnectionFactory");
return new LettuceConnectionFactory();
}
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
System.out.println("Creating RedisTemplate");
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78635522/unable-to-connect-to-redis-spring-boot[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия