JAVA-31500 :- Upgrade spring-data-redis to Spring Boot 3 (#16057)

This commit is contained in:
Amit Pandey
2024-03-24 19:18:22 +05:30
committed by GitHub
parent f277f6195e
commit 8dcc7d1569
9 changed files with 30 additions and 22 deletions
@@ -14,7 +14,7 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;
@Configuration
public class RedisConfig {
@@ -45,7 +45,7 @@ public class RedisConfig {
@PreDestroy
public void cleanRedis() {
factory.getConnection()
factory.getConnection().serverCommands()
.flushDb();
}
}
@@ -29,9 +29,9 @@ public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
final RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return template;
}
@@ -2,9 +2,11 @@ package com.baeldung.spring.data.redis.model;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisHash;
@RedisHash("Student")
@RequiredArgsConstructor
public class Student implements Serializable {
public enum Gender {
@@ -10,7 +10,7 @@ import java.util.List;
@Service
public class RedisMessageSubscriber implements MessageListener {
public static List<String> messageList = new ArrayList<String>();
public static List<String> messageList = new ArrayList<>();
public void onMessage(final Message message, final byte[] pattern) {
messageList.add(message.toString());
@@ -37,13 +37,13 @@ public class RedisKeyCommandsManualTest {
private ReactiveStringCommands stringCommands;
@BeforeClass
public static void startRedisServer() throws IOException {
public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
public static void stopRedisServer() {
redisServer.stop();
}
@@ -34,13 +34,13 @@ public class RedisTemplateListOpsManualTest {
private ReactiveListOperations<String, String> reactiveListOps;
@BeforeClass
public static void startRedisServer() throws IOException {
public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
public static void stopRedisServer() {
redisServer.stop();
}
@@ -37,13 +37,13 @@ public class RedisTemplateValueOpsManualTest {
private ReactiveValueOperations<String, Employee> reactiveValueOps;
@BeforeClass
public static void startRedisServer() throws IOException {
public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
public static void stopRedisServer() {
redisServer.stop();
}
@@ -33,18 +33,18 @@ public class StudentRepositoryManualTest {
private static redis.embedded.RedisServer redisServer;
@BeforeClass
public static void startRedisServer() throws IOException {
public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
public static void stopRedisServer() {
redisServer.stop();
}
@Test
public void whenSavingStudent_thenAvailableOnRetrieval() throws Exception {
public void whenSavingStudent_thenAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
final Student retrievedStudent = studentRepository.findById(student.getId()).get();
@@ -52,7 +52,7 @@ public class StudentRepositoryManualTest {
}
@Test
public void whenUpdatingStudent_thenAvailableOnRetrieval() throws Exception {
public void whenUpdatingStudent_thenAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
student.setName("Richard Watson");
@@ -62,7 +62,7 @@ public class StudentRepositoryManualTest {
}
@Test
public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() throws Exception {
public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() {
final Student engStudent = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
final Student medStudent = new Student("Med2015001", "Gareth Houston", Student.Gender.MALE, 2);
studentRepository.save(engStudent);
@@ -73,7 +73,7 @@ public class StudentRepositoryManualTest {
}
@Test
public void whenDeletingStudent_thenNotAvailableOnRetrieval() throws Exception {
public void whenDeletingStudent_thenNotAvailableOnRetrieval() {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
studentRepository.deleteById(student.getId());