Skip to content

Commit

Permalink
Feat [#8] Redis 관련 클래스 정의 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
geniusYoo authored Jun 24, 2024
2 parents cbf0e55 + 178f665 commit 6c1d360
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
3 changes: 1 addition & 2 deletions jaksim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
FROM eclipse-temurin:17
WORKDIR /app
COPY ./build/libs/jaksim-0.0.1-SNAPSHOT.jar /app/jaksim.jar
CMD ["java", "-Duser.timezone=Asia/Seoul", "-jar", "-Dspring.profiles.active=prod", "jaksim.jar"]

CMD ["sh", "-c", "java -Duser.timezone=Asia/Seoul -jar -Dspring.profiles.active=prod jaksim.jar > console.log 2>&1"]
5 changes: 3 additions & 2 deletions jaksim/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.sopt.jaksim.global.config;

import lombok.RequiredArgsConstructor;
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.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@RequiredArgsConstructor
@EnableRedisRepositories
public class RedisConfig {
@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

@Bean
public RedisConnectionFactory redisConnectionFactory(){
return new LettuceConnectionFactory(host, port);
}

@Bean
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
return redisTemplate;
}
}
27 changes: 27 additions & 0 deletions jaksim/src/main/java/org/sopt/jaksim/user/domain/RefreshToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sopt.jaksim.user.domain;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.index.Indexed;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PRIVATE)
@Getter
@RedisHash(value = "refreshToken", timeToLive = 60 * 60 * 24 * 1000L * 14)
public class RefreshToken {
@Id
private Long id;
@Indexed
private String refreshToken;

public static RefreshToken of(Long userId, String refreshToken) {
return RefreshToken.builder()
.id(userId)
.refreshToken(refreshToken)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.jaksim.user.repository;

import org.sopt.jaksim.user.domain.RefreshToken;
import org.springframework.data.repository.CrudRepository;

import java.util.Optional;

public interface RedisTokenRepository extends CrudRepository<RefreshToken, Long> {
Optional<RefreshToken> findByRefreshToken(final String refreshToken);
}

0 comments on commit 6c1d360

Please sign in to comment.