Redis
extends AbstractRegistry
in package
Redis registry class
One string key per worker, "{prefix}:worker:{id}", holding the JSON record.
Tags
Table of Contents
Properties
- $prefix : string
- Key prefix
- $redis : Redis|null
- Redis object
- $workerSetChecked : bool
- Whether this instance has already reconciled the worker index set against any record keys written without it. See ensureWorkerSet().
Methods
- __construct() : mixed
- Constructor
- all() : array<string|int, mixed>
- Fetch every stored record, keyed by worker ID
- delete() : void
- Remove a record. A no-op if the ID isn't there.
- getPrefix() : string
- Get the key prefix
- getRedis() : Redis|null
- Get the Redis object
- prune() : int
- Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
- read() : WorkerRecord|null
- Fetch a record by ID, or null if it isn't there
- write() : void
- Store a record, replacing any existing record with the same ID
- decode() : WorkerRecord|null
- Decode a stored record, or null if the payload is unusable
- encode() : string
- Encode a record for storage
- ensureWorkerSet() : void
- Bring the worker index set in line with any record keys that aren't in it, once per adapter instance.
- isExpired() : bool
- Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
- purgeUndecodable() : int
- Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
- recordKey() : string
- The key backing a given worker ID
- workerSetKey() : string
- Key of the set indexing registered worker IDs.
Properties
$prefix
Key prefix
protected
string
$prefix
= 'pop-registry'
$redis
Redis object
protected
Redis|null
$redis
= null
$workerSetChecked
Whether this instance has already reconciled the worker index set against any record keys written without it. See ensureWorkerSet().
protected
bool
$workerSetChecked
= false
Methods
__construct()
Constructor
public
__construct([string $host = 'localhost' ][, int|string $port = 6379 ][, string $prefix = 'pop-registry' ][, string|null $password = null ][, array<string|int, mixed>|null $context = null ]) : mixed
Parameters
- $host : string = 'localhost'
- $port : int|string = 6379
- $prefix : string = 'pop-registry'
- $password : string|null = null
- $context : array<string|int, mixed>|null = null
Tags
all()
Fetch every stored record, keyed by worker ID
public
all() : array<string|int, mixed>
Return values
array<string|int, mixed>delete()
Remove a record. A no-op if the ID isn't there.
public
delete(string $id) : void
Parameters
- $id : string
getPrefix()
Get the key prefix
public
getPrefix() : string
Return values
stringgetRedis()
Get the Redis object
public
getRedis() : Redis|null
Return values
Redis|nullprune()
Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
public
prune(int $olderThanSeconds) : int
Concrete here rather than per-backend: the expiry half is expressible purely in terms of all()/delete()/isExpired(), and four byte-identical copies would be four places for the rule to drift.
Parameters
- $olderThanSeconds : int
Return values
intread()
Fetch a record by ID, or null if it isn't there
public
read(string $id) : WorkerRecord|null
Parameters
- $id : string
Return values
WorkerRecord|nullwrite()
Store a record, replacing any existing record with the same ID
public
write(WorkerRecord $record) : void
Parameters
- $record : WorkerRecord
decode()
Decode a stored record, or null if the payload is unusable
protected
decode(string|null $payload) : WorkerRecord|null
Parameters
- $payload : string|null
Return values
WorkerRecord|nullencode()
Encode a record for storage
protected
encode(WorkerRecord $record) : string
JSON, deliberately - registry records are plain scalars and arrays, so this carries none of the unserialize() object-injection surface that job payloads do.
Parameters
- $record : WorkerRecord
Tags
Return values
stringensureWorkerSet()
Bring the worker index set in line with any record keys that aren't in it, once per adapter instance.
protected
ensureWorkerSet() : void
A record key can exist outside the set two ways: it was written by a version of this adapter that predates the set, or something wrote the key directly. Either way the set is now the only thing all() and purgeUndecodable() consult, so an unindexed record would be invisible to the stuck-worker sweep and to pruning - it would sit there forever, unreadable and unreapable.
The reconciliation costs one KEYS scan per Redis database, guarded by a marker key, which is the one place this adapter still issues one.
isExpired()
Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
protected
isExpired(WorkerRecord $record, int $olderThanSeconds) : bool
Parameters
- $record : WorkerRecord
- $olderThanSeconds : int
Return values
boolpurgeUndecodable()
Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
protected
purgeUndecodable() : int
These are invisible to all() by design (it skips them so one corrupt entry cannot derail enumeration), which would otherwise make them permanently unreapable - a truncated write or a bad payload would leak for the lifetime of the store. Backends with real storage override this; the default is a no-op for backends that cannot hold an undecodable entry.
Return values
intrecordKey()
The key backing a given worker ID
protected
recordKey(string $id) : string
Parameters
- $id : string
Return values
stringworkerSetKey()
Key of the set indexing registered worker IDs.
protected
workerSetKey() : string
Enumerating the registry used to mean a KEYS scan, which Redis runs against its whole keyspace while blocking every other client. all() is called by the stuck-worker sweep, so that scan landed on a live server on a routine schedule. Membership is tracked in a set instead, making the enumeration one SMEMBERS against a single key.