A helper for caching slow operations using Redis.
Licensed under MIT. Totally free for private or commercial projects.
composer require andrewdyer/predis-adaptor
<?php
$cache = new Anddye\PredisAdaptor\Cache([
'host' => '',
'password' => '',
'port' => '',
'scheme' => '',
]);
Option | Type | Default | Description |
---|---|---|---|
host | string | 127.0.0.1 | IP or hostname of the target server. |
password | string | not set | Accepts a value used to authenticate with a Redis server protected by password with the AUTH command. |
port | string | 6379 | TCP/IP port of the target server. |
scheme | string | tcp | Specifies the protocol used to communicate with an instance of Redis. |
Method | Description |
---|---|
$cache->client() |
|
$cache->delete(string $key) |
|
$cache->exists(string $key) |
|
$cache->get(string $key) |
|
$cache->put(string $key, $value, int $minutes = 10) |
|
$cache->remember(string $key, int $minutes, callable $callback) |
$cache->delete('my_key');
unset($cache->my_key);
unset($cache['my_key'])
$bool = $cache->exists('my_key');
$bool = isset($cache->my_key);
$value = $cache->get('my_key');
$value = $cache->my_key;
$cache->put('my_key', 'my_value');
$cache->my_key = 'my_value';
$value = $cache->remember('my_key', 10, function () {
return 'my_value';
});