PHPackages                             okdewit/redis-datastructures - 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. okdewit/redis-datastructures

ActivePackage[Caching](/categories/caching)

okdewit/redis-datastructures
============================

A Laravel + Redis library to create more advanced caching datastructures

1.2.2(2y ago)037.3k1MITPHPPHP &gt;=7.4

Since Apr 29Pushed 2y ago1 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (8)Used By (0)

Redis-datastructures
====================

[](#redis-datastructures)

A Laravel + Redis library to create more advanced caching datastructures

This package is tested with PHP 7.4 &amp; PHP 8.0,
with Laravel 6 and above,
and with both the `predis/predis` package &amp; with the native `phpredis` ext.

Usage
=====

[](#usage)

Current datastructures in this package:

IndexedCache
------------

[](#indexedcache)

IndexedCache caches objects, and optionally maintains one or more secondary indexes for those objects.

```
$cache = new IndexedCache(

    // Name, prefix where the cached objects are stored
    'colorcache',

    // A callback used to determine where the (integer) primary key can be found on the object
    fn(Color $color) => $color->id,

    // An array with secondary index definitions.
    ['color' => fn(Color $color) => $color->color]
);
```

`Color` is just a simple DTO class in this example, but it could be any serializable object or Model.

```
class Color
{
    public int $id;
    public string $color;
}
```

Expiration for the objects can be set, as well as a handler for cache misses:

```
$cache->setTimeToLive(CarbonInterval::day())
    ->setOnMiss(fn(int $id) => new Color($id, 'purple'));
```

The cache can be warmed all at once, or populated with individual items:

```
$collection = new ColorCollection([
    new Color(1, 'green'),
    new Color(2, 'blue'),
    new Color(3, 'green')
]);

$cache->warm($collection);              // Flush & populate the cache
$cache->warm($collection, false);       // Do not flush, just extend the cache with missing items

$purple = new Color(4, 'purple');
$cache->put($purple);
```

Because we defined which properties on the object represent the "primary" and (optionally) "secondary" keys, we can efficiently retrieve items from the cache:

```
// Find by primary index (unique),
// O(1)
$color = $cache->find(4);
$this->assertEquals($purple, $color);

// Find by secondary index (non unique, collection),
// O(log(N)+M), equal time complexity to an SQL BTREE index.
$colorCollection = $cache->findBy('color', $color);
$this->assertEquals(2, $colorCollection->count());

// Group by secondary index
$colorCollection = $cache->groupBy('color');
$this->assertEquals(['blue', 'green', 'purple'], $colorCollection->keys());
```

`findBy` returns a plain `Illuminate\Support\Collection` with all the objects matching the indexed constraint.
This can of course be converted into a custom collection using something like `->pipeInto(ColorCollection::class)`.

`groupBy` returns a `LazyCollection` with multiple `Collections` inside, with all objects grouped by the provided secondary index.

Finally, the whole cache can also be retrieved, or emptied:

```
$colorCollection = $cache->all();
$cache->flush();
```

Testing
=======

[](#testing)

Run `composer update`, and then `composer test`

By default, it will use the predis client, and assume connection details as defined in `phpunit.xml.dist`. This can be customized by copying and editing the dist file to `phpunit.xml` before running the tests.

On Github Actions, the package is tested against both predis &amp; phpredis.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% 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.

###  Release Activity

Cadence

Every ~177 days

Recently: every ~265 days

Total

7

Last Release

783d ago

### Community

Maintainers

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

---

Top Contributors

[![okdewit](https://avatars.githubusercontent.com/u/1403548?v=4)](https://github.com/okdewit "okdewit (28 commits)")[![PrinsFrank](https://avatars.githubusercontent.com/u/25006490?v=4)](https://github.com/PrinsFrank "PrinsFrank (2 commits)")

### Embed Badge

![Health badge](/badges/okdewit-redis-datastructures/health.svg)

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

###  Alternatives

[imanghafoori/laravel-widgetize

A minimal yet powerful package to give a better structure and caching opportunity for your Laravel apps.

909137.9k12](/packages/imanghafoori-laravel-widgetize)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[alexmg86/laravel-sub-query

Laravel subquery

7538.4k](/packages/alexmg86-laravel-sub-query)[laravel-enso/rememberable

Model caching dependency for Laravel Enso

2863.2k25](/packages/laravel-enso-rememberable)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)

PHPackages © 2026

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