SERVER/LARAVEL & PHP

laravel aws redis connect

나나나나나나나ㅏ나난ㄴ나ㅏ나나 2021. 1. 21. 16:56
728x90

laravel에서 ElastiCache로 만들어진 redis 연동하는 방법은 아래와 같다.

env에는 구성 엔드포인트를 넣으면된다

여기서 중요한건 만들때 클러스터 활성화 모드로 만들어야된다는것!

 

database.php


'redis'=>[
        'cluster' => env('REDIS_CLUSTER', true),

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
        'clusters' => [
            'default' => [
                [
                    'host' => env('REDIS_HOST', 'localhost'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', 6379),
                    'database' => env('REDIS_DATABASE', 0),
                    'read_write_timeout' => 60,
                ],
            ],
            'options' => [ // Clustering specific options
                'cluster' => 'redis', // This tells Redis Client lib to follow redirects (from cluster)
            ]
        ],
        'options' => [
            'parameters' => [ // Parameters provide defaults for the Connection Factory
                'password' => env('REDIS_PASSWORD', null), // Redirects need PW for the other nodes
                'scheme' => env('REDIS_SCHEME', 'tcp'),  // Redirects also must match scheme
            ],
            'ssl' => ['verify_peer' => false], // Since we dont have TLS cert to verify
        ],
        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '1'),
        ],
],
.env

CACHE_DRIVER=redis
REDIS_HOST= 구성엔드포인트
REDIS_PORT=6379
REDIS_SCHEME =tcp

 

그리고 elasticache 특성상 local에서는 접근을 할 수없다!

nashorn.tistory.com/entry/AWS-ElastiCacheRedis%EC%9D%98-%EC%99%B8%EB%B6%80-%EC%A0%91%EA%B7%BC-%EB%B9%84%ED%97%88%EC%9A%A9-%EC%9D%B4%EC%8A%88

 

AWS ElastiCache(Redis)의 외부 접근 비허용 이슈

AWS의 ElastiCache(Redis)를 로컬에서 접속을 하려고 하니, 정상적인 연결이 되지 않아 찾아보니 ElastiCache는 같은 VPC 내부에서만 접속이 가능하다는 것을 알게되었다. 아마도 RDS나 MongoDB와는 달리 상대

nashorn.tistory.com

 

728x90