Neuron-PHP

IRepository

Repository interface for storing and retrieving serializable data.

The IRepository interface provides a consistent API for persisting data across different storage backends (Redis, Memory, File, etc.). It supports basic CRUD operations with optional time-to-live (TTL) for automatic expiration.

Tags
example
// Store a DTO with 1 hour expiration
$repo = new Redis();
$repo->save('user:123', $userDto, 3600);

// Retrieve the DTO
$dto = $repo->find('user:123');

// Check existence
if ($repo->exists('user:123')) {
    $repo->delete('user:123');
}

Table of Contents

Methods

delete()  : bool
Delete a value by key.
exists()  : bool
Check if a key exists in the repository.
find()  : mixed
Find a value by key.
save()  : bool
Save a value to the repository.

Methods

delete()

Delete a value by key.

public delete(string $key) : bool
Parameters
$key : string

The key to delete

Return values
bool

True if deleted, false if key didn't exist

exists()

Check if a key exists in the repository.

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

The key to check

Return values
bool

True if exists and not expired, false otherwise

find()

Find a value by key.

public find(string $key) : mixed
Parameters
$key : string

The key to look up

Return values
mixed

The stored value, or null if not found or expired

save()

Save a value to the repository.

public save(string $key, mixed $value[, int $ttl = 0 ]) : bool
Parameters
$key : string

The unique key to store the value under

$value : mixed

The value to store (must be serializable)

$ttl : int = 0

Time-to-live in seconds (0 = no expiration)

Return values
bool

True on success, false on failure


        
On this page

Search results