1. Go to this page and download the library: Download llegaz/redis-cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
llegaz / redis-cache example snippets
$cache = new LLegaz\Cache\RedisEnhancedCache();
// retrieve user_id as $id
$user = new \LLegaz\Cache\Pool\CacheEntryPool($cache, 'user_data' . $id);
$cart = new \LLegaz\Cache\Pool\CacheEntryPool($cache 'user_cart' . $id);
if ($this->bananaAdded()) {
$item = $cart->getItem('product:banana');
$item->set(['count' => 3, 'unit_price' => .33, 'kg_price' => 1.99, 'total_price' => 0]]); // yeah today bananas are free
$cart->save($item);
$cartItem = $user->getItem('cart');
// increment $cartItem here
$user->save($cartItem);
}
foreach ($cart as $item) {
$cart->saveDeferred($item); // items are commited on pool object destruct
}
$cache = new LLegaz\Cache\RedisCache();
$cache->selectDatabase(3); // switch database
$cache->set('key', 'mixed value, could be an object or an array');
$cache->get('key'));
$cache->setMultiple(['key1' => [], 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4'], 90); // 1m30s expiration on each key
if ($cache->has('key1') && $cache->has('key4')) {
$array = $cache->getMultiple(['key1', 'key1', 'key4']));
var_dump(count($array)); // int(2)
var_dump($array); // array(2) { ["key1"]=> string(6) "value1" ["key4"]=> string(6) "value4" }
}
$cache = new LLegaz\Cache\RedisCache();
$cache = new LLegaz\Cache\RedisCache('127.0.0.1');
$cache = new LLegaz\Cache\RedisCache('localhost', 6379, null, 'tcp', 0, false); // the nulled field is the Redis password in clear text (here no pwd)
$cache = new LLegaz\Cache\RedisCache('localhost', 6379, null, 'tcp', 0, true);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.