定制 firehed/redis-psr16 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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_THROW may throw exceptions on network issues (in the same way directly using the Redis extension can). Exceptions thrown will implement Psr\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_FAIL will prevent exceptions from being thrown. Any error, including networking errors (where the Redis extension 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固