﻿# ADR 0002 — Single Predis Client (T-F03)

Date: 2026-09-11
Status: Accepted
Refs: T-F03, EXECUTION_ROADMAP.md §9

## Context

Multiple parts of the codebase were instantiating their own `Predis\Client`
independently (RateLimiter, JobQueue, Cache). This created hidden connection
proliferation: under load, each PHP worker could open 3+ separate TCP
connections to Redis instead of 1.

## Decision

All Redis usage is routed through a **single `Predis\Client` instance**
registered in `ContainerFactory` as a shared singleton. All consumers
(`RedisRateLimiter`, `RedisJobQueue`, `Cache`) receive this instance via
constructor injection.

## Consequences

- Maximum 1 Redis TCP connection per PHP worker process.
- A PHPUnit architecture test (`tests/Architecture/LayeringTest.php`) guards
  against regression: `new Predis\Client(...)` outside `ContainerFactory`
  causes a test failure.
- If separate Redis databases/connections are needed per service in the future,
  introduce named bindings in the container rather than direct instantiation.
