Redis
Redis
Redis socket-backed cache backend.
class Redis extends \Hazaar\Cache\Backend\BackendImplements 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 = 2socket
public Client $socketbuffer
Internal receive buffer for RESP decoding.
private string $bufferoffset
Current offset into the receive buffer.
private int $offsetdelim
RESP line delimiter sequence.
private string $delim = '"\r\n"'Methods
available
Indicates whether required socket support is available.
public available(): boolinit
Initializes Redis connection, selects DB index, and configures capabilities.
public init(string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | active cache namespace |
cmd
public cmd(array $cmds, bool $useMaster): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$cmds | array | |
$useMaster | bool |
select
public select(int $db): boolParameters
| Parameter | Type | Description |
|---|---|---|
$db | int |
close
public close(): boolhas
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$checkEmpty | bool |
get
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
set
public set(string $key, mixed $value, ?int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed | |
$timeout | int |
remove
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
clear
public clear(): booltoArray
public toArray(): voidcount
public count(): intconnect
private connect(string $host, int $port = 6379): ClientParameters
| Parameter | Type | Description |
|---|---|---|
$host | string | |
$port | int |
getChunk
private getChunk(Client $socket, ?int $bytes): stringParameters
| Parameter | Type | Description |
|---|---|---|
$socket | Client | |
$bytes | int |
decode
Decodes a RESP data chunk.
private decode(Client $socket, ?string $chunk): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$socket | Client | |
$chunk | string |
encode
Encodes data into the RESP protocol.
private encode(mixed $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | The data to encode |
encodeValue
private encodeValue(mixed $value): stringParameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed |
deconstructValue
Deconstructs a value into an array of keys and values.
private deconstructValue(mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | The value to deconstruct |
reconstructValue
Reconstructs a value from an array of keys and values.
private reconstructValue(array $rawValues): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$rawValues | array | The raw values to reconstruct |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000