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-08-29 04:31:16 UTC
README
PHP 简单 Redis 缓存
这是一个通过 predis/predis 使用 Redis 的 PHP 简单缓存类。
依赖项
PHP >= 5.6.0- 一个 Redis 服务器
安装
使用 Composer 安装
composer require dtkahl/php-simple-redis-cache
使用方法
引用命名空间
use Dtkahl\SimpleRedisCache;
创建新的 Cache 实例
$cache = new Cache([ "scheme" => "tcp", "host => "127.0.0.1", "port" => 6379 );
方法
put($key, $value, $time = null)
将项目放入缓存。 (时间单位:秒)
$cache->put('foo', 'bar', 60)
has($key)
确定键是否存在于缓存中。
$cache->has('foo')
get($key, $default = null)
从缓存中返回项目或 $default。
$cache->get('foo', 'default')
forget($key)
从缓存中移除项目。
$cache->forget('foo')
forever($key, $value)
永久存储项目在缓存中。
$cache->forever('foo', 'bar')
remember($key, $callback, $time = null)
如果存在则返回缓存项目,否则调用 $callback,缓存返回的值并返回它。
$cache->put('foo')