RedisDsn
Rasuvaeff\PropertyTesting\Runner\Redis\RedisDsn
Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2
redis://host[:port][/db][?prefix=key-prefix&timeout=seconds] (or rediss:// for TLS), taken apart.
The shape is the one the IANA registration, predis and Symfony agree on: the path is the database index, TLS is the rediss scheme, and anything else — the key prefix — is a query parameter. A path that is not a database index is refused rather than reinterpreted, so a DSN means the same thing here as everywhere else it could be pasted into.
Parsing lives in its own type because it is the part with answers worth asserting — a default port and a default prefix are decisions, and a resolver that also builds clients hides them behind a connection.
Constants
| Constant | Type | Value | Description |
|---|---|---|---|
DEFAULT_PORT | int | 6379 | |
DEFAULT_TIMEOUT | float | 5 | |
DEFAULT_DATABASE | int | 0 | |
DEFAULT_PREFIX | string | "property-testing:corpus:" | The engine's own default, so a DSN without a prefix behaves like the plain constructor. |
Constructor
__construct(
non-empty-string $host,
int $port,
int<0, max> $database,
non-empty-string $prefix,
bool $tls,
float $timeout = 5.0,
?non-empty-string $password = NULL,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$host | non-empty-string | required | The host as a client connects to it: an IPv6 literal without the brackets the URI form wraps it in. |
$port | int | required | The TCP port; Runner\Redis\DEFAULT_PORT when the DSN names none. |
$database | int<0, max> | required | The database index to SELECT; Runner\Redis\DEFAULT_DATABASE when the DSN has no path. |
$prefix | non-empty-string | required | The key prefix every corpus key starts with; Runner\Redis\DEFAULT_PREFIX when the DSN has no prefix query parameter. |
$tls | bool | required | Whether the connection is TLS (rediss://). |
$timeout | float | 5.0 | The connection timeout in seconds. |
$password | ?non-empty-string | NULL | The AUTH password, or null for an unauthenticated server. Never parsed out of the DSN — see Runner\Redis\parse(). |
Methods
toPredisParameters()
toPredisParameters(): arrayThe connection parameters predis takes.
Here rather than at the call site so the shape is something a test can assert: an array literal built where the client is constructed can only be checked by connecting to a server.
The password key is present only when there is one: predis treats a null password as a password and sends AUTH.
phpRedisHost()
phpRedisHost(): stringThe host as ext-redis connects to it: tls:// in front for TLS, which is how phpredis selects the transport.
parse()
static parse(string $dsn, ?string $password = NULL): self$dsn— The DSN, already known to use theredisorredissscheme.$password— TheAUTHpassword, supplied out of band (the adapters readPROPERTY_DB_PASSWORD). Kept out of the DSN on purpose:PROPERTY_DBis echoed in the diagnostics below and lands in CI logs, and userinfo is rejected outright. An empty value means the same as none — an exported-but-empty variable is not a password.
Throws:
InvalidArgumentException— When the DSN carries credentials, names no host, has a path that is not a database index, has an invalid port/timeout, has an unknown query parameter, or has a fragment.