dtkahl / php-simple-redis-cache
1.0.1
2017-03-19 10:38 UTC
Requires
- php: >=5.6.0
- predis/predis: ^1.1
Requires (Dev)
- phpunit/phpunit: 5.2.*
This package is auto-updated.
Last update: 2024-10-29 04:47:43 UTC
README
PHP simple redis cache
This is a simple cache class for PHP using redis trough predis/predis
.
Dependencies
PHP >= 5.6.0
- a redis server
Installation
Install with Composer:
composer require dtkahl/php-simple-redis-cache
Usage
Refer namespace:
use Dtkahl\SimpleRedisCache;
Create new Cache instance:
$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)
$cache->put('foo', 'bar', 60)
has($key)
Determinate if key exists in cache.
$cache->has('foo')
get($key, $default = null)
Return Item from cache or $default
.
$cache->get('foo', 'default')
forget($key)
Remove item from cache.
$cache->forget('foo')
forever($key, $value)
Store item in cache forever.
$cache->forever('foo', 'bar')
remember($key, $callback, $time = null)
Return cache item if exists otherwise call $callback
, cache the returned value and return it.
$cache->put('foo')