Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

RedisDriver
in

Behavioural contract for a Redis/Valkey client lib (phpredis or predis).

Each method is the typed shape the rest of ZealPHP\Store expects — the driver impl is responsible for wrapping its lib's exceptions in StoreException so callers never see a client-lib symbol.

Table of Contents

Methods

close()  : void
decrby()  : int
del()  : int
evalScript()  : mixed
exists()  : bool
expire()  : bool
get()  : string|null
hdel()  : int
hgetall()  : array<string, string>
hincrby()  : int
hincrbyfloat()  : float
hmget()  : array<int, string|null>
hset()  : int
incrby()  : int
mhgetall()  : array<int, array<string, string>>
Bulk HGETALL. Pipelined into a single round-trip; rows returned indexed by the input order. Missing keys come back as [] (empty hash) — Redis HGETALL on a non-existent key is empty, not an error.
mhsetWithMembership()  : void
Bulk write hashes + optional SET membership + optional EXPIRE, in one pipelined round-trip. Used by RedisBackend::mset and the tracked-mode mset path.
name()  : string
ping()  : bool
pipeline()  : array<int, mixed>
The pipeline callable receives an "echoed" driver instance whose methods enqueue commands instead of executing them; the return is the list of results in command order.
publish()  : int
sadd()  : int
scanCursor()  : array{0: string, 1: list}
One-batch cursor-based SCAN MATCH (S-3). Same semantics as sscanCursor but against the keyspace via SCAN.
scanKeys()  : Generator<int, string>
scard()  : int
set()  : bool
srem()  : int
sscan()  : Generator<int, string>
sscanCursor()  : array{0: string, 1: list}
One-batch cursor-based SSCAN (S-3). Returns [nextCursor, members].
subscribe()  : void
Block in a SUBSCRIBE+PSUBSCRIBE loop. The consumer is invoked once per inbound message frame with (string $payload, string $channel, ?string $pattern).
unlink()  : int
Best-effort non-blocking delete (UNLINK, Redis 4.0+). Falls back to DEL if UNLINK is unavailable. Returns count of keys removed.
xack()  : int
xadd()  : string
Append a message; auto-generated ID via *. Returns the generated ID.
xautoclaim()  : array{0: string, 1: list}>}
XAUTOCLAIM — atomically claim messages that have been pending in the group for longer than $minIdleMs and assign them to $consumer.
xgroupCreate()  : bool
Idempotent group create. Returns true if newly created, false if it already existed (BUSYGROUP). MKSTREAM ensures the stream is created if absent.
xreadGroup()  : array<string, array<int, array{id: string, payload: array}>>
XREADGROUP COUNT N BLOCK ms STREAMS s1 s2 ... > >.

Methods

decrby()

public decrby(string $key, int $by) : int
Parameters
$key : string
$by : int
Return values
int

del()

public del(string ...$keys) : int
Parameters
$keys : string
Return values
int

evalScript()

public evalScript(string $script, array<int, string> $keys, array<int, string> $args) : mixed
Parameters
$script : string
$keys : array<int, string>
$args : array<int, string>

exists()

public exists(string $key) : bool
Parameters
$key : string
Return values
bool

expire()

public expire(string $key, int $ttlSeconds) : bool
Parameters
$key : string
$ttlSeconds : int
Return values
bool

get()

public get(string $key) : string|null
Parameters
$key : string
Return values
string|null

hdel()

public hdel(string $key, string ...$fields) : int
Parameters
$key : string
$fields : string
Return values
int

hgetall()

public hgetall(string $key) : array<string, string>
Parameters
$key : string
Return values
array<string, string>

hincrby()

public hincrby(string $key, string $field, int $by) : int
Parameters
$key : string
$field : string
$by : int
Return values
int

hincrbyfloat()

public hincrbyfloat(string $key, string $field, float $by) : float
Parameters
$key : string
$field : string
$by : float
Return values
float

hmget()

public hmget(string $key, array<int, string> $fields) : array<int, string|null>
Parameters
$key : string
$fields : array<int, string>
Return values
array<int, string|null>

hset()

public hset(string $key, array<string, string> $fields) : int
Parameters
$key : string
$fields : array<string, string>
Return values
int

incrby()

public incrby(string $key, int $by) : int
Parameters
$key : string
$by : int
Return values
int

mhgetall()

Bulk HGETALL. Pipelined into a single round-trip; rows returned indexed by the input order. Missing keys come back as [] (empty hash) — Redis HGETALL on a non-existent key is empty, not an error.

public mhgetall(array<int, string> $keys) : array<int, array<string, string>>
Parameters
$keys : array<int, string>

full Redis keys (already prefixed by caller)

Return values
array<int, array<string, string>>

mhsetWithMembership()

Bulk write hashes + optional SET membership + optional EXPIRE, in one pipelined round-trip. Used by RedisBackend::mset and the tracked-mode mset path.

public mhsetWithMembership(array<int, array{rk: string, fields: array, sk?: string}> $writes[, string|null $setKey = null ][, int|null $ttl = null ]) : void

Each $writes entry:

  • rk : full Redis key for the HSET target (already prefixed)
  • fields : the hash payload
  • sk : (optional) the logical user key to add to $setKey

Behaviour:

  • HMSET $rk fields
  • if $ttl > 0: EXPIRE $rk $ttl
  • if $setKey !== null and any entries have sk: SADD $setKey sk1 sk2 ... (idempotent on existing members — no isNew check needed, but tracked mode stays consistent because SADD returns 0 for dupes)
