본문 바로가기

AWS

ElastiCache Redis 매커니즘 및 연결 방법

목차

  1. Redis 버전 6 vs 7
  2. AWS ElastiCache Redis 매커니즘
  3. EC2에서 Redis - cluster 연결 방법

Redis 버전 6 vs 7

  • ElastiCache Redis에서 7.0.5 버전과 6.2.6 버전을 지원한다.
  • 7.0.2 버전이 22.06.12에 릴리즈되었다.
  • 실제 redis github issues 페이지에서 7 버전이 unstable 하다는 의견이 많다.
  • 7 버전 릴리즈가 된지 1년도 안 지났으므로 6.2.6 버전을 선택.

AWS ElastiCache Redis 매커니즘

  • AWS에서 캐쉬로 제공해주는 redis의 매커니즘은 local에서 접속하는 것을 배제하고 설계하였다.
  • ec2에서 직접 접근하는 것을 추천하고 만약에 local에서 접속해야 한다면, site to site VPN과 Direct Connect 서비스로 접속할 수 있다. 그런데 해당 aws 서비스는 클라우드를 이용하지 않고 물리 서버를 운영할 때 local에서 접속할 수 있게 해주는 서비스이다.
  • 또한, 만약에 에러가 발생해 에러를 보고 싶으면 CloudWatch에서 로그를 볼 수 있도록 설계되었다.

AWS ElastiCache Redis 특징

  • Redis는 인메모리이다.
  • 기본적으로 휘발성 데이터이다.

AWS ElastiCache Redis 테스트 방법

  • local에서는 redis를 직접 설치해서 test한다.
  • 운영되는 redis 서버에 접속하고 싶을 때에는 session manager로 local 터미널 혹은 aws console에서 접속할 수 있다.

EC2에서 Redis - cluster 연결 방법

  • EC2 접속 - session manager

EC2 접속 후 redis-cli 다운로드 및 설치

Amazon Linux 2

sudo amazon-linux-extras install epel -y
sudo yum install gcc jemalloc-devel openssl-devel tcl tcl-devel -y
sudo wget http://download.redis.io/redis-stable.tar.gz
sudo tar xvzf redis-stable.tar.gz
cd redis-stable
sudo make BUILD_TLS=yes

EC2 접속 후 redis에 연결(ElastiCache Redis에 암호화 설정이 되어 있는 경우)

src/redis-cli -c -h [cluster-endpoint] --tls -p [port number]

src/redis-cli -c -h service-redis-cluster-0001-001.service-redis-cluster.xxxxxx.xxxx.cache.amazonaws.com --tls -p 6379

Redis 명령어 실행 테스트

set a "hello" // Set key "a" with a string value and no expiration 
OK 
get a // Get value for key "a" 
"hello" 
get b // Get value for key "b" results in miss 
(nil) 
set b "Good-bye" EX 5 // Set key "b" with a string value and a 5 second expiration 
"Good-bye" 
get b // Get value for key "b" 
"Good-bye" // wait >= 5 seconds 
get b (nil) // key has expired, nothing returned 
quit // Exit from redis-cli

 

References

1. Redis 버전

https://github.com/redis/redis/issues/10981

http://redisgate.kr/redis/introduction/redis_release7.php

http://redisgate.kr/redis/introduction/redis_release6.php

https://medium.com/garimoo/%EB%A0%88%EB%94%94%EC%8A%A4-%EB%B2%84%EC%A0%846-%EB%89%B4%ED%94%BC%EC%B2%98%EC%99%80-%EC%A3%BC%EC%9A%94-%EA%B8%B0%EB%8A%A5-%ED%85%8C%EC%8A%A4%ED%8A%B8-45a7f53c4489

 

2. AWS ElastiCache Redis 매커니즘

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/GettingStarted.ConnectToCacheNode.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/elasticache-vpc-accessing.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/GettingStarted.AuthorizeAccess.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/GettingStarted.CreateCluster.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/SubnetGroups.Creating-gs.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/set-up.html

https://docs.aws.amazon.com/ko_kr/AmazonElastiCache/latest/red-ug/WhatIs.Components.html