PHP code example of ciatog / redis-cache
1. Go to this page and download the library: Download ciatog/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/ */
ciatog / redis-cache example snippets
use Ciatog\RedisCache;
// Creates an instance of the cache using `MY_CONTEXT` as the unique context
// for all operations
$cache = new RedisCache("MY_CONTEXT");
// Returns true/false depending on whether an item with this key exists in the cache.
$cache->exists("TEST_KEY");
// Return data in cache for key `TEST_KEY`.
// If that key is not in the cache then execute the function passed as the
// second argument, set the item in the cache to the data set on $config->item
// and finally return the item data.
$cache->get(
"TEST_KEY",
function ($config) {
$config->item = "Test Data";
}
);
// Deletes the item in the cache with this key if it exists
$cache->delete("TEST_KEY");
// Deletes all items in the cache
$cache->deleteAll();
// Returns a list of all the keys in the cache
$cache->keys();