HEROJOON 블로그(히로블)

Mac에서 Redis(레디스) 설치하기 본문

Redis

Mac에서 Redis(레디스) 설치하기

herojoon 2023. 1. 16. 19:35
반응형

목표

  • Mac OS에서 Redis 설치하기
  • Mac OS에서 Redis 실행
  • Redis 실행 상태 확인
  • Redis CLI를 이용해서 Redis 사용해보기

 

해보기

1. Mac OS에서 Redis 설치

// Homebrew(Mac OS용 패키지 관리자) 설치 여부 확인
brew --version

 

// redis 설치
brew install redis

// redis 설치 제거 (설치한 redis를 제거하고 싶으시다면 아래 명령어 실행)
brew uninstall redis
// redis 설치 확인
redis-server --version

 


2. Mac OS에서 Redis 실행

2-1. Foreground로 실행하기 (Mac OS에 Redis가 정상적으로 설치되었는지 띄워보는 용도로 사용하면 될 것 같습니다.)

: Foreground로 실행하면 프로세스가 실행하는 동안 터미널에서 다른 작업을 할 수 없습니다.

터미널에서 명령어를 통해 입,출력을 주고받는데 Foreground로 실행할 경우 명령 처리가 끝날 때까지 다른 작업을 수행할 수 없습니다.

// redis foreground로 실행
redis-server

※ 위 명령어 실행 시 아래와 같은 오류가 발생했다면 redis port인 6379가 이미 실행되고 있다는 것이므로 포트를 종료하고 다시 위 명령어를 실행해주면 됩니다.

<오류명>
# Warning: Could not create server TCP listening socket *:6379: bind: Address already in use
# Failed listening on port 6379 (TCP), aborting.

"Mac에서 포트 확인 및 종료 바로가기"

 

 

2-2. Background로 실행하기 (실제 Redis를 사용할 경우에는 Background 명령어로 실행해줍니다.)

: Background로 실행할 경우 터미널에서 명령처리가 수행될 동안 다른 프로세스를 함께 수행할 수 있습니다.

ex) Application을 Background(&)로 수행하면서 원하는 파일을 찾거나 로그를 볼 수 있음.

// redis background로 실행
brew services start redis

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

// redis background로 중지
brew services stop redis

 


3. Redis 실행 상태 확인

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

 

 


4. Redis CLI를 이용해서 Redis 사용해보기

Redis CLI(Command Line Interface)는 레디스 명령어 라인 인터페이스입니다.

즉, Redis를 사용하기 위해 제공되는 Redis 명령어입니다.

해당 명령어를 이용하여 Redis에 값을 쓰고, 조회하고, 삭제할 수 있습니다.

 

// redis-cli 사용
redis-cli

 

// redis 데이터 생성, 수정(같은 Key값이 존재하면 데이터만 업데이트됨.)
// ex) set mykey, myvalue
set {key} {value}

 

// redis 데이터 조회
// ex) get mykey
get {key}

 

// redis 데이터 Key 목록 조회
keys *

 

// redis Key 수정
// ex) redis mykey mykey2
rename 기존키 변경키

 

// redis Key 개수 조회
dbsize

 

// redis Key(데이터) 삭제
// ex) del mykey2
del {key}

 

// redis Key(데이터) 전체 삭제
flushall

 

 

 

Install Redis on macOS

Use Homebrew to install and start Redis on macOS

redis.io

 

반응형

'Redis' 카테고리의 다른 글

AWS EC2에 Redis 설치하기  (0) 2024.04.07
Comments