Redis Adapter
You must have a Redis server installed on your server. Please see the Redis documentation for installation instructions.
You must also ensure you have the PHP library Predis installed.
composer require predis/predis
<?php
include 'vendor/autoload.php';
use Vespula\Cache\Adapter\Redis as RedisCache;
use Predis\Client as PredisClient;
// Create new Predis Client object
$predisClient = new PredisClient();
// create the adapter
// Expire in 3600 seconds (1 hr)
// Setting the expiry to 0 indicates NO expiry.
$adapter = new RedisCache($predisClient, 3600);
$data = [
'foo'=>'this is foo',
'bar'=>'this is bar',
'dog'=>'canine',
];
$adapter->setMultiple($data);
// Set a value in the cache with expiry of 1800s (30 min)
$adapter->set('cat', 'meow', 1800);
// Get a value. If it doesn't exist, return a default value
$value = $adapter->get('cat', 'a default value');
// Delete a value
$adapter->delete($key);
// Check for presence in the cache
$is_cached = $adapter->has($key);
// Delete all entries in the cache
$adapter->flush();
// Update the expiry on an item
$adapter->touch($key, $ttl);
// Delete multiples
$keys = [
'foo',
'bar'
];
$adapter->deleteMultiple($keys);