Skip to content

Instantly share code, notes, and snippets.

@aidvu
Last active August 29, 2015 14:02
Show Gist options
  • Save aidvu/96088fd9a10e3b326f28 to your computer and use it in GitHub Desktop.
Save aidvu/96088fd9a10e3b326f28 to your computer and use it in GitHub Desktop.
Wordpress/Redis
{
"require": {
"predis/predis": "dev-master"
}
}
<?php
require 'vendor/autoload.php';
Predis\Autoloader::register();
$client = new Predis\Client();
$set = '';
$key = md5($_SERVER['REQUEST_URI']);
$compoundKey = $set . $key;
if ($data = $client->get($compoundKey)) {
echo $data;
} else {
ob_start();
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
$data = ob_get_flush();
ob_end_clean();
$client->set($compoundKey, $data);
$client->expire($compoundKey, 86400);
}
sudo apt-get install redis-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment