Dual-way Redis cache management

2.0 2016-11-07 22:22 UTC


Redis cache manager

Latest release API documentation: https://aloframework.github.io/cache/

License Latest Stable Version Total Downloads

dev-develop Latest release
Dev Build Status Release Build Status
Coverage Status Coverage Status


Installation is available via Composer:

composer require aloframework/cache


Only Redis is supported at this time.


    use AloFramework\Cache\Clients\RedisClient;

    $redis = new RedisClient();

    $redis->setKey('foo', 'bar', 300); // expire the key in 5 minutes
    $redis->setKey('foo', 'bar', new DateTime('2015-01-01 05:05:05')); //Expire the key on 2015-01-01 05:05:05
    $redis->setKey('foo', 'bar'); //Use default expiration time
    $redis['foo'] = 'bar'; //Use default expiration time

    //Echo the keys
    echo $redis->getKey('foo');
    echo $redis['foo'];

    //Echo all the keys

    //Loop through all the keys
    foreach ($redis as $k => $v) {
        echo 'Key: ' . $k . ', Value: ' . $v . '<br/>';

    //Count the number of items in the database
    echo count($redis);

    //Or do anything you would with the standard Redis class - RedisClient extends it.

Alternative usage


    use AloFramework\Cache\Clients\RedisClient;
    use AloFramework\Cache\CacheItem;

    //Save an item
    $server = new RedisClient();

    $cacheItem           = new CacheItem('key', 'value', $server);
    $cacheItem->lifetime = 600;

    // Get or load an item
    $cacheItem = new CacheItem('key');

    echo $cacheItem->value;


Configuration is done via the Configuration class.

  • Cfg::CFG_IP - default IP to use in the connect() method (defaults to
  • Cfg::CFG_PORT - default port to use in the connect() method (defaults to 6379)
  • Cfg::CFG_TIMEOUT - default cache timeout (defaults to 300 seconds)