x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  redis:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}redis:${REDIS_VERSION:-8.2.1-alpine3.22}
    ports:
      - '${REDIS_PORT_OVERRIDE:-6379}:6379'
    volumes:
      - redis_data:/data
      # Use a custom redis.conf file
      # - ./redis.conf:/etc/redis/redis.conf
    environment:
      - TZ=${TZ:-UTC}
      - REDIS_PASSWORD=${REDIS_PASSWORD:-}
      - SKIP_FIX_PERMS=${SKIP_FIX_PERMS:-}
    command:
      - sh
      - -c
      - |
        if [ -n "$${REDIS_PASSWORD}" ]; then
          redis-server --requirepass "$${REDIS_PASSWORD}"
        else
          redis-server
        fi
    healthcheck:
      test: [CMD, redis-cli, ping]
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 5s
    deploy:
      resources:
        limits:
          cpus: ${REDIS_CPU_LIMIT:-0.5}
          memory: ${REDIS_MEMORY_LIMIT:-256M}
        reservations:
          cpus: ${REDIS_CPU_RESERVATION:-0.1}
          memory: ${REDIS_MEMORY_RESERVATION:-128M}

volumes:
  redis_data:
