Skip to content

Add Redis Container

ucan-lab edited this page May 10, 2021 · 14 revisions

docker-compose.yml

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

volumes:
  redis-store:

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

infrastructure/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"
Clone this wiki locally