定制 llegaz/redis-cache 二次开发

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

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

llegaz/redis-cache

Composer 安装命令:

composer require llegaz/redis-cache

包简介

PSR-16 and PSR-6 implementations based on Redis Strings and Hashes

README 文档

README

This project is build upon my first redis open PHP project Redis Adapter. Thanks to it you can use either Predis client or native PHP Redis client in a transparent way.

If PHP redis is installed

$ apt-get install php8.x-redis

These implementations will use it or fallback on Predis client otherwise.

Install

composer require llegaz/redis-cache
composer install

PSR-6

PSR-6 implementation is my implementation of Caching Interface from the PHP FIG www.php-fig.org/psr/psr-6 It is far from perfect and as of now (first versions of this implementation) you should be aware that pool expiration are available but by pool's fields expiration are not really ! I will try to test and implement a pool key expiration for Valkey.io in a near future but my first draft is: if you expire a pool key it will expire your entire pool SO BE EXTRA CAUTIOUS WITH THAT !

Caution

if you expire a pool key it will expire your entire pool SO BE EXTRA CAUTIOUS WITH THAT !

Basic usage

$cache = new LLegaz\Cache\RedisEnhancedCache();
$cart = new \LLegaz\Cache\Pool\CacheEntryPool($cache);
$user = new \LLegaz\Cache\Pool\CacheEntryPool($cache, 'lolo');

$id = $user->getItem('id');
if ($id->isHit()) {
    $item = $cart->getItem('banana:' . $id->get());
    $item->set('mixed value');
    $cart->save($item);
} else {
    $id->set('the lolo id');
    $user->save($id);
}

Batch

foreach ($cart as $item) {
    $cart->saveDeferred($item); // items are commited on pool object destruct
}

PSR-16

My Simple Cache implementation PHP FIG PSR-16 www.php-fig.org/psr/psr-16

    $cache = new LLegaz\Cache\RedisCache();
    $cache->selectDatabase(3); // switch database
    $cache->set('key', 'mixed value, could be an object or an array');
    $cache->get('key'));


    $cache->setMultiple(['key1' => [], 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4'], 90); // 1m30s expiration on each key
    if ($cache->has('key1') && $cache->has('key4')) {
        $array = $cache->getMultiple(['key1', 'key1', 'key4']));
        var_dump(count($array)); // int(2)
        var_dump($array); // array(2) { ["key1"]=> string(6) "value1" ["key4"]=> string(6) "value4" }
    }

Configuration

$cache = new LLegaz\Cache\RedisCache();

is equivalent to

$cache = new LLegaz\Cache\RedisCache('127.0.0.1');

or

$cache = new LLegaz\Cache\RedisCache('localhost', 6379, null, 'tcp', 0, false); // the nulled field is the Redis password in clear text (here no pwd)

Persistent connection

$cache = new LLegaz\Cache\RedisCache('localhost', 6379, null, 'tcp', 0, true);

Contributing

You're welcome to propose things. I am open to criticism as long as it remains benevolent.

Stay tuned, by following me on github, for new features using predis and PHP Redis.

@see you space cowboy

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-18