Skip to content

Instantly share code, notes, and snippets.

@tillkruss

tillkruss/redis-test.php

Last active Aug 20, 2016
Embed
What would you like to do?
[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