darkweak / storages

Souin's storages
MIT License
1 stars 3 forks source link

redis and go-redis empty key content with Valkey #19

Open sharifm-informatica opened 1 week ago

sharifm-informatica commented 1 week ago

Not sure if it is a problem with Valkey specifically. But keys are stored empty in redis/Valkey. Here is the cache part of my Caddyfile for redis:

{
    cache {
        ttl 24h
        stale 4h
        # default_cache_control public, max-age=27200
        redis {
            configuration {
                InitAddress redis-caddy:6379

            }
            # cache_keys {
            #   headers X-Token Authorization
            # }
        }
    }

All requests from Souin are uri-miss although the key is inthe Valkey DB. There is an error returned in the header of each request UPSTREAM-ERROR-OR-EMPTY-RESPONSE. ?I can see the pings and queries in valkey so netowrking and communication is not an issue. I expect Valkey to be 100% compatible with redis. Not sure if it is the factor here.

darkweak commented 10 hours ago

Hey @sharifm-informatica sorry for the delay, do you have a docker compose file to reproduce this with the command line run ran to build the instance (maybe Dockerfile)?

sharifm-informatica commented 3 hours ago

Sure:

Dockerfiles

FROM caddy:2-builder AS builder

RUN xcaddy build --with github.com/caddyserver/cache-handler --with github.com/darkweak/storages/redis/caddy
FROM caddy:2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Also:

FROM caddy:2-builder AS builder

RUN xcaddy build --with github.com/darkweak/souin/plugins/caddy --with github.com/darkweak/storages/go-redis/caddy

FROM caddy:2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Compose File

version: "3.8"
services:
  caddy:
    # image: caddy:alpine
    build: 
      context: ./caddy-cache
      # context: ./caddy-souin
      dockerfile: Dockerfile
    restart: unless-stopped
    volumes:
      - caddy_data:/data
      - caddy_config:/config
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./html/public:/srv/public:ro
    cap_add:
      - NET_ADMIN
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    depends_on:
      - phpfpm
      - redis-caddy
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://caddy/healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s
    networks:
      default:
    deploy:
      resources:
        limits:
          cpus: "0.7"
          memory: "100M"
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp

  redis-caddy:
    image: valkey/valkey:8.0-alpine
    restart: unless-stopped
    volumes:
      - redis_caddy_data:/data
      - ./redis-caddy.conf:/usr/local/etc/redis/redis.conf:ro
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s
    deploy:
      resources:
        limits:
          cpus: "0.5"
          memory: "100M"
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    security_opt:
      - no-new-privileges:true
    read_only: true

volumes:
  caddy_data:
    external: true
  caddy_config:
  redis_caddy_data:
    external: true
networks:
  default:
    driver: bridge