Version Description
- Added support for HHVM's Redis extension
- Added support for PCEL Redis extension
- Added
WP_REDIS_CLIENT
constant, to set prefered Redis client - Added
WP_REDIS_MAXTTL
constant, to force expiration of cache keys - Improved
add_or_replace()
,get()
,set()
anddelete()
methods - Improved admin screen styles
- Removed all internationalization/localization from drop-in
Download this release
Release Info
Developer | tillkruess |
Plugin | Redis Object Cache |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.1
- includes/admin-page.css +4 -0
- includes/admin-page.php +46 -15
- includes/object-cache.php +126 -109
- languages/redis-cache.pot +41 -29
- readme.txt +29 -7
- redis-cache.php +15 -2
includes/admin-page.css
CHANGED
@@ -29,3 +29,7 @@
|
|
29 |
0 0 0 1px #d54e21,
|
30 |
0 0 2px 1px rgba( 30, 140, 190, .8 );
|
31 |
}
|
|
|
|
|
|
|
|
29 |
0 0 0 1px #d54e21,
|
30 |
0 0 2px 1px rgba( 30, 140, 190, .8 );
|
31 |
}
|
32 |
+
|
33 |
+
.form-table table td {
|
34 |
+
padding: 0 1em 0 0;
|
35 |
+
}
|
includes/admin-page.php
CHANGED
@@ -15,28 +15,59 @@
|
|
15 |
</tr>
|
16 |
|
17 |
<tr valign="top">
|
18 |
-
<th scope="row"><?php _e( '
|
19 |
<td>
|
20 |
-
<
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
<?php if ( strcasecmp( 'tcp', $this->get_redis_scheme() ) === 0 ) : ?>
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
<?php endif; ?>
|
28 |
-
|
29 |
<?php if ( strcasecmp( 'unix', $this->get_redis_scheme() ) === 0 ) : ?>
|
30 |
-
|
|
|
|
|
|
|
31 |
<?php endif; ?>
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
<?php if ( ! is_null( $this->get_redis_password() ) ) : ?>
|
36 |
-
|
|
|
|
|
|
|
37 |
<?php endif; ?>
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
</td>
|
41 |
</tr>
|
42 |
|
15 |
</tr>
|
16 |
|
17 |
<tr valign="top">
|
18 |
+
<th scope="row"><?php _e( 'Configuration', 'redis-cache' ); ?></th>
|
19 |
<td>
|
20 |
+
<table>
|
21 |
+
<?php if ( ! is_null( $this->get_redis_client_name() ) ) : ?>
|
22 |
+
<tr>
|
23 |
+
<td><?php _e( 'Client:', 'redis-cache' ); ?></td>
|
24 |
+
<td><code><?php echo $this->get_redis_client_name(); ?></code></td>
|
25 |
+
</tr>
|
26 |
+
<?php endif; ?>
|
27 |
+
<tr>
|
28 |
+
<td><?php _e( 'Protocol:', 'redis-cache' ); ?></td>
|
29 |
+
<td><code><?php echo strtoupper( esc_html( $this->get_redis_scheme() ) ); ?></code></td>
|
30 |
+
</tr>
|
31 |
<?php if ( strcasecmp( 'tcp', $this->get_redis_scheme() ) === 0 ) : ?>
|
32 |
+
<tr>
|
33 |
+
<td><?php _e( 'Host:', 'redis-cache' ); ?></td>
|
34 |
+
<td><code><?php echo esc_html( $this->get_redis_host() ); ?></code></td>
|
35 |
+
</tr>
|
36 |
+
|
37 |
+
<tr>
|
38 |
+
<td><?php _e( 'Port:', 'redis-cache' ); ?></td>
|
39 |
+
<td><code><?php echo esc_html( $this->get_redis_port() ); ?></code></td>
|
40 |
+
</tr>
|
41 |
<?php endif; ?>
|
|
|
42 |
<?php if ( strcasecmp( 'unix', $this->get_redis_scheme() ) === 0 ) : ?>
|
43 |
+
<tr>
|
44 |
+
<td><?php _e( 'Path:', 'redis-cache' ); ?></td>
|
45 |
+
<td><code><?php echo esc_html( $this->get_redis_path() ); ?></code></td>
|
46 |
+
</tr>
|
47 |
<?php endif; ?>
|
48 |
+
<tr>
|
49 |
+
<td><?php _e( 'Database:', 'redis-cache' ); ?></td>
|
50 |
+
<td> <code><?php echo esc_html( $this->get_redis_database() ); ?></code></td>
|
51 |
+
</tr>
|
52 |
<?php if ( ! is_null( $this->get_redis_password() ) ) : ?>
|
53 |
+
<tr>
|
54 |
+
<td><?php _e( 'Password:', 'redis-cache' ); ?></td>
|
55 |
+
<td><code><?php echo str_repeat( '*', strlen( $this->get_redis_password() ) ); ?></code></td>
|
56 |
+
</tr>
|
57 |
<?php endif; ?>
|
58 |
+
<?php if ( ! is_null( $this->get_redis_cachekey_prefix() ) && trim( $this->get_redis_cachekey_prefix() ) !== '' ) : ?>
|
59 |
+
<tr>
|
60 |
+
<td><?php _e( 'Key Prefix:', 'redis-cache' ); ?></td>
|
61 |
+
<td><code><?php echo esc_html( $this->get_redis_cachekey_prefix() ); ?></code></td>
|
62 |
+
</tr>
|
63 |
+
<?php endif; ?>
|
64 |
+
<?php if ( ! is_null( $this->get_redis_maxttl() ) ) : ?>
|
65 |
+
<tr>
|
66 |
+
<td><?php _e( 'Max. TTL:', 'redis-cache' ); ?></td>
|
67 |
+
<td><code><?php echo esc_html( $this->get_redis_maxttl() ); ?></code></td>
|
68 |
+
</tr>
|
69 |
+
<?php endif; ?>
|
70 |
+
</table>
|
71 |
</td>
|
72 |
</tr>
|
73 |
|
includes/object-cache.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A Redis backend for the WordPress Object Cache based on the Predis client library for PHP.
|
6 |
-
Version: 1.
|
7 |
Author: Till Krüss
|
8 |
Author URI: http://till.kruss.me/
|
9 |
License: GPLv3
|
@@ -264,6 +264,13 @@ class WP_Object_Cache {
|
|
264 |
*/
|
265 |
private $cache = array();
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
/**
|
268 |
* List of global groups.
|
269 |
*
|
@@ -311,12 +318,11 @@ class WP_Object_Cache {
|
|
311 |
*
|
312 |
* Instantiates the Redis class.
|
313 |
*
|
314 |
-
* @param
|
315 |
*/
|
316 |
public function __construct() {
|
317 |
global $blog_id, $table_prefix;
|
318 |
|
319 |
-
// General Redis settings
|
320 |
$redis = array(
|
321 |
'scheme' => 'tcp',
|
322 |
'host' => '127.0.0.1',
|
@@ -347,23 +353,79 @@ class WP_Object_Cache {
|
|
347 |
$redis[ 'database' ] = WP_REDIS_DATABASE;
|
348 |
}
|
349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
try {
|
351 |
|
352 |
-
if (
|
353 |
-
throw new Exception;
|
354 |
-
}
|
355 |
|
356 |
-
|
357 |
-
|
358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
|
360 |
-
|
361 |
|
362 |
-
|
|
|
|
|
363 |
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
} catch ( Exception $exception ) {
|
369 |
|
@@ -442,39 +504,35 @@ class WP_Object_Cache {
|
|
442 |
* @param int $expiration The expiration time, defaults to 0.
|
443 |
* @return bool Returns TRUE on success or FALSE on failure.
|
444 |
*/
|
|
|
445 |
protected function add_or_replace( $add, $key, $value, $group = 'default', $expiration = 0 ) {
|
446 |
$derived_key = $this->build_key( $key, $group );
|
|
|
447 |
|
448 |
-
//
|
449 |
-
if ( in_array( $group, $this->no_redis_groups )
|
|
|
450 |
|
451 |
-
|
452 |
-
if (
|
453 |
-
( $add && isset( $this->cache[ $derived_key ] ) ) ||
|
454 |
-
( ! $add && ! isset( $this->cache[ $derived_key ] ) )
|
455 |
-
) {
|
456 |
return false;
|
457 |
}
|
458 |
|
459 |
-
$this->
|
460 |
|
461 |
-
|
|
|
|
|
|
|
|
|
462 |
}
|
463 |
|
464 |
-
|
465 |
-
if (
|
466 |
-
( $add && $this->redis->exists( $derived_key ) ) ||
|
467 |
-
( ! $add && ! $this->redis->exists( $derived_key ) )
|
468 |
-
) {
|
469 |
return false;
|
470 |
}
|
471 |
|
472 |
-
|
473 |
-
|
474 |
-
if ( $expiration ) {
|
475 |
-
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, maybe_serialize( $value ) ) );
|
476 |
-
} else {
|
477 |
-
$result = $this->parse_predis_response( $this->redis->set( $derived_key, maybe_serialize( $value ) ) );
|
478 |
}
|
479 |
|
480 |
return $result;
|
@@ -490,20 +548,15 @@ class WP_Object_Cache {
|
|
490 |
public function delete( $key, $group = 'default' ) {
|
491 |
$derived_key = $this->build_key( $key, $group );
|
492 |
|
493 |
-
|
494 |
-
if (
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
return true;
|
499 |
-
} else {
|
500 |
-
return false;
|
501 |
-
}
|
502 |
}
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
|
508 |
return $result;
|
509 |
}
|
@@ -550,12 +603,12 @@ class WP_Object_Cache {
|
|
550 |
}
|
551 |
|
552 |
$result = $this->redis->get( $derived_key );
|
553 |
-
if ($result
|
554 |
$this->cache_misses++;
|
555 |
return false;
|
556 |
} else {
|
557 |
$this->cache_hits++;
|
558 |
-
$value = maybe_unserialize($result);
|
559 |
}
|
560 |
|
561 |
$this->add_to_internal_cache( $derived_key, $value );
|
@@ -638,20 +691,21 @@ class WP_Object_Cache {
|
|
638 |
*/
|
639 |
public function set( $key, $value, $group = 'default', $expiration = 0 ) {
|
640 |
$derived_key = $this->build_key( $key, $group );
|
|
|
641 |
|
642 |
-
//
|
643 |
-
if ( in_array( $group, $this->no_redis_groups )
|
644 |
-
$this->
|
645 |
-
|
646 |
-
|
|
|
|
|
|
|
647 |
}
|
648 |
|
649 |
-
//
|
650 |
-
|
651 |
-
|
652 |
-
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, maybe_serialize( $value ) ) );
|
653 |
-
} else {
|
654 |
-
$result = $this->parse_predis_response( $this->redis->set( $derived_key, maybe_serialize( $value ) ) );
|
655 |
}
|
656 |
|
657 |
return $result;
|
@@ -723,17 +777,17 @@ class WP_Object_Cache {
|
|
723 |
public function stats() { ?>
|
724 |
|
725 |
<p>
|
726 |
-
<strong
|
727 |
-
<strong
|
728 |
-
<strong
|
729 |
</p>
|
730 |
|
731 |
-
<p><strong
|
732 |
|
733 |
<ul>
|
734 |
-
<li><em
|
735 |
<?php foreach ( $this->cache as $group => $cache ) : ?>
|
736 |
-
<li><?php printf(
|
737 |
<?php endforeach; ?>
|
738 |
</ul><?php
|
739 |
|
@@ -873,53 +927,16 @@ class WP_Object_Cache {
|
|
873 |
}
|
874 |
|
875 |
/**
|
876 |
-
*
|
877 |
-
*
|
878 |
-
* Since this class may run befor the i18n methods are loaded in WP, we'll make sure they
|
879 |
-
* exist before using them. Most require a text domain, some don't, so the second param allows
|
880 |
-
* specifiying which type is being called.
|
881 |
-
*
|
882 |
-
* @param string $method The WP method to pass the string through if it exists.
|
883 |
-
* @param string $string The string to internationalize.
|
884 |
-
* @param bool $domain Whether or not to pass the text domain to the method as well.
|
885 |
-
* @param mixed $params Any extra param or array of params to send to the method.
|
886 |
-
* @return string The maybe internationalaized string.
|
887 |
-
*/
|
888 |
-
protected function _i18n( $method, $string, $domain = true, $params = array() ) {
|
889 |
-
// Pass through if the method doesn't exist.
|
890 |
-
if ( ! function_exists( $method ) ) {
|
891 |
-
return $string;
|
892 |
-
}
|
893 |
-
// Allow non-array single extra values
|
894 |
-
if ( ! is_array( $params ) ) {
|
895 |
-
$params = array( $params );
|
896 |
-
}
|
897 |
-
// Add domain param if needed.
|
898 |
-
if ( (bool) $domain ) {
|
899 |
-
array_unshift( $params, 'redis-cache' );
|
900 |
-
}
|
901 |
-
// Add the string
|
902 |
-
array_unshift( $params, $string );
|
903 |
-
|
904 |
-
return call_user_func_array( $method, $params );
|
905 |
-
}
|
906 |
-
|
907 |
-
/**
|
908 |
-
* Try to escape any HTML from output, if not available, strip tags.
|
909 |
*
|
910 |
-
*
|
911 |
-
* it will use the native strip_tags instead to simply remove them. This is needed since
|
912 |
-
* in some circumstances this may be loaded before esc_html is available.
|
913 |
-
*
|
914 |
-
* @param string $string The string to escape or strip.
|
915 |
-
* @return string The safe string for output.
|
916 |
*/
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
return strip_tags( $string );
|
922 |
}
|
|
|
923 |
}
|
924 |
|
925 |
}
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A Redis backend for the WordPress Object Cache based on the Predis client library for PHP.
|
6 |
+
Version: 1.1
|
7 |
Author: Till Krüss
|
8 |
Author URI: http://till.kruss.me/
|
9 |
License: GPLv3
|
264 |
*/
|
265 |
private $cache = array();
|
266 |
|
267 |
+
/**
|
268 |
+
* Name of the used Redis client
|
269 |
+
*
|
270 |
+
* @var bool
|
271 |
+
*/
|
272 |
+
public $redis_client = null;
|
273 |
+
|
274 |
/**
|
275 |
* List of global groups.
|
276 |
*
|
318 |
*
|
319 |
* Instantiates the Redis class.
|
320 |
*
|
321 |
+
* @param null $persistent_id To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance.
|
322 |
*/
|
323 |
public function __construct() {
|
324 |
global $blog_id, $table_prefix;
|
325 |
|
|
|
326 |
$redis = array(
|
327 |
'scheme' => 'tcp',
|
328 |
'host' => '127.0.0.1',
|
353 |
$redis[ 'database' ] = WP_REDIS_DATABASE;
|
354 |
}
|
355 |
|
356 |
+
$redis_client = defined( 'WP_REDIS_CLIENT' ) ? WP_REDIS_CLIENT : null;
|
357 |
+
|
358 |
+
if ( class_exists( 'Redis' ) && strcasecmp( 'predis', $redis_client ) !== 0 ) {
|
359 |
+
$redis_client = defined( 'HHVM_VERSION' ) ? 'hhvm' : 'pecl';
|
360 |
+
} else {
|
361 |
+
$redis_client = 'predis';
|
362 |
+
}
|
363 |
+
|
364 |
try {
|
365 |
|
366 |
+
if ( strcasecmp( 'hhvm', $redis_client ) === 0 ) {
|
|
|
|
|
367 |
|
368 |
+
$this->redis_client = sprintf( 'HHVM %s Extension', HHVM_VERSION );
|
369 |
+
$this->redis = new Redis();
|
370 |
+
|
371 |
+
// adjust host and port, if the scheme is `unix`
|
372 |
+
if ( strcasecmp( 'unix', $redis[ 'scheme' ] ) === 0 ) {
|
373 |
+
$redis[ 'host' ] = 'unix://' . $redis[ 'path' ];
|
374 |
+
$redis[ 'port' ] = 0;
|
375 |
+
}
|
376 |
+
|
377 |
+
if ( ! $this->redis->connect( $redis[ 'host' ], $redis[ 'port' ] ) ) {
|
378 |
+
throw new Exception;
|
379 |
+
}
|
380 |
+
|
381 |
+
$this->redis_connected = true;
|
382 |
+
|
383 |
+
} elseif ( strcasecmp( 'pecl', $redis_client ) === 0 ) {
|
384 |
+
|
385 |
+
$this->redis_client = 'PCEL Extension';
|
386 |
+
$this->redis = new Redis();
|
387 |
+
|
388 |
+
if ( strcasecmp( 'unix', $redis[ 'scheme' ] ) === 0 ) {
|
389 |
+
$this->redis->connect( $redis[ 'path' ] );
|
390 |
+
} else {
|
391 |
+
$this->redis->connect( $redis[ 'host' ], $redis[ 'port' ] );
|
392 |
+
}
|
393 |
+
|
394 |
+
if ( isset( $redis[ 'password' ] ) ) {
|
395 |
+
$this->redis->auth( $redis[ 'password' ] );
|
396 |
+
}
|
397 |
+
|
398 |
+
if ( isset( $redis[ 'database' ] ) ) {
|
399 |
+
$this->redis->select( $redis[ 'database' ] );
|
400 |
+
}
|
401 |
|
402 |
+
$this->redis_connected = true;
|
403 |
|
404 |
+
} else {
|
405 |
+
|
406 |
+
$this->redis_client = 'Predis';
|
407 |
|
408 |
+
// require PHP 5.4 or greater
|
409 |
+
if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
|
410 |
+
throw new Exception;
|
411 |
+
}
|
412 |
+
|
413 |
+
// check if bundled Predis library exists
|
414 |
+
if ( ! realpath( dirname( __FILE__ ) . '/plugins/redis-cache/includes/predis.php' ) ) {
|
415 |
+
throw new Exception;
|
416 |
+
}
|
417 |
+
|
418 |
+
require_once dirname( __FILE__ ) . '/plugins/redis-cache/includes/predis.php';
|
419 |
+
|
420 |
+
Predis\Autoloader::register();
|
421 |
+
|
422 |
+
$this->redis = new Predis\Client( $redis );
|
423 |
+
$this->redis->connect();
|
424 |
+
|
425 |
+
$this->redis_connected = true;
|
426 |
+
$this->redis_client .= ' v' . Predis\Client::VERSION;
|
427 |
+
|
428 |
+
}
|
429 |
|
430 |
} catch ( Exception $exception ) {
|
431 |
|
504 |
* @param int $expiration The expiration time, defaults to 0.
|
505 |
* @return bool Returns TRUE on success or FALSE on failure.
|
506 |
*/
|
507 |
+
|
508 |
protected function add_or_replace( $add, $key, $value, $group = 'default', $expiration = 0 ) {
|
509 |
$derived_key = $this->build_key( $key, $group );
|
510 |
+
$result = true;
|
511 |
|
512 |
+
// save if group not excluded and redis is up
|
513 |
+
if ( ! in_array( $group, $this->no_redis_groups ) && $this->redis_status() ) {
|
514 |
+
$exists = $this->redis->exists( $derived_key );
|
515 |
|
516 |
+
if ( $add === $exists ) {
|
|
|
|
|
|
|
|
|
517 |
return false;
|
518 |
}
|
519 |
|
520 |
+
$expiration = $this->validate_expiration( $expiration );
|
521 |
|
522 |
+
if ( $expiration ) {
|
523 |
+
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, maybe_serialize( $value ) ) );
|
524 |
+
} else {
|
525 |
+
$result = $this->parse_predis_response( $this->redis->set( $derived_key, maybe_serialize( $value ) ) );
|
526 |
+
}
|
527 |
}
|
528 |
|
529 |
+
$exists = isset( $this->cache[ $derived_key ] );
|
530 |
+
if ( $add === $exists ) {
|
|
|
|
|
|
|
531 |
return false;
|
532 |
}
|
533 |
|
534 |
+
if ( $result ) {
|
535 |
+
$this->add_to_internal_cache( $derived_key, $value );
|
|
|
|
|
|
|
|
|
536 |
}
|
537 |
|
538 |
return $result;
|
548 |
public function delete( $key, $group = 'default' ) {
|
549 |
$derived_key = $this->build_key( $key, $group );
|
550 |
|
551 |
+
$result = false;
|
552 |
+
if ( isset( $this->cache[ $derived_key ] ) ) {
|
553 |
+
unset( $this->cache[ $derived_key ] );
|
554 |
+
$result = true;
|
|
|
|
|
|
|
|
|
|
|
555 |
}
|
556 |
|
557 |
+
if ( $this->redis_status() && ! in_array( $group, $this->no_redis_groups ) ) {
|
558 |
+
$result = $this->parse_predis_response( $this->redis->del( $derived_key ) );
|
559 |
+
}
|
560 |
|
561 |
return $result;
|
562 |
}
|
603 |
}
|
604 |
|
605 |
$result = $this->redis->get( $derived_key );
|
606 |
+
if ($result === NULL) {
|
607 |
$this->cache_misses++;
|
608 |
return false;
|
609 |
} else {
|
610 |
$this->cache_hits++;
|
611 |
+
$value = maybe_unserialize( $result );
|
612 |
}
|
613 |
|
614 |
$this->add_to_internal_cache( $derived_key, $value );
|
691 |
*/
|
692 |
public function set( $key, $value, $group = 'default', $expiration = 0 ) {
|
693 |
$derived_key = $this->build_key( $key, $group );
|
694 |
+
$result = true;
|
695 |
|
696 |
+
// save if group not excluded from redis and redis is up
|
697 |
+
if ( ! in_array( $group, $this->no_redis_groups ) && $this->redis_status() ) {
|
698 |
+
$expiration = $this->validate_expiration($expiration);
|
699 |
+
if ( $expiration ) {
|
700 |
+
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, maybe_serialize( $value ) ) );
|
701 |
+
} else {
|
702 |
+
$result = $this->parse_predis_response( $this->redis->set( $derived_key, maybe_serialize( $value ) ) );
|
703 |
+
}
|
704 |
}
|
705 |
|
706 |
+
// if the set was successful, or we didn't go to redis
|
707 |
+
if ( $result ) {
|
708 |
+
$this->add_to_internal_cache( $derived_key, $value );
|
|
|
|
|
|
|
709 |
}
|
710 |
|
711 |
return $result;
|
777 |
public function stats() { ?>
|
778 |
|
779 |
<p>
|
780 |
+
<strong>Cache Status:</strong> <?php echo $this->redis_status() ? 'Connected' : 'Not connected'; ?><br />
|
781 |
+
<strong>Cache Hits:</strong> <?php echo $this->cache_hits; ?><br />
|
782 |
+
<strong>Cache Misses:</strong> <?php echo $this->cache_misses; ?>
|
783 |
</p>
|
784 |
|
785 |
+
<p><strong>Caches Retrieved:</strong></p>
|
786 |
|
787 |
<ul>
|
788 |
+
<li><em>prefix:group:key - size in kilobytes</em></li>
|
789 |
<?php foreach ( $this->cache as $group => $cache ) : ?>
|
790 |
+
<li><?php printf( '%s - %s kb', strip_tags( $group ), number_format( strlen( serialize( $cache ) ) / 1024, 2 ) ); ?></li>
|
791 |
<?php endforeach; ?>
|
792 |
</ul><?php
|
793 |
|
927 |
}
|
928 |
|
929 |
/**
|
930 |
+
* Wrapper to validate the cache keys expiration value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
931 |
*
|
932 |
+
* @param mixed $expiration Incomming expiration value (whatever it is)
|
|
|
|
|
|
|
|
|
|
|
933 |
*/
|
934 |
+
protected function validate_expiration( $expiration ) {
|
935 |
+
$expiration = ( is_array( $expiration ) || is_object( $expiration ) ? 0 : abs( intval( $expiration ) ) );
|
936 |
+
if ( $expiration === 0 && defined( 'WP_REDIS_MAXTTL' ) ) {
|
937 |
+
$expiration = intval( WP_REDIS_MAXTTL );
|
|
|
938 |
}
|
939 |
+
return $expiration;
|
940 |
}
|
941 |
|
942 |
}
|
languages/redis-cache.pot
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
# This file is distributed under the same license as the Redis Object Cache package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: Redis Object Cache 1.
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/redis-cache\n"
|
7 |
-
"POT-Creation-Date: 2015-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -12,7 +12,7 @@ msgstr ""
|
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
-
#. #-#-#-#-# plugin.pot (Redis Object Cache 1.
|
16 |
#. Plugin Name of the plugin/theme
|
17 |
#: includes/admin-page.php:6 redis-cache.php:42
|
18 |
msgid "Redis Object Cache"
|
@@ -23,42 +23,54 @@ msgid "Redis Status"
|
|
23 |
msgstr ""
|
24 |
|
25 |
#: includes/admin-page.php:18
|
26 |
-
msgid "
|
27 |
msgstr ""
|
28 |
|
29 |
-
#: includes/admin-page.php:
|
|
|
|
|
|
|
|
|
30 |
msgid "Protocol:"
|
31 |
msgstr ""
|
32 |
|
33 |
-
#: includes/admin-page.php:
|
34 |
msgid "Host:"
|
35 |
msgstr ""
|
36 |
|
37 |
-
#: includes/admin-page.php:
|
38 |
msgid "Port:"
|
39 |
msgstr ""
|
40 |
|
41 |
-
#: includes/admin-page.php:
|
42 |
msgid "Path:"
|
43 |
msgstr ""
|
44 |
|
45 |
-
#: includes/admin-page.php:
|
46 |
msgid "Database:"
|
47 |
msgstr ""
|
48 |
|
49 |
-
#: includes/admin-page.php:
|
50 |
msgid "Password:"
|
51 |
msgstr ""
|
52 |
|
53 |
-
#: includes/admin-page.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
msgid "Flush Cache"
|
55 |
msgstr ""
|
56 |
|
57 |
-
#: includes/admin-page.php:
|
58 |
msgid "Enable Object Cache"
|
59 |
msgstr ""
|
60 |
|
61 |
-
#: includes/admin-page.php:
|
62 |
msgid "Disable Object Cache"
|
63 |
msgstr ""
|
64 |
|
@@ -66,66 +78,66 @@ msgstr ""
|
|
66 |
msgid "Redis"
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: redis-cache.php:
|
70 |
-
msgid "
|
71 |
msgstr ""
|
72 |
|
73 |
-
#: redis-cache.php:
|
74 |
msgid "Connected"
|
75 |
msgstr ""
|
76 |
|
77 |
-
#: redis-cache.php:
|
78 |
msgid "Not connected"
|
79 |
msgstr ""
|
80 |
|
81 |
-
#: redis-cache.php:
|
82 |
msgid "Unknown"
|
83 |
msgstr ""
|
84 |
|
85 |
-
#: redis-cache.php:
|
86 |
msgid ""
|
87 |
"The Redis object cache drop-in is outdated. <a href=\"%s\">Update it now</a>."
|
88 |
msgstr ""
|
89 |
|
90 |
-
#: redis-cache.php:
|
91 |
msgid ""
|
92 |
"Another object cache drop-in is already active. To use Redis, <a href=\"%s"
|
93 |
"\">please replace it now</a>."
|
94 |
msgstr ""
|
95 |
|
96 |
-
#: redis-cache.php:
|
97 |
msgid "This plugin requires PHP 5.4 or greater."
|
98 |
msgstr ""
|
99 |
|
100 |
-
#: redis-cache.php:
|
101 |
msgid "Object Cache enabled."
|
102 |
msgstr ""
|
103 |
|
104 |
-
#: redis-cache.php:
|
105 |
msgid "Object Cache could not be enabled."
|
106 |
msgstr ""
|
107 |
|
108 |
-
#: redis-cache.php:
|
109 |
msgid "Object Cache disabled."
|
110 |
msgstr ""
|
111 |
|
112 |
-
#: redis-cache.php:
|
113 |
msgid "Object Cache could not be disabled."
|
114 |
msgstr ""
|
115 |
|
116 |
-
#: redis-cache.php:
|
117 |
msgid "Object Cache flushed."
|
118 |
msgstr ""
|
119 |
|
120 |
-
#: redis-cache.php:
|
121 |
msgid "Object Cache could not be flushed."
|
122 |
msgstr ""
|
123 |
|
124 |
-
#: redis-cache.php:
|
125 |
msgid "Drop-in updated."
|
126 |
msgstr ""
|
127 |
|
128 |
-
#: redis-cache.php:
|
129 |
msgid "Drop-in could not be updated."
|
130 |
msgstr ""
|
131 |
|
2 |
# This file is distributed under the same license as the Redis Object Cache package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: Redis Object Cache 1.1\n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/redis-cache\n"
|
7 |
+
"POT-Creation-Date: 2015-03-21 08:52:49+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
+
#. #-#-#-#-# plugin.pot (Redis Object Cache 1.1) #-#-#-#-#
|
16 |
#. Plugin Name of the plugin/theme
|
17 |
#: includes/admin-page.php:6 redis-cache.php:42
|
18 |
msgid "Redis Object Cache"
|
23 |
msgstr ""
|
24 |
|
25 |
#: includes/admin-page.php:18
|
26 |
+
msgid "Configuration"
|
27 |
msgstr ""
|
28 |
|
29 |
+
#: includes/admin-page.php:23
|
30 |
+
msgid "Client:"
|
31 |
+
msgstr ""
|
32 |
+
|
33 |
+
#: includes/admin-page.php:28
|
34 |
msgid "Protocol:"
|
35 |
msgstr ""
|
36 |
|
37 |
+
#: includes/admin-page.php:33
|
38 |
msgid "Host:"
|
39 |
msgstr ""
|
40 |
|
41 |
+
#: includes/admin-page.php:38
|
42 |
msgid "Port:"
|
43 |
msgstr ""
|
44 |
|
45 |
+
#: includes/admin-page.php:44
|
46 |
msgid "Path:"
|
47 |
msgstr ""
|
48 |
|
49 |
+
#: includes/admin-page.php:49
|
50 |
msgid "Database:"
|
51 |
msgstr ""
|
52 |
|
53 |
+
#: includes/admin-page.php:54
|
54 |
msgid "Password:"
|
55 |
msgstr ""
|
56 |
|
57 |
+
#: includes/admin-page.php:60
|
58 |
+
msgid "Key Prefix:"
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
#: includes/admin-page.php:66
|
62 |
+
msgid "Max. TTL:"
|
63 |
+
msgstr ""
|
64 |
+
|
65 |
+
#: includes/admin-page.php:79
|
66 |
msgid "Flush Cache"
|
67 |
msgstr ""
|
68 |
|
69 |
+
#: includes/admin-page.php:84
|
70 |
msgid "Enable Object Cache"
|
71 |
msgstr ""
|
72 |
|
73 |
+
#: includes/admin-page.php:86
|
74 |
msgid "Disable Object Cache"
|
75 |
msgstr ""
|
76 |
|
78 |
msgid "Redis"
|
79 |
msgstr ""
|
80 |
|
81 |
+
#: redis-cache.php:149
|
82 |
+
msgid "Not installed"
|
83 |
msgstr ""
|
84 |
|
85 |
+
#: redis-cache.php:153
|
86 |
msgid "Connected"
|
87 |
msgstr ""
|
88 |
|
89 |
+
#: redis-cache.php:153
|
90 |
msgid "Not connected"
|
91 |
msgstr ""
|
92 |
|
93 |
+
#: redis-cache.php:156
|
94 |
msgid "Unknown"
|
95 |
msgstr ""
|
96 |
|
97 |
+
#: redis-cache.php:178
|
98 |
msgid ""
|
99 |
"The Redis object cache drop-in is outdated. <a href=\"%s\">Update it now</a>."
|
100 |
msgstr ""
|
101 |
|
102 |
+
#: redis-cache.php:184
|
103 |
msgid ""
|
104 |
"Another object cache drop-in is already active. To use Redis, <a href=\"%s"
|
105 |
"\">please replace it now</a>."
|
106 |
msgstr ""
|
107 |
|
108 |
+
#: redis-cache.php:200
|
109 |
msgid "This plugin requires PHP 5.4 or greater."
|
110 |
msgstr ""
|
111 |
|
112 |
+
#: redis-cache.php:209
|
113 |
msgid "Object Cache enabled."
|
114 |
msgstr ""
|
115 |
|
116 |
+
#: redis-cache.php:212
|
117 |
msgid "Object Cache could not be enabled."
|
118 |
msgstr ""
|
119 |
|
120 |
+
#: redis-cache.php:215
|
121 |
msgid "Object Cache disabled."
|
122 |
msgstr ""
|
123 |
|
124 |
+
#: redis-cache.php:218
|
125 |
msgid "Object Cache could not be disabled."
|
126 |
msgstr ""
|
127 |
|
128 |
+
#: redis-cache.php:221
|
129 |
msgid "Object Cache flushed."
|
130 |
msgstr ""
|
131 |
|
132 |
+
#: redis-cache.php:224
|
133 |
msgid "Object Cache could not be flushed."
|
134 |
msgstr ""
|
135 |
|
136 |
+
#: redis-cache.php:227
|
137 |
msgid "Drop-in updated."
|
138 |
msgstr ""
|
139 |
|
140 |
+
#: redis-cache.php:230
|
141 |
msgid "Drop-in could not be updated."
|
142 |
msgstr ""
|
143 |
|
readme.txt
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
=== Redis Object Cache ===
|
2 |
Contributors: tillkruess
|
3 |
Donate link: http://till.kruss.me/donations/
|
4 |
-
Tags: redis, predis, caching, cache, object cache, wp object cache, server, performance, optimize, speed, load
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.2
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
-
A persistent object cache backend powered by Redis and the Predis library for PHP.
|
12 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
-
A persistent object cache backend powered by [Redis](
|
17 |
|
18 |
To adjust the connection parameters or prefixing cache keys, see [Other Notes](http://wordpress.org/extend/plugins/redis-cache/other_notes/).
|
19 |
|
20 |
-
Forked from Eric Mann's and Erick Hitter's [Redis Object Cache](https://github.com/ericmann/Redis-Object-Cache)
|
21 |
|
22 |
|
23 |
== Installation ==
|
@@ -36,9 +36,13 @@ By default the object cache drop-in will connect to Redis over TCP at `127.0.0.1
|
|
36 |
|
37 |
To adjust the connection parameters, define the following constants in your `wp-config.php`.
|
38 |
|
|
|
|
|
|
|
|
|
39 |
* `WP_REDIS_SCHEME` [default: `tcp`]
|
40 |
|
41 |
-
Specifies the protocol used to communicate with an instance of Redis. Internally the client uses the connection class associated to the specified connection scheme.
|
42 |
|
43 |
* `WP_REDIS_HOST` [default: `127.0.0.1`]
|
44 |
|
@@ -54,12 +58,16 @@ To adjust the connection parameters, define the following constants in your `wp-
|
|
54 |
|
55 |
* `WP_REDIS_DATABASE` [default: `0`]
|
56 |
|
57 |
-
Accepts a numeric value that is used
|
58 |
|
59 |
* `WP_REDIS_PASSWORD` [default: not set]
|
60 |
|
61 |
Accepts a value used to authenticate with a Redis server protected by password with the `AUTH` command.
|
62 |
|
|
|
|
|
|
|
|
|
63 |
|
64 |
== Prefixing Cache Keys ==
|
65 |
|
@@ -75,6 +83,16 @@ Users with setups where multiple installs share a common `wp-config.php` or `$ta
|
|
75 |
|
76 |
== Changelog ==
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
= 1.0.2 =
|
79 |
|
80 |
* Added "Flush Cache" button
|
@@ -97,6 +115,10 @@ Users with setups where multiple installs share a common `wp-config.php` or `$ta
|
|
97 |
|
98 |
== Upgrade Notice ==
|
99 |
|
|
|
|
|
|
|
|
|
100 |
= 1.0.2 =
|
101 |
|
102 |
This update includes significant speed improvements and support for UNIX domain sockets.
|
1 |
=== Redis Object Cache ===
|
2 |
Contributors: tillkruess
|
3 |
Donate link: http://till.kruss.me/donations/
|
4 |
+
Tags: redis, predis, hhvm, pecl, caching, cache, object cache, wp object cache, server, performance, optimize, speed, load
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.2
|
7 |
+
Stable tag: 1.1
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
+
A persistent object cache backend powered by Redis. Supports HHVM's Redis extension, the PCEL Redis Extension and the Predis library for PHP.
|
12 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
+
A persistent object cache backend powered by Redis. Supports [HHVM's Redis extension](https://github.com/facebook/hhvm/tree/master/hphp/system/php/redis), the [PCEL Redis Extension](https://github.com/phpredis/phpredis) and the [Predis](https://github.com/nrk/predis/) library for PHP *(Predis requires PHP 5.4 or greater)*.
|
17 |
|
18 |
To adjust the connection parameters or prefixing cache keys, see [Other Notes](http://wordpress.org/extend/plugins/redis-cache/other_notes/).
|
19 |
|
20 |
+
Forked from Eric Mann's and Erick Hitter's [Redis Object Cache](https://github.com/ericmann/Redis-Object-Cache).
|
21 |
|
22 |
|
23 |
== Installation ==
|
36 |
|
37 |
To adjust the connection parameters, define the following constants in your `wp-config.php`.
|
38 |
|
39 |
+
* `WP_REDIS_CLIENT` [default: not set]
|
40 |
+
|
41 |
+
Specifies the client used to communicate with Redis. Supports `hhvm`, `pecl` and `predis`.
|
42 |
+
|
43 |
* `WP_REDIS_SCHEME` [default: `tcp`]
|
44 |
|
45 |
+
Specifies the protocol used to communicate with an instance of Redis. Internally the client uses the connection class associated to the specified connection scheme. Supports `tcp` (TCP/IP), `unix` (UNIX domain sockets) or `http` (HTTP protocol through Webdis).
|
46 |
|
47 |
* `WP_REDIS_HOST` [default: `127.0.0.1`]
|
48 |
|
58 |
|
59 |
* `WP_REDIS_DATABASE` [default: `0`]
|
60 |
|
61 |
+
Accepts a numeric value that is used to automatically select a logical database with the `SELECT` command.
|
62 |
|
63 |
* `WP_REDIS_PASSWORD` [default: not set]
|
64 |
|
65 |
Accepts a value used to authenticate with a Redis server protected by password with the `AUTH` command.
|
66 |
|
67 |
+
* `WP_REDIS_MAXTTL` [default: not set]
|
68 |
+
|
69 |
+
Set maximum time-to-live (in seconds) for cache keys with an expiration time of `0`.
|
70 |
+
|
71 |
|
72 |
== Prefixing Cache Keys ==
|
73 |
|
83 |
|
84 |
== Changelog ==
|
85 |
|
86 |
+
= 1.1 =
|
87 |
+
|
88 |
+
* Added support for HHVM's Redis extension
|
89 |
+
* Added support for PCEL Redis extension
|
90 |
+
* Added `WP_REDIS_CLIENT` constant, to set prefered Redis client
|
91 |
+
* Added `WP_REDIS_MAXTTL` constant, to force expiration of cache keys
|
92 |
+
* Improved `add_or_replace()`, `get()`, `set()` and `delete()` methods
|
93 |
+
* Improved admin screen styles
|
94 |
+
* Removed all internationalization/localization from drop-in
|
95 |
+
|
96 |
= 1.0.2 =
|
97 |
|
98 |
* Added "Flush Cache" button
|
115 |
|
116 |
== Upgrade Notice ==
|
117 |
|
118 |
+
= 1.1 =
|
119 |
+
|
120 |
+
This update includes bug fixes and adds supports for HHVM/PCEL Redis extensions.
|
121 |
+
|
122 |
= 1.0.2 =
|
123 |
|
124 |
This update includes significant speed improvements and support for UNIX domain sockets.
|
redis-cache.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A Redis backend for the WordPress Object Cache based on the Predis client library for PHP.
|
6 |
-
Version: 1.
|
7 |
Text Domain: redis-cache
|
8 |
Domain Path: /languages
|
9 |
Author: Till Krüss
|
@@ -104,6 +104,11 @@ class RedisObjectCache {
|
|
104 |
return $this->object_cache_dropin_exists() && method_exists( $GLOBALS[ 'wp_object_cache' ], 'redis_status' );
|
105 |
}
|
106 |
|
|
|
|
|
|
|
|
|
|
|
107 |
public function get_redis_scheme() {
|
108 |
return defined( 'WP_REDIS_SCHEME' ) ? WP_REDIS_SCHEME : 'tcp';
|
109 |
}
|
@@ -128,12 +133,20 @@ class RedisObjectCache {
|
|
128 |
return defined( 'WP_REDIS_PASSWORD' ) ? WP_REDIS_PASSWORD : null;
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
public function get_redis_status() {
|
132 |
|
133 |
global $wp_object_cache;
|
134 |
|
135 |
if ( ! $this->object_cache_dropin_exists() ) {
|
136 |
-
return __( '
|
137 |
}
|
138 |
|
139 |
if ( $this->validate_object_cache_dropin() ) {
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A Redis backend for the WordPress Object Cache based on the Predis client library for PHP.
|
6 |
+
Version: 1.1
|
7 |
Text Domain: redis-cache
|
8 |
Domain Path: /languages
|
9 |
Author: Till Krüss
|
104 |
return $this->object_cache_dropin_exists() && method_exists( $GLOBALS[ 'wp_object_cache' ], 'redis_status' );
|
105 |
}
|
106 |
|
107 |
+
public function get_redis_client_name() {
|
108 |
+
global $wp_object_cache;
|
109 |
+
return $wp_object_cache->redis_client;
|
110 |
+
}
|
111 |
+
|
112 |
public function get_redis_scheme() {
|
113 |
return defined( 'WP_REDIS_SCHEME' ) ? WP_REDIS_SCHEME : 'tcp';
|
114 |
}
|
133 |
return defined( 'WP_REDIS_PASSWORD' ) ? WP_REDIS_PASSWORD : null;
|
134 |
}
|
135 |
|
136 |
+
public function get_redis_cachekey_prefix() {
|
137 |
+
return defined( 'WP_CACHE_KEY_SALT' ) ? WP_CACHE_KEY_SALT : null;
|
138 |
+
}
|
139 |
+
|
140 |
+
public function get_redis_maxttl() {
|
141 |
+
return defined( 'WP_REDIS_MAXTTL' ) ? WP_REDIS_MAXTTL : null;
|
142 |
+
}
|
143 |
+
|
144 |
public function get_redis_status() {
|
145 |
|
146 |
global $wp_object_cache;
|
147 |
|
148 |
if ( ! $this->object_cache_dropin_exists() ) {
|
149 |
+
return __( 'Not installed', 'redis-cache' );
|
150 |
}
|
151 |
|
152 |
if ( $this->validate_object_cache_dropin() ) {
|