DLight\Application\Drive\Cache\Redis
Mô tả: Redis cache driver (lazy connect). Hỗ trợ prefix, TTL mặc định, remember(), clearPrefix() bằng SCAN.
Yêu cầu extension ext-redis.
Public API
__construct(array $config = [])set(string $key, mixed $value, ?int $ttl = null): boolget(string $key, mixed $fallback = null, ?int $ttl = null): mixedremember(string $key, int $ttl, callable $callback): mixedrememberForever(string $key, callable $callback): mixeddelete(string $key): boolexists(string $key): bool/has(string $key): boolincrement(string $key, int $by = 1): intclearPrefix(): voidgetClient(): \Redis
Demo
use DLight\Application\Drive\Cache\Redis;
$cache = new Redis(['prefix' => 'dlight:']);
$cache->set('hello', ['a' => 1], 60);
$data = $cache->get('hello');
$users = $cache->remember('users', 30, function () {
return ['u1', 'u2'];
});