Skip to content

Add Redis Container

ucan-lab edited this page Jun 14, 2023 · 14 revisions

compose.yml

https://hub.docker.com/_/redis

volumes:
  redis-store:

services:
  redis:
    image: redis:6.2-alpine
    volumes:
      - type: volume
        source: redis-store
        target: /data
        volume:
          nocopy: true

infra/docker/php/Dockerfile

https://github.com/phpredis/phpredis.git

RUN git clone https://github.com/phpredis/phpredis.git /usr/src/php/ext/redis
RUN docker-php-ext-install redis

Laravel's .env

REDIS_HOST=redis
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

Since Laravel5.7, it has changed from QUEUE_DRIVER to QUEUE_CONNECTION. https://github.com/laravel/laravel/releases/tag/v5.7.0

Redis for Laravel

$ make tinker
use Illuminate\Support\Facades\Redis;
Redis::set('name', 'hoge');
Redis::get('name');

Redis cli

$ docker compose exec redis redis-cli

> flushall
OK

> set name "hoge"
OK
> get name
"hoge"