terah / redis-cache
A very simple redis caching lib with hierarchical keys
8.0.0.0
2025-08-20 02:16 UTC
Requires
- php: >=8.0
- ext-psr: *
- ext-redis: *
- terah/fluent-assert: 8.*
This package is auto-updated.
Last update: 2026-06-20 04:11:44 UTC
README
Super simple redis caching implementation.
Install
Via Composer
$ composer require terah/redis-cache
Usage
$redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $namespace = 'my-short-db-cache'; $defaultTtl = 60 * 60; // 1 hour $cache = new Terah\RedisCache\RedisCache($redis, $defaultTtl, $namespace); // Save your data $cache->set('my-user-list', expensiveFunctionCall(), 60 * 60 * 2); // Ttl will default to $defaultTtl // Fetch your data $myData = $cache->get('my-user-list'); // Deletes $cache->delete('my-user-list'); // Convenient callback handler $callback = function() { return expensiveDataFetch(); } $data = $cache->remember('my-user-list', $callback, 60 * 60 * 1); // Hierarchical keys - caching in 'directories' $cache->set('/user_data/user_profiles/freddy', $data); $cache->set('/user_data/user_profiles/betty', $data); $cache->set('/user_data/user_profiles/micky', $data); // now you can flush all user data: $cache->delete('/user_data/');
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email terry@terah.com.au instead of using the issue tracker.
Credits
- [Terry Cullen][https://github.com/terah]
- All Contributors
License
The MIT License (MIT). Please see License File for more information.