Version Description
- Added support for PhpRedis TLS connections
- Added support for timeout, read timeout and password when using PhpRedis cluster
- Fixed issue with
INFO
command - Fixed object cloning when setting cache keys
Download this release
Release Info
Developer | tillkruess |
Plugin | Redis Object Cache |
Version | 1.5.7 |
Comparing to | |
See all releases |
Code changes from version 1.5.6 to 1.5.7
- includes/diagnostics.php +6 -2
- includes/object-cache.php +46 -21
- readme.txt +9 -2
- redis-cache.php +2 -2
includes/diagnostics.php
CHANGED
@@ -1,14 +1,16 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
3 |
global $wp_object_cache;
|
4 |
|
5 |
$info = $plugins = $dropins = array();
|
6 |
$dropin = $this->validate_object_cache_dropin() && ( ! defined('WP_REDIS_DISABLED') || ! WP_REDIS_DISABLED );
|
7 |
|
8 |
$info[ 'Status' ] = $this->get_status();
|
9 |
-
$info[ 'Redis Version' ] = $this->get_redis_version() ?: 'Unknown';
|
10 |
$info[ 'Client' ] = $this->get_redis_client_name();
|
11 |
-
|
12 |
$info[ 'Drop-in' ] = $dropin ? 'Valid' : 'Invalid';
|
13 |
|
14 |
if ( $dropin ) {
|
@@ -31,6 +33,8 @@ if ( defined( 'HHVM_VERSION' ) ) {
|
|
31 |
$info[ 'HHVM Version' ] = HHVM_VERSION;
|
32 |
}
|
33 |
|
|
|
|
|
34 |
$info[ 'Multisite' ] = is_multisite() ? 'Yes' : 'No';
|
35 |
|
36 |
if ( $dropin ) {
|
1 |
<?php
|
2 |
|
3 |
+
// TODO: detect constants being defined too late...
|
4 |
+
// open config file, strpos()
|
5 |
+
// defined to late, or commented out...
|
6 |
+
|
7 |
global $wp_object_cache;
|
8 |
|
9 |
$info = $plugins = $dropins = array();
|
10 |
$dropin = $this->validate_object_cache_dropin() && ( ! defined('WP_REDIS_DISABLED') || ! WP_REDIS_DISABLED );
|
11 |
|
12 |
$info[ 'Status' ] = $this->get_status();
|
|
|
13 |
$info[ 'Client' ] = $this->get_redis_client_name();
|
|
|
14 |
$info[ 'Drop-in' ] = $dropin ? 'Valid' : 'Invalid';
|
15 |
|
16 |
if ( $dropin ) {
|
33 |
$info[ 'HHVM Version' ] = HHVM_VERSION;
|
34 |
}
|
35 |
|
36 |
+
$info[ 'Redis Version' ] = $this->get_redis_version() ?: 'Unknown';
|
37 |
+
|
38 |
$info[ 'Multisite' ] = is_multisite() ? 'Yes' : 'No';
|
39 |
|
40 |
if ( $dropin ) {
|
includes/object-cache.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Redis Object Cache Drop-In
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
|
6 |
-
Version: 1.5.
|
7 |
Author: Till Krüss
|
8 |
Author URI: https://till.im/
|
9 |
License: GPLv3
|
@@ -466,7 +466,18 @@ class WP_Object_Cache
|
|
466 |
if (defined('WP_REDIS_SHARDS')) {
|
467 |
$this->redis = new RedisArray(array_values(WP_REDIS_SHARDS));
|
468 |
} elseif (defined('WP_REDIS_CLUSTER')) {
|
469 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
} else {
|
471 |
$this->redis = new Redis();
|
472 |
|
@@ -478,17 +489,25 @@ class WP_Object_Cache
|
|
478 |
$parameters['retry_interval'],
|
479 |
];
|
480 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
if (strcasecmp('unix', $parameters['scheme']) === 0) {
|
482 |
$connection_args[0] = $parameters['path'];
|
483 |
$connection_args[1] = null;
|
484 |
}
|
485 |
|
486 |
-
if (version_compare($phpredis_version,'3.1.3','>=')){
|
487 |
$connection_args[] = $parameters['read_timeout'];
|
488 |
}
|
489 |
|
490 |
call_user_func_array(
|
491 |
-
[
|
492 |
$connection_args
|
493 |
);
|
494 |
}
|
@@ -573,12 +592,12 @@ class WP_Object_Cache
|
|
573 |
}
|
574 |
|
575 |
if ( ! isset( $options['replication'] ) || ! $options['replication'] ) {
|
576 |
-
$
|
577 |
|
578 |
-
if (isset($
|
579 |
-
$this->redis_version = $
|
580 |
-
} elseif (isset(
|
581 |
-
$this->redis_version = $
|
582 |
}
|
583 |
}
|
584 |
|
@@ -973,7 +992,7 @@ LUA;
|
|
973 |
$found = true;
|
974 |
$this->cache_hits++;
|
975 |
|
976 |
-
return
|
977 |
} elseif (in_array($group, $this->ignored_groups) || ! $this->redis_status()) {
|
978 |
$found = false;
|
979 |
$this->cache_misses++;
|
@@ -1002,10 +1021,7 @@ LUA;
|
|
1002 |
|
1003 |
$this->add_to_internal_cache($derived_key, $value);
|
1004 |
|
1005 |
-
$value = is_object($value) ? clone $value : $value;
|
1006 |
-
|
1007 |
if (function_exists('do_action')) {
|
1008 |
-
|
1009 |
$execute_time = microtime(true) - $start_time;
|
1010 |
|
1011 |
do_action('redis_object_cache_get', $key, $value, $group, $force, $found, $execute_time);
|
@@ -1329,20 +1345,22 @@ LUA;
|
|
1329 |
/**
|
1330 |
* Get a value specifically from the internal, run-time cache, not Redis.
|
1331 |
*
|
1332 |
-
* @param int|string $
|
1333 |
-
* @param int|string $group
|
1334 |
*
|
1335 |
* @return bool|mixed Value on success; false on failure.
|
1336 |
*/
|
1337 |
-
public function get_from_internal_cache($
|
1338 |
{
|
1339 |
-
|
|
|
|
|
1340 |
|
1341 |
-
if (
|
1342 |
-
return $this->cache[$derived_key];
|
1343 |
}
|
1344 |
|
1345 |
-
return
|
1346 |
}
|
1347 |
|
1348 |
/**
|
@@ -1440,7 +1458,9 @@ LUA;
|
|
1440 |
|
1441 |
// don't attempt to unserialize data that wasn't serialized going in
|
1442 |
if ($this->is_serialized($original)) {
|
1443 |
-
|
|
|
|
|
1444 |
}
|
1445 |
|
1446 |
return $original;
|
@@ -1448,11 +1468,16 @@ LUA;
|
|
1448 |
|
1449 |
/**
|
1450 |
* Serialize data, if needed.
|
|
|
1451 |
* @param string|array|object $data Data that might be serialized.
|
1452 |
* @return mixed A scalar data
|
1453 |
*/
|
1454 |
protected function maybe_serialize($data)
|
1455 |
{
|
|
|
|
|
|
|
|
|
1456 |
if (defined('WP_REDIS_SERIALIZER') && ! empty(WP_REDIS_SERIALIZER)) {
|
1457 |
return $data;
|
1458 |
}
|
3 |
Plugin Name: Redis Object Cache Drop-In
|
4 |
Plugin URI: http://wordpress.org/plugins/redis-cache/
|
5 |
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
|
6 |
+
Version: 1.5.7
|
7 |
Author: Till Krüss
|
8 |
Author URI: https://till.im/
|
9 |
License: GPLv3
|
466 |
if (defined('WP_REDIS_SHARDS')) {
|
467 |
$this->redis = new RedisArray(array_values(WP_REDIS_SHARDS));
|
468 |
} elseif (defined('WP_REDIS_CLUSTER')) {
|
469 |
+
$connection_args = [
|
470 |
+
null,
|
471 |
+
array_values(WP_REDIS_CLUSTER),
|
472 |
+
$parameters['timeout'],
|
473 |
+
$parameters['read_timeout'],
|
474 |
+
];
|
475 |
+
|
476 |
+
if (isset($parameters['password']) && version_compare($phpredis_version, '4.3.0', '>=')) {
|
477 |
+
$connection_args[] = $parameters['password'];
|
478 |
+
}
|
479 |
+
|
480 |
+
$this->redis = new RedisCluster(...$connection_args);
|
481 |
} else {
|
482 |
$this->redis = new Redis();
|
483 |
|
489 |
$parameters['retry_interval'],
|
490 |
];
|
491 |
|
492 |
+
if (strcasecmp('tls', $parameters['scheme']) === 0) {
|
493 |
+
$connection_args[0] = sprintf(
|
494 |
+
'%s://%s',
|
495 |
+
$parameters['scheme'],
|
496 |
+
str_replace('tls://', '', $parameters['host'])
|
497 |
+
);
|
498 |
+
}
|
499 |
+
|
500 |
if (strcasecmp('unix', $parameters['scheme']) === 0) {
|
501 |
$connection_args[0] = $parameters['path'];
|
502 |
$connection_args[1] = null;
|
503 |
}
|
504 |
|
505 |
+
if (version_compare($phpredis_version, '3.1.3', '>=')) {
|
506 |
$connection_args[] = $parameters['read_timeout'];
|
507 |
}
|
508 |
|
509 |
call_user_func_array(
|
510 |
+
[$this->redis, 'connect'],
|
511 |
$connection_args
|
512 |
);
|
513 |
}
|
592 |
}
|
593 |
|
594 |
if ( ! isset( $options['replication'] ) || ! $options['replication'] ) {
|
595 |
+
$info = $this->redis->info();
|
596 |
|
597 |
+
if (isset($info['redis_version'])) {
|
598 |
+
$this->redis_version = $info['redis_version'];
|
599 |
+
} elseif (isset($info['Server']['redis_version'])) {
|
600 |
+
$this->redis_version = $info['Server']['redis_version'];
|
601 |
}
|
602 |
}
|
603 |
|
992 |
$found = true;
|
993 |
$this->cache_hits++;
|
994 |
|
995 |
+
return $this->get_from_internal_cache($derived_key, $group);
|
996 |
} elseif (in_array($group, $this->ignored_groups) || ! $this->redis_status()) {
|
997 |
$found = false;
|
998 |
$this->cache_misses++;
|
1021 |
|
1022 |
$this->add_to_internal_cache($derived_key, $value);
|
1023 |
|
|
|
|
|
1024 |
if (function_exists('do_action')) {
|
|
|
1025 |
$execute_time = microtime(true) - $start_time;
|
1026 |
|
1027 |
do_action('redis_object_cache_get', $key, $value, $group, $force, $found, $execute_time);
|
1345 |
/**
|
1346 |
* Get a value specifically from the internal, run-time cache, not Redis.
|
1347 |
*
|
1348 |
+
* @param int|string $derived_key Key value.
|
1349 |
+
* @param int|string $group Group that the value belongs to.
|
1350 |
*
|
1351 |
* @return bool|mixed Value on success; false on failure.
|
1352 |
*/
|
1353 |
+
public function get_from_internal_cache($derived_key, $group)
|
1354 |
{
|
1355 |
+
if (! isset($this->cache[$derived_key])) {
|
1356 |
+
return false;
|
1357 |
+
}
|
1358 |
|
1359 |
+
if (is_object($this->cache[$derived_key])) {
|
1360 |
+
return clone $this->cache[$derived_key];
|
1361 |
}
|
1362 |
|
1363 |
+
return $this->cache[$derived_key];
|
1364 |
}
|
1365 |
|
1366 |
/**
|
1458 |
|
1459 |
// don't attempt to unserialize data that wasn't serialized going in
|
1460 |
if ($this->is_serialized($original)) {
|
1461 |
+
$value = @unserialize($original);
|
1462 |
+
|
1463 |
+
return is_object($value) ? clone $value : $value;
|
1464 |
}
|
1465 |
|
1466 |
return $original;
|
1468 |
|
1469 |
/**
|
1470 |
* Serialize data, if needed.
|
1471 |
+
*
|
1472 |
* @param string|array|object $data Data that might be serialized.
|
1473 |
* @return mixed A scalar data
|
1474 |
*/
|
1475 |
protected function maybe_serialize($data)
|
1476 |
{
|
1477 |
+
if (is_object($data)) {
|
1478 |
+
$data = clone $data;
|
1479 |
+
}
|
1480 |
+
|
1481 |
if (defined('WP_REDIS_SERIALIZER') && ! empty(WP_REDIS_SERIALIZER)) {
|
1482 |
return $data;
|
1483 |
}
|
readme.txt
CHANGED
@@ -3,9 +3,9 @@ Contributors: tillkruess
|
|
3 |
Donate link: https://www.paypal.me/tillkruss
|
4 |
Tags: redis, predis, phpredis, hhvm, pecl, caching, cache, object cache, performance, replication, clustering
|
5 |
Requires at least: 3.3
|
6 |
-
Tested up to: 5.
|
7 |
Requires PHP: 5.4
|
8 |
-
Stable tag: 1.5.
|
9 |
License: GPLv3
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
11 |
|
@@ -218,6 +218,13 @@ The following commands are supported:
|
|
218 |
|
219 |
== Changelog ==
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
= 1.5.6 =
|
222 |
|
223 |
- Added object cloning to in-memory cache
|
3 |
Donate link: https://www.paypal.me/tillkruss
|
4 |
Tags: redis, predis, phpredis, hhvm, pecl, caching, cache, object cache, performance, replication, clustering
|
5 |
Requires at least: 3.3
|
6 |
+
Tested up to: 5.4
|
7 |
Requires PHP: 5.4
|
8 |
+
Stable tag: 1.5.7
|
9 |
License: GPLv3
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
11 |
|
218 |
|
219 |
== Changelog ==
|
220 |
|
221 |
+
= 1.5.7 =
|
222 |
+
|
223 |
+
- Added support for PhpRedis TLS connections
|
224 |
+
- Added support for timeout, read timeout and password when using PhpRedis cluster
|
225 |
+
- Fixed issue with `INFO` command
|
226 |
+
- Fixed object cloning when setting cache keys
|
227 |
+
|
228 |
= 1.5.6 =
|
229 |
|
230 |
- Added object cloning to in-memory cache
|
redis-cache.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: https://wordpress.org/plugins/redis-cache/
|
5 |
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
|
6 |
-
Version: 1.5.
|
7 |
Text Domain: redis-cache
|
8 |
Domain Path: /languages
|
9 |
Author: Till Krüss
|
@@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
17 |
exit;
|
18 |
}
|
19 |
|
20 |
-
define( 'WP_REDIS_VERSION', '1.5.
|
21 |
|
22 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
23 |
require_once dirname( __FILE__ ) . '/includes/wp-cli-commands.php';
|
3 |
Plugin Name: Redis Object Cache
|
4 |
Plugin URI: https://wordpress.org/plugins/redis-cache/
|
5 |
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
|
6 |
+
Version: 1.5.7
|
7 |
Text Domain: redis-cache
|
8 |
Domain Path: /languages
|
9 |
Author: Till Krüss
|
17 |
exit;
|
18 |
}
|
19 |
|
20 |
+
define( 'WP_REDIS_VERSION', '1.5.7' );
|
21 |
|
22 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
23 |
require_once dirname( __FILE__ ) . '/includes/wp-cli-commands.php';
|