buzzingpixel/redis-psr-cache-implementation

Redis的PSR Cache接口实现

1.0.0 2022-01-04 23:38 UTC

This package is auto-updated.

Last update: 2024-09-05 05:26:06 UTC


README

用法

// Create a Redis instance
$redis = new \Redis();
$redis->connect(getenv('REDIS_HOST'));

// Create the RedisCacheItemPool and send it the redis instance
$cacheItemPool = new \BuzzingPixel\RedisCache\RedisCacheItemPool($redis);

以下是一个配置BuzzingPixel 容器的例子,使其在自动连接PSR CacheItemPoolInterface时默认使用RedisCacheItemPool(其他容器也可以类似配置)。

$container = new \BuzzingPixel\Container\Container(
    bindings: [
        \Psr\Cache\CacheItemPoolInterface::class => \BuzzingPixel\RedisCache\RedisCacheItemPool::class,
        \Redis::class => static function (): \Redis {
            $redis = new \Redis();
            $redis->connect(getenv('REDIS_HOST'));
            return $redis;
        }
    ]
);