Parameters
$writes : array<int, array{rk: string, fields: array, sk?: string}>
$setKey : string|null = null
$ttl : int|null = null

pipeline()

The pipeline callable receives an "echoed" driver instance whose methods enqueue commands instead of executing them; the return is the list of results in command order.

public pipeline(callable $batch) : array<int, mixed>
Parameters
$batch : callable
Return values
array<int, mixed>

publish()

public publish(string $channel, string $payload) : int
Parameters
$channel : string
$payload : string
Return values
int

receivers Redis delivered to

sadd()

public sadd(string $key, array<int, string> $members) : int
Parameters
$key : string
$members : array<int, string>
Return values
int

scanCursor()

One-batch cursor-based SCAN MATCH (S-3). Same semantics as sscanCursor but against the keyspace via SCAN.

public scanCursor(string $match, string $cursor, int $count) : array{0: string, 1: list}
Parameters
$match : string
$cursor : string
$count : int
Return values
array{0: string, 1: list}

scanKeys()

public scanKeys(string $match[, int $batch = 200 ]) : Generator<int, string>
Parameters
$match : string
$batch : int = 200
Return values
Generator<int, string>

scard()

public scard(string $key) : int
Parameters
$key : string
Return values
int

set()

public set(string $key, string $value[, int|null $ttlSeconds = null ]) : bool
Parameters
$key : string
$value : string
$ttlSeconds : int|null = null
Return values
bool

srem()

public srem(string $key, array<int, string> $members) : int
Parameters
$key : string
$members : array<int, string>
Return values
int

sscan()

public sscan(string $key[, int $batch = 100 ]) : Generator<int, string>
Parameters
$key : string
$batch : int = 100
Return values
Generator<int, string>

sscanCursor()

One-batch cursor-based SSCAN (S-3). Returns [nextCursor, members].

public sscanCursor(string $key, string $cursor, int $count) : array{0: string, 1: list}

$cursor === '0' starts a fresh scan; when the returned next-cursor is '0' the scan is exhausted. Use when iterating large SETs without blocking on a full generator drain — required for paginated UIs.

Parameters
$key : string
$cursor : string
$count : int
Return values
array{0: string, 1: list}

subscribe()

Block in a SUBSCRIBE+PSUBSCRIBE loop. The consumer is invoked once per inbound message frame with (string $payload, string $channel, ?string $pattern).

public subscribe(array<int, string> $exactChannels, array<int, string> $patternChannels, callable(string $payload, string $channel, Array $pattern): void $consumer) : void

Throwing PubSubStopException from inside the consumer is the clean stop signal — drivers MUST catch it, UNSUBSCRIBE, return.

Parameters
$exactChannels : array<int, string>

channels for SUBSCRIBE

$patternChannels : array<int, string>

patterns for PSUBSCRIBE (Redis * glob)

$consumer : callable(string $payload, string $channel, Array $pattern): void

Best-effort non-blocking delete (UNLINK, Redis 4.0+). Falls back to DEL if UNLINK is unavailable. Returns count of keys removed.

public unlink(string ...$keys) : int

Used by RedisBackend::clear to avoid blocking the Redis main thread on large tables (UNLINK runs the actual reclaim in a background thread).

Parameters
$keys : string
Return values
int

xack()

public xack(string $stream, string $group, string ...$ids) : int
Parameters
$stream : string
$group : string
$ids : string
Return values
int

ids actually ACK'd

xadd()

Append a message; auto-generated ID via *. Returns the generated ID.

public xadd(string $stream, array<string, string> $fields[, int|null $maxLen = null ]) : string
Parameters
$stream : string
$fields : array<string, string>

field=>value pairs forming the stream entry

$maxLen : int|null = null

if set, applied as MAXLEN ~ trimming

Return values
string

xautoclaim()

XAUTOCLAIM — atomically claim messages that have been pending in the group for longer than $minIdleMs and assign them to $consumer.

public xautoclaim(string $stream, string $group, string $consumer, int $minIdleMs[, string $start = '0-0' ][, int $count = 16 ]) : array{0: string, 1: list}>}

Used for stale-consumer recovery: when a consumer crashes mid-processing, its pending messages stay pending forever; a healthy peer steals them after the idle threshold.

Returns a tuple of [next-cursor, claimed-entries]. Iterate $start with the next-cursor until it comes back as '0-0' to drain.

Parameters
$stream : string
$group : string
$consumer : string
$minIdleMs : int
$start : string = '0-0'
$count : int = 16
Return values
array{0: string, 1: list}>}

xgroupCreate()

Idempotent group create. Returns true if newly created, false if it already existed (BUSYGROUP). MKSTREAM ensures the stream is created if absent.

public xgroupCreate(string $stream, string $group[, string $id = '$' ][, bool $mkStream = true ]) : bool
Parameters
$stream : string
$group : string
$id : string = '$'
$mkStream : bool = true
Return values
bool

xreadGroup()

XREADGROUP COUNT N BLOCK ms STREAMS s1 s2 ... > >.

public xreadGroup(string $group, string $consumer, array<int, string> $streams, int $count, int $blockMs) : array<string, array<int, array{id: string, payload: array}>>
Parameters
$group : string
$consumer : string
$streams : array<int, string>
$count : int
$blockMs : int
Return values
array<string, array<int, array{id: string, payload: array}>>

keyed by stream

On this page