API Index — Namespaces, Packages, Reports, Indices
StoreBackend
in
Behavioural contract every Store backend implements.
The default TableBackend wraps OpenSwoole\Table (single-node,
in-memory, lock-free reads, nanosecond latency). RedisBackend
(Task 6) talks to Redis/Valkey for cross-node + persistent state.
Phase 2's TieredBackend layers them.
Implementations MUST preserve identical typed shapes across backends:
a get() returning ['hits' => 1] from Table must return the same
['hits' => 1] from Redis after a TypeCodec decode pass.
Table of Contents
Methods
- clear() : void
- count() : int
- Return the number of rows currently stored in table
$name. - decr() : int|float
- Atomically decrement column
$colof row$keyin table$nameby$by. - del() : bool
- Delete the row at
$keyfrom table$name. Returnstrueon success,falseif the key did not exist. - exists() : bool
- Return
truewhen table$namecontains a row with key$key. - get() : mixed
- Read a row OR a single field.
- incr() : int|float
- Atomically increment column
$colof row$keyin table$nameby$by. - iterate() : Generator<string, array<string, scalar>>
-
iteratePaged()
: array{cursor: string, rows: array
>} - Paginated iteration (S-3). Returns one batch + an opaque cursor for
the next batch. Use for large tables where a full
iterate()drain is impractical (e.g. rendering a single page of a 100k-member room roster, exposing cursors over HTTP). - make() : void
- Register a named table with a column schema. For Table this allocates shared memory immediately; for Redis it stores the schema and defers connection until first use.
- mget() : array<string, array<string, scalar>|null>
- Bulk read. Returns
[key => row]; rows arenullfor missing keys (NOT omitted) so callers can distinguish "not found" from "empty row". RedisBackend pipelines this into one round-trip; TableBackend loops. - mset() : bool
- Bulk write. Returns true on full success, false if any individual row failed (TableBackend overflow). The Redis impl is pipelined.
- names() : array<int, string>
- set() : bool
- Write a row into table
$nameunder$key. Overwrites any existing row.
Methods
clear()
public
clear(string $name) : void
Parameters
- $name : string
count()
Return the number of rows currently stored in table $name.
public
count(string $name) : int
Parameters
- $name : string
Return values
intdecr()
Atomically decrement column $col of row $key in table $name by $by.
public
decr(string $name, string $key, string $col[, int|float $by = 1 ]) : int|float
Returns the new column value. Creates the row with the column set to -$by when it does not exist.
Parameters
- $name : string
- $key : string
- $col : string
- $by : int|float = 1
Return values
int|floatdel()
Delete the row at $key from table $name. Returns true on success, false if the key did not exist.
public
del(string $name, string $key) : bool
Parameters
- $name : string
- $key : string
Return values
boolexists()
Return true when table $name contains a row with key $key.
public
exists(string $name, string $key) : bool
Parameters
- $name : string
- $key : string
Return values
boolget()
Read a row OR a single field.
public
get(string $name, string $key[, string|null $field = null ]) : mixed
Returns array<string, scalar> when $field is null, the field's
scalar value when set, or null on miss. The exact typed shape
across backends is preserved by TypeCodec (Task 5).
Parameters
- $name : string
- $key : string
- $field : string|null = null
incr()
Atomically increment column $col of row $key in table $name by $by.
public
incr(string $name, string $key, string $col[, int|float $by = 1 ]) : int|float
Returns the new column value. Creates the row with the column set to $by when it does not exist.
Parameters
- $name : string
- $key : string
- $col : string
- $by : int|float = 1
Return values
int|floatiterate()
public
iterate(string $name) : Generator<string, array<string, scalar>>
Parameters
- $name : string
Return values
Generator<string, array<string, scalar>>iteratePaged()
Paginated iteration (S-3). Returns one batch + an opaque cursor for
the next batch. Use for large tables where a full iterate() drain
is impractical (e.g. rendering a single page of a 100k-member room
roster, exposing cursors over HTTP).
public
iteratePaged(string $name[, string $cursor = '0' ][, int $count = 100 ]) : array{cursor: string, rows: array>}
Contract:
$cursor === '0'(or '') starts a fresh scan.- When the returned
cursorfield is'0'the scan is exhausted. $countis a HINT (Redis SCAN convention) — the batch returned may contain fewer rows on tracked-mode SETs with sparse hits, or more than$counton small SETs (single-batch returns).- Cursors are NOT stable across schema/clear changes; resume only within a logically-consistent window.
Parameters
- $name : string
- $cursor : string = '0'
- $count : int = 100
Return values
array{cursor: string, rows: arraymake()
Register a named table with a column schema. For Table this allocates shared memory immediately; for Redis it stores the schema and defers connection until first use.
public
make(string $name, int $maxRows, array<string, array{0: int, 1?: int}> $columns[, array<string, mixed> $opts = [] ]) : void
Parameters
- $name : string
- $maxRows : int
- $columns : array<string, array{0: int, 1?: int}>
- $opts : array<string, mixed> = []
-
backend-specific: mode/ttl/etc.
mget()
Bulk read. Returns [key => row]; rows are null for missing keys
(NOT omitted) so callers can distinguish "not found" from "empty
row". RedisBackend pipelines this into one round-trip; TableBackend
loops.
public
mget(string $name, array<int, string> $keys) : array<string, array<string, scalar>|null>
Parameters
- $name : string
- $keys : array<int, string>
Return values
array<string, array<string, scalar>|null>mset()
Bulk write. Returns true on full success, false if any individual row failed (TableBackend overflow). The Redis impl is pipelined.
public
mset(string $name, array<string, array<string, scalar>> $rows) : bool
Parameters
- $name : string
- $rows : array<string, array<string, scalar>>
Return values
boolnames()
public
names() : array<int, string>
Return values
array<int, string>set()
Write a row into table $name under $key. Overwrites any existing row.
public
set(string $name, string $key, array<string, scalar> $row) : bool
Returns true on success, or false when the backend cannot store the entry
(e.g. the OpenSwoole\Table is full).
Parameters
- $name : string
- $key : string
- $row : array<string, scalar>
-
Column-name → value map. All declared columns must be present.