본문 바로가기

개발

[SpringBoot] Redis 설치 및 사용

리프레시 토큰을 구현하기위해 redis설치 

 

[설치]

brew install redis

[설치 확인]

redis-server --version

 

[Mac에서 실행-(Foreground)]

yeonbin@yeonbinui-MacBookPro redis % redis-server
5043:C 25 Jul 2023 13:12:35.429 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5043:C 25 Jul 2023 13:12:35.429 # Redis version=7.0.12, bits=64, commit=00000000, modified=0, pid=5043, just started
5043:C 25 Jul 2023 13:12:35.429 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
5043:M 25 Jul 2023 13:12:35.431 * Increased maximum number of open files to 10032 (it was originally set to 256).
5043:M 25 Jul 2023 13:12:35.431 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.12 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5043
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

5043:M 25 Jul 2023 13:12:35.432 # WARNING: The TCP backlog setting of 511 cannot be enforced because kern.ipc.somaxconn is set to the lower value of 128.
5043:M 25 Jul 2023 13:12:35.432 # Server initialized
5043:M 25 Jul 2023 13:12:35.432 * Ready to accept connections

[Mac에서 실행-(Background)]

대부분의 경우 백그라운드에서 실행하기 때문에 프론트에서 작동되는 redis를 종료하고 실행한다.

 

[실행]

yeonbin@yeonbinui-MacBookPro redis % brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)

[재실행 & 중지]

// redis background로 재실행
brew services restart redis

// redis background로 중지
brew services stop redis

[실행확인]

// redis 실행 상태 확인
brew services info redis

 

 

[리프레시 토큰 redis 저장 테스트]

redis-cli
.
.
127.0.0.1:6379> keys *
1) "refresh:1"
2) "refresh"
.
.
127.0.0.1:6379> hgetall refresh:1
1) "_class"
2) "com.example.gg.security.Token"
3) "expiration"
4) "120"
5) "id"
6) "1"
7) "refresh_token"
8) "ed040516-a8b4-4b84-8d36-30e7ecfc049c"