Redis
Redis
Redis socket-backed cache backend.
class Redis extends \Hazaar\Cache\BackendExtends: Hazaar\Cache\Backend
Implements cache operations over the Redis RESP protocol using a low-level socket client. Values are stored under namespaced Redis keys and support optional TTL/keepalive behavior controlled by backend options.
This backend provides object storage support by serializing complex values into hash fields and reconstructing them on read.
Properties
weight
Backend priority weight used when selecting backends in a chain.
protected int $weight = 2Type: int
config
Typed view of this backend's options.
private Redis\Options $configType: Hazaar\Cache\Backend\Redis\Options
socket
public Client $socketType: Hazaar\Socket\Client
buffer
Internal receive buffer for RESP decoding.
private string $bufferType: string
offset
Current offset into the receive buffer.
private int $offsetType: int
delim
RESP line delimiter sequence.
private string $delim = '"\r\n"'Type: string
Methods
available
Indicates whether required socket support is available.
public available(): boolReturns: bool
init
Initializes Redis connection, selects DB index, and configures capabilities.
public init(string $namespace): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | active cache namespace |
cmd
public cmd(array $cmds, bool $useMaster): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$cmds | array | |
$useMaster | bool |
select
public select(int $db): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$db | int |
close
public close(): boolReturns: bool
has
public has(string $key, bool $checkEmpty): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$checkEmpty | bool |
get
public get(string $key): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
set
public set(string $key, mixed $value, ?int $timeout): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed | |
$timeout | int |
remove
public remove(string $key): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
clear
public clear(): boolReturns: bool
toArray
public toArray(): arrayReturns: array
count
public count(): intReturns: int
connect
private connect(string $host, int $port = 6379): ClientReturns: Hazaar\Socket\Client
Parameters
| Parameter | Type | Description |
|---|---|---|
$host | string | |
$port | int |
getChunk
private getChunk(Client $socket, ?int $bytes): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$socket | Hazaar\Socket\Client | |
$bytes | int |
decode
Decodes a RESP data chunk.
private decode(Client $socket, ?string $chunk): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$socket | Hazaar\Socket\Client | |
$chunk | string |
encode
Encodes data into the RESP protocol.
private encode(mixed $data): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | The data to encode |
encodeValue
private encodeValue(mixed $value): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed |
deconstructValue
Deconstructs a value into an array of keys and values.
private deconstructValue(mixed $value): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | The value to deconstruct |
reconstructValue
Reconstructs a value from an array of keys and values.
private reconstructValue(array $rawValues): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$rawValues | array | The raw values to reconstruct |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000