1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel10 Cacheに ElastiCache for Redisのクラスターモードを利用する際の設定

Last updated at Posted at 2023-09-22

Laravelで、CacheにRedisを利用する場合、config/database.phpに設定を書き込むのですが、ElastiCache for Redisのクラスターモードを有効にした場合、記述内容が変更になります。
クラスターモードは、エンドポイントを共通にできるなどメリットも多いので、利用してみると良いとか思います。

下記のようにconfig/database.phpにデフォルトでは記述されていない、clustersを追加する必要があります。

config/database.php
'redis' => [

    'client' => env('REDIS_CLIENT', 'phpredis'),
        
    'options' => [
        'cluster' => 'redis',
    ],
    'clusters' => [
        'cache' => [
            [
                'host' => env('REDIS_HOST', '127.0.0.1'),
                'password' => env('REDIS_PASSWORD', null),
                'port' => env('REDIS_PORT', 6379),
                'database' => 0,
                'read_write_timeout' => env('REDIS_READ_WRITE_TIMEOUT', 60),
            ]
        ],
    ],
];

実際の値については、.envファイルに記述しますが、

REDIS_CLIENT には、predisを利用している場合は、predisを指定します。

REDIS_HOST には、設定エンドポイントを指定します。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?