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