terah/redis-cache

A very simple redis caching lib with hierarchical keys


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.