-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat] 레디스 DB 추가
- Loading branch information
Showing
12 changed files
with
148 additions
and
31 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
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,34 @@ | ||
package com.simter.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.HashOperations; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
@EnableRedisRepositories(basePackageClasses = TokenRedisRepository.class) | ||
public class RedisConfig { | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | ||
RedisTemplate<String, String> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(redisConnectionFactory); | ||
template.setDefaultSerializer(new StringRedisSerializer()); | ||
template.afterPropertiesSet(); | ||
return template; | ||
} | ||
|
||
@Bean | ||
public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) { | ||
return redisTemplate.opsForValue(); | ||
} | ||
|
||
@Bean | ||
public HashOperations<String, String, String> hashOperations(RedisTemplate<String, String> redisTemplate) { | ||
return redisTemplate.opsForHash(); | ||
} | ||
} |
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,26 @@ | ||
package com.simter.config; | ||
|
||
import jakarta.persistence.Id; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.index.Indexed; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "token", timeToLive = 60 * 60 * 24 * 7) | ||
public class TokenRedis { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Indexed | ||
private String accessToken; | ||
|
||
private String refreshToken; | ||
|
||
public void updateToken(String accessToken, String refreshToken) { | ||
this.accessToken = accessToken; | ||
this.refreshToken = refreshToken; | ||
} | ||
} |
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,10 @@ | ||
package com.simter.config; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface TokenRedisRepository extends CrudRepository<TokenRedis, String> { | ||
|
||
Optional<TokenRedis> findByAccessToken(String accessToken); | ||
|
||
} |
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
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
Oops, something went wrong.