HashObjectDriver
in package
implements
RdbObjectDriver
Store an object as a flattened hash.
This converts nested object + arrays into a flattened form using a dot notation.
For example:
['abc' => [
'def' => [123, 456]
]]
becomes:
'abc.def.0' => 123
'abc.def.1' => 456
This somewhat breaks the setObject() signature, where the return value is the number of keys rather than the number of bytes.
Objects are expected to implement JsonSerializable and JsonDeserializable.
For convenience, implement the RdbJsonObject interface.
The 'expected' parameter is required.
Table of Contents
Interfaces
- RdbObjectDriver
- Base interface for object drivers.
Properties
Methods
- __construct() : mixed
- getObject() : T|null
- Get an object from a key.
- inspect() : string|null
- Inspect the object stored in the key.
- mGetObjects() : array<string, T|null>
- Get multiple objects from a key.
- mSetObjects() : array<string|int, int>
- Set multiple objects.
- setObject() : int
- Set an object.
Properties
$rdb
protected
Rdb
$rdb
Methods
__construct()
public
__construct(Rdb $rdb) : mixed
Parameters
- $rdb : Rdb
getObject()
Get an object from a key.
public
getObject(string $key, string $expected) : T|null
Parameters
- $key : string
- $expected : string
Tags
Return values
T|nullinspect()
Inspect the object stored in the key.
public
inspect(string $key) : string|null
Parameters
- $key : string
Tags
Return values
string|null —the object class name
mGetObjects()
Get multiple objects from a key.
public
mGetObjects(array<string|int, mixed> $keys, string $expected) : array<string, T|null>
Parameters
- $keys : array<string|int, mixed>
- $expected : string
Tags
Return values
array<string, T|null>mSetObjects()
Set multiple objects.
public
mSetObjects(iterable<string|int, mixed> $items) : array<string|int, int>
Parameters
- $items : iterable<string|int, mixed>
-
[ key => object ]
Tags
Return values
array<string|int, int> —[ key => int ] object sizes in bytes
setObject()
Set an object.
public
setObject(string $key, object $value[, int|float $ttl = 0 ]) : int
Parameters
- $key : string
- $value : object
- $ttl : int|float = 0
-
seconds
Tags
Return values
int —object size in bytes