-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[BE] chore(#35): Redis setting
- Loading branch information
Showing
9 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/example/backend/domain/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.backend.domain.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
|
||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
// Bean으로 등록해 Redis 연결 - Lettuce 사용 | ||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/example/backend/domain/define/test/RedisTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.backend.domain.define.test; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@RedisHash(value = "test", timeToLive = 60 * 3) // 3분 | ||
public class RedisTest { | ||
@Id | ||
private Long id; | ||
|
||
private String description; | ||
|
||
@Builder | ||
public RedisTest(String description) { | ||
this.description = description; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../src/main/java/com/example/backend/domain/define/test/repository/RedisTestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.backend.domain.define.test.repository; | ||
|
||
import com.example.backend.domain.define.test.RedisTest; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface RedisTestRepository extends CrudRepository<RedisTest, Long> { | ||
} |
5 changes: 0 additions & 5 deletions
5
backend/src/test/java/com/example/backend/auth/api/service/jwt/JwtServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...java/com/example/backend/domain/redis/define/test/repository/RedisTestRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.backend.domain.redis.define.test.repository; | ||
|
||
import com.example.backend.auth.TestConfig; | ||
import com.example.backend.domain.define.test.RedisTest; | ||
import com.example.backend.domain.define.test.repository.RedisTestRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
class RedisTestRepositoryTest extends TestConfig { | ||
@Autowired | ||
private RedisTestRepository redisTestRepository; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
// redisTestRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Redis 저장 & 조회 테스트") | ||
void redisSaveTest() { | ||
// given | ||
RedisTest savedEntity = redisTestRepository.save(RedisTest.builder() | ||
.description("테스트 입니다.") | ||
.build()); | ||
|
||
// when | ||
RedisTest findEntity = redisTestRepository.findById(savedEntity.getId()).get(); | ||
|
||
// then | ||
assertThat(findEntity).isNotNull(); | ||
assertThat(findEntity.getDescription()).isEqualTo("테스트 입니다."); | ||
} | ||
} |