This is a simple cache class for PHP using redis trough predis/predis.
PHP >= 5.6.0- a redis server
Install with Composer:
composer require dtkahl/php-simple-redis-cache
Refer namespace:
use Dtkahl\SimpleRedisCache;
Create new Cache instance:
$cache = new Cache([
"scheme" => "tcp",
"host => "127.0.0.1",
"port" => 6379
);Put item to cache. (time in seconds)
$cache->put('foo', 'bar', 60)Determinate if key exists in cache.
$cache->has('foo')Return Item from cache or $default.
$cache->get('foo', 'default')Remove item from cache.
$cache->forget('foo')Store item in cache forever.
$cache->forever('foo', 'bar')Return cache item if exists otherwise call $callback, cache the returned value and return it.
$cache->put('foo')