Ready to use redis
This commit is contained in:
@@ -60,6 +60,11 @@ dependencies {
|
|||||||
Jwt (JSON Web Token Support For The JVM)
|
Jwt (JSON Web Token Support For The JVM)
|
||||||
*/
|
*/
|
||||||
implementation 'io.jsonwebtoken:jjwt:0.9.1'
|
implementation 'io.jsonwebtoken:jjwt:0.9.1'
|
||||||
|
|
||||||
|
/*
|
||||||
|
Redis
|
||||||
|
*/
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
|
|||||||
43
src/main/java/demo/api/config/RedisConfig.java
Normal file
43
src/main/java/demo/api/config/RedisConfig.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package demo.api.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.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Value("${redis.host}")
|
||||||
|
private String redisHost;
|
||||||
|
|
||||||
|
@Value("${redis.port}")
|
||||||
|
private int redisPort;
|
||||||
|
|
||||||
|
/*
|
||||||
|
RedisTemplate을 이용한 방식
|
||||||
|
|
||||||
|
RedisConnectionFactory 인터페이스를 통해
|
||||||
|
LettuceConnectionFactory를 생성하여 반환
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public RedisConnectionFactory redisConnectionFactory() {
|
||||||
|
return new LettuceConnectionFactory(redisHost, redisPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, String> redisTemplate() {
|
||||||
|
// redisTemplate를 받아와서 set, get, delete를 사용
|
||||||
|
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
|
||||||
|
// setKeySerializer, setValueSerializer 설정
|
||||||
|
// redis-cli을 통해 직접 데이터를 조회 시 알아볼 수 없는 형태로 출력되는 것을 방지
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory());
|
||||||
|
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,4 +7,5 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class TokenDto {
|
public class TokenDto {
|
||||||
private String access_token;
|
private String access_token;
|
||||||
|
private String refresh_token;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/userList")
|
@GetMapping("/userList")
|
||||||
public List<User> showUserList(Model model) {
|
public List<User> showUserList() {
|
||||||
return userService.findAll();
|
return userService.findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,14 +47,4 @@ public class User extends CoreEntity {
|
|||||||
this.password = passwordEncoder.encode(this.password);
|
this.password = passwordEncoder.encode(this.password);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 비밀번호 확인
|
|
||||||
* @param plainPassword 암호화 이전의 비밀번호
|
|
||||||
* @param passwordEncoder 암호화에 사용된 클래스
|
|
||||||
* @return true | false
|
|
||||||
*/
|
|
||||||
public boolean checkPassword(String plainPassword, PasswordEncoder passwordEncoder) {
|
|
||||||
return passwordEncoder.matches(plainPassword, this.password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,3 +14,6 @@ jwt:
|
|||||||
token:
|
token:
|
||||||
secret-key: aG91Mjctc2ltcGxlLXNwcmluZy1ib290LWFwaS1qd3QK
|
secret-key: aG91Mjctc2ltcGxlLXNwcmluZy1ib290LWFwaS1qd3QK
|
||||||
expire-length: 300000
|
expire-length: 300000
|
||||||
|
redis:
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
Reference in New Issue
Block a user