damalis / redis-cache-for-php-framework
PHP框架的Redis缓存
dev-main
2023-02-01 12:33 UTC
Requires
- php: ^7.4 || ^8.0
- predis/predis: >=2.0
This package is auto-updated.
Last update: 2024-09-15 09:38:59 UTC
README
PHP框架的Redis缓存。
安装
composer require damalis/redis-cache-for-php-framework
使用方法
将每个成功的HTTP响应缓存到本地Redis服务器,有效期为24小时。
示例
slim 框架;
use Slim\Factory\AppFactory;
use Slim\Factory\ServerRequestCreatorFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
//...
// Create Request object from globals
$serverRequestCreator = ServerRequestCreatorFactory::create();
$request = $serverRequestCreator->createServerRequestFromGlobals();
$client = new \Predis\Client('tcp://:6379', [
'prefix' => $request->getUri()->getHost()
]);
$app->add(new \damalis\RedisCache\Cache($client, [
'timeout' => 86400
]));
// ...