PHPackages                             llegaz/redis-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. llegaz/redis-cache

ActiveLibrary[Caching](/categories/caching)

llegaz/redis-cache
==================

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

10[2 PRs](https://github.com/llegaz/RedisCache/pulls)PHP

Since Mar 14Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/llegaz/RedisCache)[ Packagist](https://packagist.org/packages/llegaz/redis-cache)[ RSS](/packages/llegaz-redis-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Redis Cache
===========

[](#redis-cache)

This project is build upon my first redis open PHP project [Redis Adapter](https://packagist.org/packages/llegaz/redis-adapter). Thanks to it you can use either [Predis](https://github.com/predis/predis) client or native [PHP Redis](https://github.com/phpredis/phpredis/) client in a transparent way.

This implementation is quite safe and rely totally on RESP (REdis Serialization Protocol), implemented by Predis and the Redis PHP extension, through their standard API.

PSR divergences
---------------

[](#psr-divergences)

For now some of the reserved charachters `()/@:` for the keys are supported entirely, it is an on purpose choice we made because PSR reserved those characters years ago and did nothing concrete with it, or nothing I have heard of. Moreover there are some real life example where those characters are cool to have (emails, urls, paths, and even redis proposed key format which is considered a good practise, e.g user:123). Finally, as there are no security constraints not to use those characters we made the choice not to follow PSR on this point and to support those chars `()/@:` and we hope it will be well tolerated by the PHP developpers community. A contrario we decided to not enable withespaces in keys to ease debugging and because it is not a redis standard (std\_key:preferred:form) nor in URL RFC definition. And so we thought it as not a good practice, at least, for our use cases. But thoses choices are not engraved in marble and are totally still on the table to discussion.

Install
-------

[](#install)

If PHP redis is installed

```
$ apt-get install php8.x-redis
```

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

You can simply use composer to install this library:

```
composer require llegaz/redis-cache
composer install
```

PSR-6
-----

[](#psr-6)

PSR-6 implementation is my implementation of `Caching Interface` from the PHP FIG [www.php-fig.org/psr/psr-6](https://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](https://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

[](#caution)

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

### Basic usage

[](#basic-usage)

Of course you should do cleaner, proper implementation, the below example is not production ready, it is simplified and given ONLY for the sake of example !

```
$cache = new LLegaz\Cache\RedisEnhancedCache();
// retrieve user_id as $id
$user = new \LLegaz\Cache\Pool\CacheEntryPool($cache, 'user_data' . $id);
$cart = new \LLegaz\Cache\Pool\CacheEntryPool($cache 'user_cart' . $id);

if ($this->bananaAdded()) {
    $item = $cart->getItem('product:banana');
    $item->set(['count' => 3, 'unit_price' => .33, 'kg_price' => 1.99, 'total_price' => 0]]); // yeah today bananas are free
    $cart->save($item);
    $cartItem = $user->getItem('cart');
    // increment $cartItem here
    $user->save($cartItem);
}
```

### Batch

[](#batch)

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

PSR-16
------

[](#psr-16)

My `Simple Cache` implementation PHP FIG PSR-16 [www.php-fig.org/psr/psr-16](https://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
-------------

[](#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

[](#persistent-connection)

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

Contributing
------------

[](#contributing)

We welcome contributions! This project follows **Git Flow** workflow.

### Quick Start

[](#quick-start)

```
# Create feature branch from develop
git checkout -b feature/my-feature develop

# Make changes and commit
git commit -m "feat: add new feature"

# Push and create Pull Request
git push origin feature/my-feature
```

For complete guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md) which covers:

- Git Flow workflow in detail
- Development environment setup
- Testing requirements and commands
- Code quality standards (PSR-12, PHPStan)
- Pull Request process and review timeline

### Development Commands

[](#development-commands)

```
# Install dependencies
composer install

# Run tests
composer test:integration

# Code quality
composer cs:check    # Check style
composer cs:fix      # Fix style
composer stan        # Static analysis
composer quality     # Run all checks
```

### CI/CD Status

[](#cicd-status)

[![CI](https://github.com/llegaz/RedisCache/workflows/CI/badge.svg)](https://github.com/llegaz/RedisCache/actions)[![codecov](https://camo.githubusercontent.com/2d28a3fbd7fd2f9b2d413ab14638a7ce03310e655806049a9ff1ed803cfc9294/68747470733a2f2f636f6465636f762e696f2f67682f6c6c6567617a2f526564697343616368652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/llegaz/RedisCache)

**Automated testing on:**

- 🐘 PHP 8.4.x, 8.5.x (latest stable versions)
- 📦 Redis 7.2
- 🔌 Both Predis and phpredis adapters

All Pull Requests are automatically tested before merge.

[View test results →](https://github.com/llegaz/RedisCache/actions)

RedisCache
==========

[](#rediscache)

[![CI](https://camo.githubusercontent.com/248ee932c47b719ae6685fb627ae6fa6105e17ddfc0e195c184e32dca3e78865/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6c6567617a2f526564697343616368652f63692e796d6c3f6272616e63683d646576656c6f70266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/248ee932c47b719ae6685fb627ae6fa6105e17ddfc0e195c184e32dca3e78865/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6c6567617a2f526564697343616368652f63692e796d6c3f6272616e63683d646576656c6f70266c6162656c3d7465737473267374796c653d666c61742d737175617265)[![PHP](https://camo.githubusercontent.com/5d14369f777c36ed06d2d0598edf43a8f04e0a1678f75e5dcc45d2e1733057cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e34253230253743253230382e352d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/5d14369f777c36ed06d2d0598edf43a8f04e0a1678f75e5dcc45d2e1733057cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e34253230253743253230382e352d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![Redis](https://camo.githubusercontent.com/7aebdf48bbb838bdb90a31c5e621e032a8610f26e9840ac1e7ea1d6c0a735022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656469732d372e322d4443333832443f7374796c653d666c61742d737175617265266c6f676f3d7265646973266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/7aebdf48bbb838bdb90a31c5e621e032a8610f26e9840ac1e7ea1d6c0a735022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656469732d372e322d4443333832443f7374796c653d666c61742d737175617265266c6f676f3d7265646973266c6f676f436f6c6f723d7768697465)[![Coverage](https://camo.githubusercontent.com/871ef9b88848aeb6c07a7ea2162f873d3dc53a0aa9a519814feb7f7048d20cef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d38352532352d737563636573733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/871ef9b88848aeb6c07a7ea2162f873d3dc53a0aa9a519814feb7f7048d20cef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d38352532352d737563636573733f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/e95f4589ae522bd6be956b11fefa668573a1279bc3c9bb323ccfc4be072ae70e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6c6567617a2f526564697343616368653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/e95f4589ae522bd6be956b11fefa668573a1279bc3c9bb323ccfc4be072ae70e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6c6567617a2f526564697343616368653f7374796c653d666c61742d737175617265)

**Redis-native PSR-16/PSR-6 for mature developers**

Stay tuned, by following me on github, for new features using [predis](https://github.com/predis/predis) and [PHP Redis](https://github.com/phpredis/phpredis/).

---

**@See you space cowboy...** 🚀

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance60

Regular maintenance activity

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5c6fbcd88b3869f85973ecbd65773891a8b231f43c01f0e7bb85aab55d06d6e?d=identicon)[llegaz](/maintainers/llegaz)

---

Top Contributors

[![llegaz](https://avatars.githubusercontent.com/u/25434383?v=4)](https://github.com/llegaz "llegaz (140 commits)")

---

Tags

persistent-connectionspsr-16psr-6redisredis-cache

### Embed Badge

![Health badge](/badges/llegaz-redis-cache/health.svg)

```
[![Health](https://phpackages.com/badges/llegaz-redis-cache/health.svg)](https://phpackages.com/packages/llegaz-redis-cache)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
