firehed/redis-psr16
Composer 安装命令:
composer require firehed/redis-psr16
包简介
Redis implementation of PSR-16
README 文档
README
This is a Redis implementation for the PSR-16 SimpleCache interface.
This library actually uses the multi-key operators supported by Redis (mget, etc), unlike most other implementations at the time of writing.
Installation and Usage
Install: composer require firehed/redis-psr16
Usage:
$redis = new \Redis(); $redis->connect('yourhost', 6379); $redis->auth(['user' => 'youruser', 'pass' => 'yourpass']); $cache = new \Firehed\Cache\RedisPsr16($redis); // Use like any other PSR-16 implementation
If Redis::OPT_SERIALIZER is not set (or uses the default Redis::SERIALIZER_NONE), this library will automatically set it to Redis::SERIALIZER_PHP.
This will ensure that non-string values are stored and retreived correctly.
Be aware that this means if any objects are cached, any magic methods related to serialization (__sleep(), __wakeup(), __serialize(), __unserialize()) will be called during caching operations.
Setting that option to any other value before providing Redis to this library will use the set serializer:
use Firehed\Cache\RedisPsr16; use Redis; // Automatically sets SERIALIZER_PHP: $redis = new Redis(); // connect/auth $cache = new RedisPsr16($redis); // Uses specified SERIALIZER_JSON $redis = new Redis(); // connect/auth $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON); $cache = new RedisPsr16($redis);
Configuration
A runtime mode can be set via the $mode constructor parameter:
use Firehed\Cache\RedisPsr16; $cache = new RedisPsr16($redis, RedisPsr16::MODE_THROW);
-
RedisPsr16::MODE_THROWmay throw exceptions on network issues (in the same way directly using theRedisextension can). Exceptions thrown will implementPsr\SimpleCache\CacheException, per PSR-16 requirements. This will help expose networking issues and may be beneficial for logging and error handling, but does require calling libraries to handle them. This is the default mode. -
RedisPsr16::MODE_FAILwill prevent exceptions from being thrown. Any error, including networking errors (where theRedisextension throws) will be treated as a failure. This could result in misleading behavior around cache misses; if it's important for your application to know the difference between "miss" and "Redis unavailable", do not use this mode.
The mode can be adjusted at runtime with RedisPsr16::setMode($mode).
统计信息
- 总下载量: 1.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-02