Skip to content

Instantly share code, notes, and snippets.

@tillkruss
Last active August 20, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tillkruss/b2ca21f79a14cd900e4b3b282eaf3447 to your computer and use it in GitHub Desktop.
Save tillkruss/b2ca21f79a14cd900e4b3b282eaf3447 to your computer and use it in GitHub Desktop.
[WordPress] Redis Test MU-Plugin
<?php
/*
Plugin Name: Redis Test
Plugin URI: https://wordpress.org/plugins/redis-cache/
Description: Redis connection test.
Author: Till Krüss
Version: 1.0
Author URI: https://till.im/
*/
add_filter( 'debug_bar_panels', function ( $panels ) {
return array_merge($panels, [new Debug_Bar_Redis_Test]);
} );
class Debug_Bar_Redis_Test {
function title() {
return 'Redis Test';
}
function is_visible() {
return true;
}
function prerender() { }
function render() {
echo '<pre>';
echo 'Deleting test key...' . PHP_EOL;
wp_cache_delete( 'redis-test' );
if (! wp_cache_get( 'redis-test' )) {
echo 'Test key deleted!' . PHP_EOL;
} else {
echo 'Test key could not be deleted!' . PHP_EOL;
}
echo 'Storing test key...' . PHP_EOL;
wp_cache_add( 'redis-test', 'foobar' );
echo 'Looking up test key...' . PHP_EOL;
if ( wp_cache_get('redis-test') === 'foobar' ) {
echo 'Test key found!' . PHP_EOL;
} else {
echo 'Test key could not be found!' . PHP_EOL;
}
echo 'Deleting test key...' . PHP_EOL;
wp_cache_delete( 'redis-test' );
echo '</pre>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment