Skip to content

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 ​

ConstantTypeValueDescription
DEFAULT_PORTint6379
DEFAULT_TIMEOUTfloat5
DEFAULT_DATABASEint0
DEFAULT_PREFIXstring"property-testing:corpus:"The engine's own default, so a DSN without a prefix behaves like the plain constructor.

Constructor ​

php
__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,
)
ParameterTypeDefaultDescription
$hostnon-empty-stringrequiredThe host as a client connects to it: an IPv6 literal without the brackets the URI form wraps it in.
$portintrequiredThe TCP port; Runner\Redis\DEFAULT_PORT when the DSN names none.
$databaseint<0, max>requiredThe database index to SELECT; Runner\Redis\DEFAULT_DATABASE when the DSN has no path.
$prefixnon-empty-stringrequiredThe key prefix every corpus key starts with; Runner\Redis\DEFAULT_PREFIX when the DSN has no prefix query parameter.
$tlsboolrequiredWhether the connection is TLS (rediss://).
$timeoutfloat5.0The connection timeout in seconds.
$password?non-empty-stringNULLThe AUTH password, or null for an unauthenticated server. Never parsed out of the DSN — see Runner\Redis\parse().

Methods ​

toPredisParameters() ​

php
toPredisParameters(): array

The 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() ​

php
phpRedisHost(): string

The host as ext-redis connects to it: tls:// in front for TLS, which is how phpredis selects the transport.

parse() ​

php
static parse(string $dsn, ?string $password = NULL): self
  • $dsn — The DSN, already known to use the redis or rediss scheme.
  • $password — The AUTH password, supplied out of band (the adapters read PROPERTY_DB_PASSWORD). Kept out of the DSN on purpose: PROPERTY_DB is 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.