Redis Object Cache - Version 1.5.2

Version Description

  • Added Redis version to diagnostics
    • Added WP_REDIS_DISABLE_BANNERS constant to disable promotions
    • Fixed an issue with redis.replicate_commands()
Download this release

Release Info

Developer tillkruess
Plugin Icon 128x128 Redis Object Cache
Version 1.5.2
Comparing to
See all releases

Code changes from version 1.5.1 to 1.5.2

includes/admin-page.css CHANGED
@@ -40,6 +40,11 @@
40
  display: none;
41
  }
42
 
 
 
 
 
 
43
  @media screen and (min-width: 1110px) {
44
  .settings_page_redis-cache .card {
45
  display: block;
40
  display: none;
41
  }
42
 
43
+ .settings_page_redis-cache .card ul {
44
+ list-style: circle;
45
+ padding-left: 25px;
46
+ }
47
+
48
  @media screen and (min-width: 1110px) {
49
  .settings_page_redis-cache .card {
50
  display: block;
includes/admin-page.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ( function ( $ ) {
2
+ $( function () {
3
+ $( ".notice.is-dismissible[data-dismissible]" ).on(
4
+ "click.roc-dismiss-notice",
5
+ ".notice-dismiss",
6
+ function ( event ) {
7
+ $.post( ajaxurl, {
8
+ notice: $( this ).parent().attr( "data-dismissible" ),
9
+ action: "roc_dismiss_notice",
10
+ } );
11
+
12
+ event.preventDefault();
13
+ }
14
+ );
15
+ } );
16
+ } ( jQuery ) );
includes/admin-page.php CHANGED
@@ -5,19 +5,30 @@
5
 
6
  <h1><?php _e( 'Redis Object Cache', 'redis-cache' ); ?></h1>
7
 
8
- <div class="card">
9
- <h2 class="title">
10
- <?php _e( 'Redis Cache Pro', 'redis-cache' ); ?>
11
- </h2>
12
- <p>
13
- <?php _e( 'A business class object cache backend. Truly reliable, highly optimized, fully customizable and with a dedicated engineer when you most need it.', 'redis-cache' ); ?>
14
- </p>
15
- <p>
16
- <a class="button button-primary" target="_blank" rel="noopener" href="https://wprediscache.com/?utm_source=wp-plugin&amp;utm_medium=settings">
17
- <?php _e( 'Learn more', 'redis-cache' ); ?>
18
- </a>
19
- </p>
20
- </div>
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  <div class="section-overview">
23
 
5
 
6
  <h1><?php _e( 'Redis Object Cache', 'redis-cache' ); ?></h1>
7
 
8
+ <?php if ( ! defined( 'WP_REDIS_DISABLE_BANNERS' ) || ! WP_REDIS_DISABLE_BANNERS ) : ?>
9
+ <div class="card">
10
+ <h2 class="title">
11
+ <?php _e( 'Redis Cache Pro', 'redis-cache' ); ?>
12
+ </h2>
13
+ <p>
14
+ <?php _e( '<b>A business class object cache backend.</b> Truly reliable, highly-optimized and fully customizable, with a <u>dedicated engineer</u> when you most need it.', 'redis-cache' ); ?>
15
+ </p>
16
+ <ul>
17
+ <li>Rewritten for raw performance</li>
18
+ <li>100% WordPress object cache API compliant</li>
19
+ <li>Easy debugging & logging</li>
20
+ <li>Fully unit tested (100% code coverage)</li>
21
+ <li>Secure connections with TLS</li>
22
+ <li>Seamless WP CLI & Debug Bar integration</li>
23
+ <li>Optimized for WooCommerce, Jetpack & Yoast SEO</li>
24
+ </ul>
25
+ <p>
26
+ <a class="button button-primary" target="_blank" rel="noopener" href="https://wprediscache.com/?utm_source=wp-plugin&amp;utm_medium=settings">
27
+ <?php _e( 'Learn more', 'redis-cache' ); ?>
28
+ </a>
29
+ </p>
30
+ </div>
31
+ <?php endif; ?>
32
 
33
  <div class="section-overview">
34
 
includes/diagnostics.php CHANGED
@@ -1,11 +1,14 @@
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[ 'Client' ] = $this->get_redis_client_name();
10
 
11
  $info[ 'Drop-in' ] = $dropin ? 'Valid' : 'Invalid';
1
  <?php
2
 
3
+ // TODO: detect constants being defined too late...
4
+
5
  global $wp_object_cache;
6
 
7
  $info = $plugins = $dropins = array();
8
  $dropin = $this->validate_object_cache_dropin() && ( ! defined('WP_REDIS_DISABLED') || ! WP_REDIS_DISABLED );
9
 
10
  $info[ 'Status' ] = $this->get_status();
11
+ $info[ 'Redis Version' ] = $this->get_redis_version() ?: 'Unknown';
12
  $info[ 'Client' ] = $this->get_redis_client_name();
13
 
14
  $info[ 'Drop-in' ] = $dropin ? 'Valid' : 'Invalid';
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.1
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  License: GPLv3
@@ -288,6 +288,13 @@ class WP_Object_Cache
288
  */
289
  private $redis;
290
 
 
 
 
 
 
 
 
291
  /**
292
  * Track if Redis is available
293
  *
@@ -565,6 +572,13 @@ class WP_Object_Cache
565
  $this->redis->ping();
566
  }
567
 
 
 
 
 
 
 
 
568
  $this->redis_connected = true;
569
  } catch (Exception $exception) {
570
  $this->handle_exception($exception);
@@ -597,6 +611,16 @@ class WP_Object_Cache
597
  return $this->redis;
598
  }
599
 
 
 
 
 
 
 
 
 
 
 
600
  /**
601
  * Adds a value to cache.
602
  *
@@ -845,7 +869,6 @@ class WP_Object_Cache
845
  {
846
  return function () use ($salt) {
847
  $script = <<<LUA
848
- redis.replicate_commands()
849
  local cur = 0
850
  local i = 0
851
  local tmp
@@ -862,6 +885,10 @@ class WP_Object_Cache
862
  return i
863
  LUA;
864
 
 
 
 
 
865
  $args = ($this->redis instanceof Predis\Client)
866
  ? [$script, 0]
867
  : [$script];
@@ -886,7 +913,6 @@ LUA;
886
  }, $this->unflushable_groups);
887
 
888
  $script = <<<LUA
889
- redis.replicate_commands()
890
  local cur = 0
891
  local i = 0
892
  local d, tmp
@@ -909,6 +935,9 @@ LUA;
909
  until 0 == cur
910
  return i
911
  LUA;
 
 
 
912
 
913
  $args = ($this->redis instanceof Predis\Client)
914
  ? array_merge([$script, count($unflushable)], $unflushable)
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.2
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  License: GPLv3
288
  */
289
  private $redis;
290
 
291
+ /**
292
+ * The Redis server version.
293
+ *
294
+ * @var null|string
295
+ */
296
+ private $redis_version = null;
297
+
298
  /**
299
  * Track if Redis is available
300
  *
572
  $this->redis->ping();
573
  }
574
 
575
+ $server_info = $this->redis->info( 'SERVER' );
576
+ if (isset($server_info['redis_version'])) {
577
+ $this->redis_version = $server_info['redis_version'];
578
+ } elseif (isset( $server_info['Server']['redis_version'])) {
579
+ $this->redis_version = $server_info['Server']['redis_version'];
580
+ }
581
+
582
  $this->redis_connected = true;
583
  } catch (Exception $exception) {
584
  $this->handle_exception($exception);
611
  return $this->redis;
612
  }
613
 
614
+ /**
615
+ * Returns the Redis server version.
616
+ *
617
+ * @return null|string
618
+ */
619
+ public function redis_version()
620
+ {
621
+ return $this->redis_version;
622
+ }
623
+
624
  /**
625
  * Adds a value to cache.
626
  *
869
  {
870
  return function () use ($salt) {
871
  $script = <<<LUA
 
872
  local cur = 0
873
  local i = 0
874
  local tmp
885
  return i
886
  LUA;
887
 
888
+ if (version_compare($this->redis_version(), '5', '<') && version_compare($this->redis_version(), '3.2', '>=')) {
889
+ $script = 'redis.replicate_commands()' . "\n" . $script;
890
+ }
891
+
892
  $args = ($this->redis instanceof Predis\Client)
893
  ? [$script, 0]
894
  : [$script];
913
  }, $this->unflushable_groups);
914
 
915
  $script = <<<LUA
 
916
  local cur = 0
917
  local i = 0
918
  local d, tmp
935
  until 0 == cur
936
  return i
937
  LUA;
938
+ if (version_compare($this->redis_version(), '5', '<') && version_compare($this->redis_version(), '3.2', '>=')) {
939
+ $script = 'redis.replicate_commands()' . "\n" . $script;
940
+ }
941
 
942
  $args = ($this->redis instanceof Predis\Client)
943
  ? array_merge([$script, count($unflushable)], $unflushable)
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: redis, predis, phpredis, hhvm, pecl, caching, cache, object cache, perform
5
  Requires at least: 3.3
6
  Tested up to: 5.3
7
  Requires PHP: 5.4
8
- Stable tag: 1.5.1
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -214,6 +214,12 @@ The following commands are supported:
214
 
215
  == Changelog ==
216
 
 
 
 
 
 
 
217
  = 1.5.1 =
218
 
219
  This plugin turned 5 years today (Nov 14th) and its only fitting to release the business edition today as well.
5
  Requires at least: 3.3
6
  Tested up to: 5.3
7
  Requires PHP: 5.4
8
+ Stable tag: 1.5.2
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
214
 
215
  == Changelog ==
216
 
217
+ = 1.5.2 =
218
+
219
+ * Added Redis version to diagnostics
220
+ * Added `WP_REDIS_DISABLE_BANNERS` constant to disable promotions
221
+ * Fixed an issue with `redis.replicate_commands()`
222
+
223
  = 1.5.1 =
224
 
225
  This plugin turned 5 years today (Nov 14th) and its only fitting to release the business edition today as well.
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.1
7
  Text Domain: redis-cache
8
  Domain Path: /languages
9
  Author: Till Krüss
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'WP_REDIS_VERSION', '1.5.1' );
20
 
21
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
22
  require_once dirname( __FILE__ ) . '/includes/wp-cli-commands.php';
@@ -41,10 +41,13 @@ class RedisObjectCache {
41
  add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'add_admin_menu_page' ) );
42
  add_action( 'admin_init', array( $this, 'schedule_events' ) );
43
  add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
 
44
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
 
45
  add_action( 'load-' . $this->screen, array( $this, 'do_admin_actions' ) );
46
  add_action( 'load-' . $this->screen, array( $this, 'add_admin_page_notices' ) );
47
  add_action( 'redis_gather_metrics', array( $this, 'gather_metrics' ) );
 
48
 
49
  add_filter( sprintf(
50
  '%splugin_action_links_%s',
@@ -125,6 +128,25 @@ class RedisObjectCache {
125
 
126
  }
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  public function object_cache_dropin_exists() {
129
  return file_exists( WP_CONTENT_DIR . '/object-cache.php' );
130
  }
@@ -185,6 +207,21 @@ class RedisObjectCache {
185
 
186
  }
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  public function get_redis_client_name() {
189
 
190
  global $wp_object_cache;
@@ -290,6 +327,8 @@ class RedisObjectCache {
290
 
291
  public function schedule_events()
292
  {
 
 
293
  if ( ! wp_next_scheduled( 'redis_gather_metrics' ) ) {
294
  wp_schedule_event( time(), 'daily', 'redis_gather_metrics' );
295
  }
@@ -312,12 +351,14 @@ class RedisObjectCache {
312
  'url' => get_home_url(),
313
  'plugin' => WP_REDIS_VERSION,
314
  'wordpress' => get_bloginfo('version'),
 
315
  'php' => phpversion(),
316
  'phpredis' => phpversion('redis'),
317
  'igbinary' => phpversion('igbinary'),
318
- 'network' => is_multisite(),
319
  'client' => $this->get_redis_client_name(),
320
  'serializer' => defined('WP_REDIS_SERIALIZER') ? WP_REDIS_SERIALIZER : null,
 
321
  // only gathers boolean values (no DSNs)
322
  'cluster' => defined('WP_REDIS_CLUSTER') ? (bool) WP_REDIS_CLUSTER : null,
323
  'servers' => defined('WP_REDIS_SERVERS') ? (bool) WP_REDIS_SERVERS : null,
@@ -392,6 +433,50 @@ class RedisObjectCache {
392
 
393
  }
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  public function initialize_filesystem( $url, $silent = false ) {
396
 
397
  if ( $silent ) {
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.2
7
  Text Domain: redis-cache
8
  Domain Path: /languages
9
  Author: Till Krüss
16
  exit;
17
  }
18
 
19
+ define( 'WP_REDIS_VERSION', '1.5.2' );
20
 
21
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
22
  require_once dirname( __FILE__ ) . '/includes/wp-cli-commands.php';
41
  add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'add_admin_menu_page' ) );
42
  add_action( 'admin_init', array( $this, 'schedule_events' ) );
43
  add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
44
+ add_action( 'admin_notices', array( $this, 'pro_notice' ) );
45
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
46
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
47
  add_action( 'load-' . $this->screen, array( $this, 'do_admin_actions' ) );
48
  add_action( 'load-' . $this->screen, array( $this, 'add_admin_page_notices' ) );
49
  add_action( 'redis_gather_metrics', array( $this, 'gather_metrics' ) );
50
+ add_action( 'wp_ajax_roc_dismiss_notice', array( $this, 'dismiss_notice' ) );
51
 
52
  add_filter( sprintf(
53
  '%splugin_action_links_%s',
128
 
129
  }
130
 
131
+ public function enqueue_admin_scripts() {
132
+ $screen = get_current_screen();
133
+
134
+ if ( ! isset( $screen->id ) ) {
135
+ return;
136
+ }
137
+
138
+ if ( ! in_array( $screen->id, array( 'dashboard', $this->screen ) ) ) {
139
+ return;
140
+ }
141
+
142
+ wp_enqueue_script(
143
+ 'roc-dismissible-notices',
144
+ plugins_url( 'includes/admin-page.js', __FILE__ ),
145
+ array( 'jquery' ),
146
+ WP_REDIS_VERSION
147
+ );
148
+ }
149
+
150
  public function object_cache_dropin_exists() {
151
  return file_exists( WP_CONTENT_DIR . '/object-cache.php' );
152
  }
207
 
208
  }
209
 
210
+ public function get_redis_version() {
211
+
212
+ global $wp_object_cache;
213
+
214
+ if ( defined( 'WP_REDIS_DISABLED' ) && WP_REDIS_DISABLED ) {
215
+ return;
216
+ }
217
+
218
+ if ( $this->validate_object_cache_dropin() ) {
219
+ return $wp_object_cache->redis_version();
220
+ }
221
+
222
+ return;
223
+ }
224
+
225
  public function get_redis_client_name() {
226
 
227
  global $wp_object_cache;
327
 
328
  public function schedule_events()
329
  {
330
+ // TODO: remove daily schedule and switch to weekly?
331
+
332
  if ( ! wp_next_scheduled( 'redis_gather_metrics' ) ) {
333
  wp_schedule_event( time(), 'daily', 'redis_gather_metrics' );
334
  }
351
  'url' => get_home_url(),
352
  'plugin' => WP_REDIS_VERSION,
353
  'wordpress' => get_bloginfo('version'),
354
+ 'network' => is_multisite(),
355
  'php' => phpversion(),
356
  'phpredis' => phpversion('redis'),
357
  'igbinary' => phpversion('igbinary'),
358
+ 'redis' => $this->get_redis_version(),
359
  'client' => $this->get_redis_client_name(),
360
  'serializer' => defined('WP_REDIS_SERIALIZER') ? WP_REDIS_SERIALIZER : null,
361
+ 'woocommerce' => defined('WC_VERSION') ? WC_VERSION : null,
362
  // only gathers boolean values (no DSNs)
363
  'cluster' => defined('WP_REDIS_CLUSTER') ? (bool) WP_REDIS_CLUSTER : null,
364
  'servers' => defined('WP_REDIS_SERVERS') ? (bool) WP_REDIS_SERVERS : null,
433
 
434
  }
435
 
436
+ public function dismiss_notice() {
437
+ $notice = sprintf(
438
+ 'roc_dismissed_%s',
439
+ sanitize_key( $_POST[ 'notice' ] )
440
+ );
441
+
442
+ update_user_meta( get_current_user_id(), $notice, '1' );
443
+
444
+ wp_die();
445
+ }
446
+
447
+ public function pro_notice() {
448
+ $screen = get_current_screen();
449
+
450
+ if ( ! isset( $screen->id ) ) {
451
+ return;
452
+ }
453
+
454
+ if ( ! in_array( $screen->id, array( 'dashboard', $this->screen ) ) ) {
455
+ return;
456
+ }
457
+
458
+ if ( ! current_user_can( 'manage_options' ) ) {
459
+ return;
460
+ }
461
+
462
+ if ( defined( 'WP_REDIS_DISABLE_BANNERS' ) && WP_REDIS_DISABLE_BANNERS ) {
463
+ return;
464
+ }
465
+
466
+ if ( get_user_meta( get_current_user_id(), 'roc_dismissed_pro_release_notice', true ) == '1' ) {
467
+ return;
468
+ }
469
+
470
+ printf(
471
+ '<div class="notice notice-info is-dismissible" data-dismissible="pro_release_notice"><p><strong>%s</strong> %s</p></div>',
472
+ __( 'Redis Cache Pro is out!', 'redis-cache' ),
473
+ sprintf(
474
+ __( 'A <u>business class</u> object cache backend. Truly reliable, highly-optimized and fully customizable, with a <u>dedicated engineer</u> when you most need it. <a href="%1$s">Learn more »</a>', 'redis-cache' ),
475
+ network_admin_url( $this->page )
476
+ )
477
+ );
478
+ }
479
+
480
  public function initialize_filesystem( $url, $silent = false ) {
481
 
482
  if ( $silent ) {