-
Notifications
You must be signed in to change notification settings - Fork 0
[Study] Embedded Redis Spring Boot 3.0 동작 확인
Bear edited this page Apr 26, 2023
·
1 revision
it.ozimov:embedded-redis
가장 최신 버전인 0.7.3
사용 시
slf4j
가 추가되어 LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
에러 발생
0.7.2
로 다운그레이드하여 해결
dependencies {
implementation ('it.ozimov:embedded-redis:0.7.2')
implementation ('org.springframework.boot:spring-boot-starter-data-redis')
}
@Configuration
@Profile("local")
public class EmbeddedRedisConfig
{
@Value("${spring.data.redis.port}")
private int redisPort;
private RedisServer redisServer;
@PostConstruct
public void redisServer()
{
redisServer = new RedisServer(redisPort);
redisServer.start();
}
@PreDestroy
public void stopRedis() {
if (redisServer != null) {
redisServer.stop();
}
}
}
@SpringBootTest
class EmbeddedRedisConfigTest
{
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Test
@DisplayName("임베디드 레디스에 데이터를 잘 적재하고 꺼낼 수 있다.")
void embeddedRedisTest()
{
ListOperations<String, Object> listOperations = redisTemplate.opsForList();
listOperations.leftPush("hello", "world");
listOperations.leftPush("hello", "world");
assertEquals(listOperations.size("hello"), 2);
}
}