Redis Object Cache - Version 1.3

Version Description

  • New admin interface
    • Added support for wp_cache_get()'s $force and $found parameter
    • Added support for clustering and replication with Predis
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.3

includes/admin-page.css CHANGED
@@ -1,4 +1,10 @@
1
 
 
 
 
 
 
 
2
  .wrap .button.delete {
3
  background: #d54e21;
4
  border-color: #a83d1a;
@@ -9,10 +15,9 @@
9
 
10
  .wrap .button.delete:hover,
11
  .wrap .button.delete:focus {
12
- background: #be461d;
13
  border-color: #923517;
14
  color: white;
15
- box-shadow: inset 0 1px 0 #e3704a;
16
  }
17
 
18
  .wrap .button.delete:focus {
@@ -29,7 +34,3 @@
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
- }
1
 
2
+ .settings_page_redis-cache .form-table th,
3
+ .settings_page_redis-cache .form-table td {
4
+ padding-top: 7px;
5
+ padding-bottom: 7px;
6
+ }
7
+
8
  .wrap .button.delete {
9
  background: #d54e21;
10
  border-color: #a83d1a;
15
 
16
  .wrap .button.delete:hover,
17
  .wrap .button.delete:focus {
18
+ background: #c7491f;
19
  border-color: #923517;
20
  color: white;
 
21
  }
22
 
23
  .wrap .button.delete:focus {
34
  0 0 0 1px #d54e21,
35
  0 0 2px 1px rgba( 30, 140, 190, .8 );
36
  }
 
 
 
 
includes/admin-page.php CHANGED
@@ -5,79 +5,42 @@
5
 
6
  <h1><?php _e( 'Redis Object Cache', 'redis-cache' ); ?></h1>
7
 
8
- <?php settings_errors(); ?>
9
 
10
  <table class="form-table">
11
 
12
- <tr valign="top">
13
- <th scope="row"><?php _e( 'Redis Status', 'redis-cache' ); ?></th>
14
- <td><code><?php echo $this->get_redis_status(); ?></code></td>
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
 
74
  </table>
75
 
76
  <p class="submit">
77
 
78
- <?php if ( strcasecmp( 'connected', $this->get_redis_status() ) === 0 ) : ?>
79
- <a href="<?php echo wp_nonce_url( network_admin_url( add_query_arg( 'action', 'flush-cache', $this->page ) ), 'flush-cache' ); ?>" class="button button-primary button-large"><?php _e( 'Flush Cache', 'redis-cache' ); ?></a>
80
- &nbsp;
81
  <?php endif; ?>
82
 
83
  <?php if ( ! $this->object_cache_dropin_exists() ) : ?>
@@ -88,4 +51,8 @@
88
 
89
  </p>
90
 
 
 
 
 
91
  </div>
5
 
6
  <h1><?php _e( 'Redis Object Cache', 'redis-cache' ); ?></h1>
7
 
8
+ <h2 class="title"><?php _e( 'Overview', 'redis-cache' ); ?></h2>
9
 
10
  <table class="form-table">
11
 
12
+ <tr>
13
+ <th><?php _e( 'Status:', 'redis-cache' ); ?></th>
14
+ <td><code><?php echo $this->get_status(); ?></code></td>
15
  </tr>
16
 
17
+ <?php if ( ! is_null( $this->get_redis_client_name() ) ) : ?>
18
+ <tr>
19
+ <th><?php _e( 'Client:', 'redis-cache' ); ?></th>
20
+ <td><code><?php echo esc_html( $this->get_redis_client_name() ); ?></code></td>
21
+ </tr>
22
+ <?php endif; ?>
23
+
24
+ <?php if ( ! is_null( $this->get_redis_cachekey_prefix() ) && trim( $this->get_redis_cachekey_prefix() ) !== '' ) : ?>
25
+ <tr>
26
+ <th><?php _e( 'Key Prefix:', 'redis-cache' ); ?></th>
27
+ <td><code><?php echo esc_html( $this->get_redis_cachekey_prefix() ); ?></code></td>
28
+ </tr>
29
+ <?php endif; ?>
30
+
31
+ <?php if ( ! is_null( $this->get_redis_maxttl() ) ) : ?>
32
+ <tr>
33
+ <th><?php _e( 'Max. TTL:', 'redis-cache' ); ?></th>
34
+ <td><code><?php echo esc_html( $this->get_redis_maxttl() ); ?></code></td>
35
+ </tr>
36
+ <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  </table>
39
 
40
  <p class="submit">
41
 
42
+ <?php if ( $this->get_redis_status() ) : ?>
43
+ <a href="<?php echo wp_nonce_url( network_admin_url( add_query_arg( 'action', 'flush-cache', $this->page ) ), 'flush-cache' ); ?>" class="button button-primary button-large"><?php _e( 'Flush Cache', 'redis-cache' ); ?></a> &nbsp;
 
44
  <?php endif; ?>
45
 
46
  <?php if ( ! $this->object_cache_dropin_exists() ) : ?>
51
 
52
  </p>
53
 
54
+ <h2 class="title"><?php _e( 'Servers', 'redis-cache' ); ?></h2>
55
+
56
+ <?php $this->show_servers_list(); ?>
57
+
58
  </div>
includes/object-cache.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
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.2.1
7
  Author: Till Krüss
8
  Author URI: http://till.kruss.me/
9
  License: GPLv3
@@ -100,14 +100,18 @@ function wp_cache_flush( $delay = 0 ) {
100
  *
101
  * @param string $key The key under which to store the value.
102
  * @param string $group The group value appended to the $key.
 
 
 
 
103
  *
104
  * @global WP_Object_Cache $wp_object_cache
105
  *
106
  * @return bool|mixed Cached object value.
107
  */
108
- function wp_cache_get( $key, $group = '' ) {
109
  global $wp_object_cache;
110
- return $wp_object_cache->get( $key, $group );
111
  }
112
 
113
  /**
@@ -155,7 +159,7 @@ function wp_cache_incr( $key, $offset = 1, $group = '' ) {
155
  */
156
  function wp_cache_init() {
157
  global $wp_object_cache;
158
- $wp_object_cache = new WP_Object_Cache();
159
  }
160
 
161
  /**
@@ -246,7 +250,7 @@ class WP_Object_Cache {
246
  /**
247
  * Holds the Redis client.
248
  *
249
- * @var Predis\Client
250
  */
251
  private $redis;
252
 
@@ -323,118 +327,104 @@ class WP_Object_Cache {
323
  public function __construct() {
324
  global $blog_id, $table_prefix;
325
 
326
- $redis = array(
327
  'scheme' => 'tcp',
328
  'host' => '127.0.0.1',
329
  'port' => 6379
330
  );
331
 
332
- if ( defined( 'WP_REDIS_SCHEME' ) ) {
333
- $redis[ 'scheme' ] = WP_REDIS_SCHEME;
334
- }
335
-
336
- if ( defined( 'WP_REDIS_HOST' ) ) {
337
- $redis[ 'host' ] = WP_REDIS_HOST;
338
- }
339
-
340
- if ( defined( 'WP_REDIS_PORT' ) ) {
341
- $redis[ 'port' ] = WP_REDIS_PORT;
342
- }
343
-
344
- if ( defined( 'WP_REDIS_PATH' ) ) {
345
- $redis[ 'path' ] = WP_REDIS_PATH;
346
- }
347
-
348
- if ( defined( 'WP_REDIS_PASSWORD' ) ) {
349
- $redis[ 'password' ] = WP_REDIS_PASSWORD;
350
- }
351
-
352
- if ( defined( 'WP_REDIS_DATABASE' ) ) {
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
- if ( isset( $redis[ 'password' ] ) ) {
382
- $this->redis->auth( $redis[ 'password' ] );
383
- }
384
-
385
- if ( isset( $redis[ 'database' ] ) ) {
386
- $this->redis->select( $redis[ 'database' ] );
387
- }
388
-
389
- $this->redis_connected = true;
390
 
391
- } elseif ( strcasecmp( 'pecl', $redis_client ) === 0 ) {
392
 
393
- $this->redis_client = 'PCEL Extension';
394
  $this->redis = new Redis();
395
 
396
- if ( strcasecmp( 'unix', $redis[ 'scheme' ] ) === 0 ) {
397
- $this->redis->connect( $redis[ 'path' ] );
398
  } else {
399
- $this->redis->connect( $redis[ 'host' ], $redis[ 'port' ] );
400
  }
 
401
 
402
- if ( isset( $redis[ 'password' ] ) ) {
403
- $this->redis->auth( $redis[ 'password' ] );
 
404
  }
405
 
406
- if ( isset( $redis[ 'database' ] ) ) {
407
- $this->redis->select( $redis[ 'database' ] );
408
  }
 
409
 
410
- $this->redis_connected = true;
411
-
412
- } else {
413
 
414
  $this->redis_client = 'Predis';
415
 
416
- // require PHP 5.4 or greater
417
  if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
418
  throw new Exception;
419
  }
420
 
421
- // check if bundled Predis library exists
422
- if ( ! realpath( dirname( __FILE__ ) . '/plugins/redis-cache/includes/predis.php' ) ) {
423
- throw new Exception;
 
424
  }
425
 
426
- require_once dirname( __FILE__ ) . '/plugins/redis-cache/includes/predis.php';
427
 
428
- Predis\Autoloader::register();
 
 
 
 
 
 
 
 
429
 
430
- $this->redis = new Predis\Client( $redis );
431
  $this->redis->connect();
432
 
433
- $this->redis_connected = true;
434
- $this->redis_client .= ' v' . Predis\Client::VERSION;
435
 
436
  }
437
 
 
 
 
 
 
438
  } catch ( Exception $exception ) {
439
 
440
  // When Redis is unavailable, fall back to the internal back by forcing all groups to be "no redis" groups
@@ -528,9 +518,9 @@ class WP_Object_Cache {
528
  $expiration = $this->validate_expiration( $expiration );
529
 
530
  if ( $expiration ) {
531
- $result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->maybe_serialize( $value ) ) );
532
  } else {
533
- $result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
534
  }
535
  }
536
 
@@ -563,7 +553,7 @@ class WP_Object_Cache {
563
  }
564
 
565
  if ( $this->redis_status() && ! in_array( $group, $this->no_redis_groups ) ) {
566
- $result = $this->parse_predis_response( $this->redis->del( $derived_key ) );
567
  }
568
 
569
  return $result;
@@ -584,7 +574,7 @@ class WP_Object_Cache {
584
  $this->cache = array();
585
 
586
  if ( $this->redis_status() ) {
587
- $result = $this->parse_predis_response( $this->redis->flushdb() );
588
  }
589
 
590
  return $result;
@@ -597,31 +587,47 @@ class WP_Object_Cache {
597
  *
598
  * @param string $key The key under which to store the value.
599
  * @param string $group The group value appended to the $key.
 
 
 
 
600
  * @return bool|mixed Cached object value.
601
  */
602
- public function get( $key, $group = 'default' ) {
603
  $derived_key = $this->build_key( $key, $group );
604
 
605
- if ( isset( $this->cache[ $derived_key ] ) ) {
 
606
  $this->cache_hits++;
 
607
  return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ];
608
  } elseif ( in_array( $group, $this->no_redis_groups ) || ! $this->redis_status() ) {
 
609
  $this->cache_misses++;
 
610
  return false;
611
  }
612
 
613
  $result = $this->redis->get( $derived_key );
 
614
  if ($result === NULL) {
 
615
  $this->cache_misses++;
 
616
  return false;
617
  } else {
 
618
  $this->cache_hits++;
619
  $value = $this->maybe_unserialize( $result );
620
  }
621
 
622
  $this->add_to_internal_cache( $derived_key, $value );
623
 
624
- return is_object( $value ) ? clone $value : $value;
 
 
 
 
625
  }
626
 
627
  /**
@@ -705,9 +711,9 @@ class WP_Object_Cache {
705
  if ( ! in_array( $group, $this->no_redis_groups ) && $this->redis_status() ) {
706
  $expiration = $this->validate_expiration($expiration);
707
  if ( $expiration ) {
708
- $result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->maybe_serialize( $value ) ) );
709
  } else {
710
- $result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
711
  }
712
  }
713
 
@@ -716,6 +722,8 @@ class WP_Object_Cache {
716
  $this->add_to_internal_cache( $derived_key, $value );
717
  }
718
 
 
 
719
  return $result;
720
  }
721
 
@@ -741,7 +749,7 @@ class WP_Object_Cache {
741
  }
742
 
743
  // Save to Redis
744
- $result = $this->parse_predis_response( $this->redis->incrBy( $derived_key, $offset ) );
745
 
746
  $this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
747
 
@@ -770,7 +778,7 @@ class WP_Object_Cache {
770
  }
771
 
772
  // Save to Redis
773
- $result = $this->parse_predis_response( $this->redis->decrBy( $derived_key, $offset ) );
774
 
775
  $this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
776
 
@@ -785,17 +793,14 @@ class WP_Object_Cache {
785
  public function stats() { ?>
786
 
787
  <p>
788
- <strong>Cache Status:</strong> <?php echo $this->redis_status() ? 'Connected' : 'Not connected'; ?><br />
789
  <strong>Cache Hits:</strong> <?php echo $this->cache_hits; ?><br />
790
  <strong>Cache Misses:</strong> <?php echo $this->cache_misses; ?>
791
  </p>
792
 
793
- <p><strong>Caches Retrieved:</strong></p>
794
-
795
  <ul>
796
- <li><em>prefix:group:key - size in kilobytes</em></li>
797
  <?php foreach ( $this->cache as $group => $cache ) : ?>
798
- <li><?php printf( '%s - %s kb', strip_tags( $group ), number_format( strlen( serialize( $cache ) ) / 1024, 2 ) ); ?></li>
799
  <?php endforeach; ?>
800
  </ul><?php
801
 
@@ -844,12 +849,12 @@ class WP_Object_Cache {
844
  }
845
 
846
  /**
847
- * Convert the response fro Predis into something meaningful
848
  *
849
  * @param mixed $response
850
  * @return mixed
851
  */
852
- protected function parse_predis_response( $response ) {
853
  if ( is_bool( $response ) ) {
854
  return $response;
855
  }
2
  /*
3
  Plugin Name: Redis Object Cache
4
  Plugin URI: http://wordpress.org/plugins/redis-cache/
5
+ Description: A persistent object cache backend powered by Redis. Supports HHVM's Redis extension, the PECL Redis Extension and the Predis library for PHP.
6
+ Version: 1.3
7
  Author: Till Krüss
8
  Author URI: http://till.kruss.me/
9
  License: GPLv3
100
  *
101
  * @param string $key The key under which to store the value.
102
  * @param string $group The group value appended to the $key.
103
+ * @param bool $force Optional. Whether to force an update of the local cache from the persistent
104
+ * cache. Default false.
105
+ * @param bool &$found Optional. Whether the key was found in the cache. Disambiguates a return of false,
106
+ * a storable value. Passed by reference. Default null.
107
  *
108
  * @global WP_Object_Cache $wp_object_cache
109
  *
110
  * @return bool|mixed Cached object value.
111
  */
112
+ function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
113
  global $wp_object_cache;
114
+ return $wp_object_cache->get( $key, $group, $force, $found );
115
  }
116
 
117
  /**
159
  */
160
  function wp_cache_init() {
161
  global $wp_object_cache;
162
+ $wp_object_cache = new WP_Object_Cache;
163
  }
164
 
165
  /**
250
  /**
251
  * Holds the Redis client.
252
  *
253
+ * @var mixed
254
  */
255
  private $redis;
256
 
327
  public function __construct() {
328
  global $blog_id, $table_prefix;
329
 
330
+ $parameters = array(
331
  'scheme' => 'tcp',
332
  'host' => '127.0.0.1',
333
  'port' => 6379
334
  );
335
 
336
+ foreach ( [ 'scheme', 'host', 'port', 'path', 'password', 'database' ] as $setting ) {
337
+ $constant = sprintf( 'WP_REDIS_%s', strtoupper( $setting ) );
338
+ if ( defined( $constant ) ) {
339
+ $server[ $setting ] = constant( $constant );
340
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  }
342
 
343
+ $client = defined( 'WP_REDIS_CLIENT' ) ? WP_REDIS_CLIENT : null;
344
 
345
+ if ( class_exists( 'Redis' ) && strcasecmp( 'predis', $client ) !== 0 ) {
346
+ $client = defined( 'HHVM_VERSION' ) ? 'hhvm' : 'pecl';
347
  } else {
348
+ $client = 'predis';
349
  }
350
 
351
  try {
352
 
353
+ if ( strcasecmp( 'hhvm', $client ) === 0 ) {
354
 
355
+ $this->redis_client = sprintf( 'HHVM Extension (v%s)', HHVM_VERSION );
356
  $this->redis = new Redis();
357
 
358
+ // Adjust host and port, if the scheme is `unix`
359
+ if ( strcasecmp( 'unix', $parameters[ 'scheme' ] ) === 0 ) {
360
+ $parameters[ 'host' ] = 'unix://' . $parameters[ 'path' ];
361
+ $parameters[ 'port' ] = 0;
362
  }
363
 
364
+ $this->redis->connect( $parameters[ 'host' ], $parameters[ 'port' ] );
365
+ }
 
 
 
 
 
 
 
 
 
 
 
366
 
367
+ if ( strcasecmp( 'pecl', $client ) === 0 ) {
368
 
369
+ $this->redis_client = sprintf( 'PECL Extension (v%s)', phpversion('redis') );
370
  $this->redis = new Redis();
371
 
372
+ if ( strcasecmp( 'unix', $parameters[ 'scheme' ] ) === 0 ) {
373
+ $this->redis->connect( $parameters[ 'path' ] );
374
  } else {
375
+ $this->redis->connect( $parameters[ 'host' ], $parameters[ 'port' ] );
376
  }
377
+ }
378
 
379
+ if ( strcasecmp( 'pecl', $client ) === 0 || strcasecmp( 'hhvm', $client ) === 0 ) {
380
+ if ( isset( $parameters[ 'password' ] ) ) {
381
+ $this->redis->auth( $parameters[ 'password' ] );
382
  }
383
 
384
+ if ( isset( $parameters[ 'database' ] ) ) {
385
+ $this->redis->select( $parameters[ 'database' ] );
386
  }
387
+ }
388
 
389
+ if ( strcasecmp( 'predis', $client ) === 0 ) {
 
 
390
 
391
  $this->redis_client = 'Predis';
392
 
393
+ // Require PHP 5.4 or greater
394
  if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
395
  throw new Exception;
396
  }
397
 
398
+ // Load bundled Predis library
399
+ if ( ! class_exists( 'Predis\Client' ) ) {
400
+ require_once WP_CONTENT_DIR . '/plugins/redis-cache/includes/predis.php';
401
+ Predis\Autoloader::register();
402
  }
403
 
404
+ $options = array();
405
 
406
+ if ( defined( 'WP_REDIS_CLUSTER' ) ) {
407
+ $parameters = WP_REDIS_CLUSTER;
408
+ $options[ 'cluster' ] = 'redis';
409
+ }
410
+
411
+ if ( defined( 'WP_REDIS_SERVERS' ) ) {
412
+ $parameters = WP_REDIS_SERVERS;
413
+ $options[ 'replication' ] = true;
414
+ }
415
 
416
+ $this->redis = new Predis\Client( $parameters, $options );
417
  $this->redis->connect();
418
 
419
+ $this->redis_client .= sprintf( ' (v%s)', Predis\Client::VERSION );
 
420
 
421
  }
422
 
423
+ // Throws exception if Redis is unavailable
424
+ $this->redis->ping();
425
+
426
+ $this->redis_connected = true;
427
+
428
  } catch ( Exception $exception ) {
429
 
430
  // When Redis is unavailable, fall back to the internal back by forcing all groups to be "no redis" groups
518
  $expiration = $this->validate_expiration( $expiration );
519
 
520
  if ( $expiration ) {
521
+ $result = $this->parse_redis_response( $this->redis->setex( $derived_key, $expiration, $this->maybe_serialize( $value ) ) );
522
  } else {
523
+ $result = $this->parse_redis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
524
  }
525
  }
526
 
553
  }
554
 
555
  if ( $this->redis_status() && ! in_array( $group, $this->no_redis_groups ) ) {
556
+ $result = $this->parse_redis_response( $this->redis->del( $derived_key ) );
557
  }
558
 
559
  return $result;
574
  $this->cache = array();
575
 
576
  if ( $this->redis_status() ) {
577
+ $result = $this->parse_redis_response( $this->redis->flushdb() );
578
  }
579
 
580
  return $result;
587
  *
588
  * @param string $key The key under which to store the value.
589
  * @param string $group The group value appended to the $key.
590
+ * @param string $force Optional. Whether to force a refetch rather than relying on the local
591
+ * cache. Default false.
592
+ * @param bool &$found Optional. Whether the key was found in the cache. Disambiguates a return of
593
+ * false, a storable value. Passed by reference. Default null.
594
  * @return bool|mixed Cached object value.
595
  */
596
+ public function get( $key, $group = 'default', $force = false, &$found = null ) {
597
  $derived_key = $this->build_key( $key, $group );
598
 
599
+ if ( isset( $this->cache[ $derived_key ] ) && ! $force ) {
600
+ $found = true;
601
  $this->cache_hits++;
602
+
603
  return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ];
604
  } elseif ( in_array( $group, $this->no_redis_groups ) || ! $this->redis_status() ) {
605
+ $found = false;
606
  $this->cache_misses++;
607
+
608
  return false;
609
  }
610
 
611
  $result = $this->redis->get( $derived_key );
612
+
613
  if ($result === NULL) {
614
+ $found = false;
615
  $this->cache_misses++;
616
+
617
  return false;
618
  } else {
619
+ $found = true;
620
  $this->cache_hits++;
621
  $value = $this->maybe_unserialize( $result );
622
  }
623
 
624
  $this->add_to_internal_cache( $derived_key, $value );
625
 
626
+ $value = is_object( $value ) ? clone $value : $value;
627
+
628
+ do_action( 'redis_object_cache_get', $key, $value, $group, $force, $found );
629
+
630
+ return apply_filters( 'redis_object_cache_get', $value, $key, $group, $force, $found );
631
  }
632
 
633
  /**
711
  if ( ! in_array( $group, $this->no_redis_groups ) && $this->redis_status() ) {
712
  $expiration = $this->validate_expiration($expiration);
713
  if ( $expiration ) {
714
+ $result = $this->parse_redis_response( $this->redis->setex( $derived_key, $expiration, $this->maybe_serialize( $value ) ) );
715
  } else {
716
+ $result = $this->parse_redis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
717
  }
718
  }
719
 
722
  $this->add_to_internal_cache( $derived_key, $value );
723
  }
724
 
725
+ do_action( 'redis_object_cache_set', $key, $value, $group, $expiration );
726
+
727
  return $result;
728
  }
729
 
749
  }
750
 
751
  // Save to Redis
752
+ $result = $this->parse_redis_response( $this->redis->incrBy( $derived_key, $offset ) );
753
 
754
  $this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
755
 
778
  }
779
 
780
  // Save to Redis
781
+ $result = $this->parse_redis_response( $this->redis->decrBy( $derived_key, $offset ) );
782
 
783
  $this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
784
 
793
  public function stats() { ?>
794
 
795
  <p>
796
+ <strong>Cache Status:</strong> <?php echo $this->redis_status() ? 'Connected' : 'Not Connected'; ?><br />
797
  <strong>Cache Hits:</strong> <?php echo $this->cache_hits; ?><br />
798
  <strong>Cache Misses:</strong> <?php echo $this->cache_misses; ?>
799
  </p>
800
 
 
 
801
  <ul>
 
802
  <?php foreach ( $this->cache as $group => $cache ) : ?>
803
+ <li><?php printf( '%s - %sk', strip_tags( $group ), number_format( strlen( serialize( $cache ) ) / 1024, 2 ) ); ?></li>
804
  <?php endforeach; ?>
805
  </ul><?php
806
 
849
  }
850
 
851
  /**
852
+ * Convert Redis responses into something meaningful
853
  *
854
  * @param mixed $response
855
  * @return mixed
856
  */
857
+ protected function parse_redis_response( $response ) {
858
  if ( is_bool( $response ) ) {
859
  return $response;
860
  }
includes/servers-list.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Servers_List extends WP_List_Table {
4
+
5
+ public function __construct() {
6
+
7
+ parent::__construct( array(
8
+ 'singular' => __( 'Server', 'redis-cache' ),
9
+ 'plural' => __( 'Servers', 'redis-cache' ),
10
+ 'ajax' => false
11
+ ) );
12
+
13
+ }
14
+
15
+ public function get_columns() {
16
+
17
+ return array(
18
+ 'alias' => 'Alias',
19
+ 'scheme' => 'Protocol',
20
+ 'host' => 'Host',
21
+ 'port' => 'Port',
22
+ 'path' => 'Path',
23
+ 'database' => 'Database',
24
+ 'password' => 'Password',
25
+ );
26
+
27
+ }
28
+
29
+ public function get_hidden_columns() {
30
+
31
+ $hidden = array( 'host', 'port', 'path' );
32
+
33
+ array_walk_recursive( $this->items, function ( $value, $key ) use ( &$hidden ) {
34
+ if ( $key == 'scheme' ) {
35
+ if ( strcasecmp( 'tcp', $value ) === 0 ) {
36
+ $hidden = array_diff( $hidden, array( 'host', 'port' ) );
37
+ }
38
+ if ( strcasecmp( 'unix', $value ) === 0 ) {
39
+ $hidden = array_diff( $hidden, array( 'path' ) );
40
+ }
41
+ }
42
+ } );
43
+
44
+ return $hidden;
45
+
46
+ }
47
+
48
+ public function prepare_items() {
49
+
50
+ if ( ! class_exists( 'Predis\Client' ) ) {
51
+ require_once dirname(__FILE__) . '/predis.php';
52
+ Predis\Autoloader::register();
53
+ }
54
+
55
+ $this->items = $this->get_servers();
56
+
57
+ $this->_column_headers = array($this->get_columns(), $this->get_hidden_columns(), array());
58
+
59
+ }
60
+
61
+ public function column_default( $item, $column_name ) {
62
+
63
+ switch ( $column_name ) {
64
+
65
+ case 'scheme':
66
+ return isset( $item[ 'scheme' ] ) ? strtoupper( $item[ 'scheme' ] ) : 'TCP';
67
+
68
+ case 'host':
69
+ return isset( $item[ 'host' ] ) ? $item[ 'host' ] : '127.0.0.1';
70
+
71
+ case 'port':
72
+ return isset( $item[ 'port' ] ) ? $item[ 'port' ] : '6379';
73
+
74
+ case 'database':
75
+ return isset( $item[ 'database' ] ) ? $item[ 'database' ] : '0';
76
+
77
+ case 'password':
78
+ return isset( $item[ 'password' ] ) ? __( 'Yes', 'redis-cache' ) : __( 'No', 'redis-cache' );
79
+
80
+ default:
81
+ return isset( $item[ $column_name ] ) ? $item[ $column_name ] : '';
82
+ }
83
+
84
+ }
85
+
86
+ protected function display_tablenav($which)
87
+ {
88
+ // hide table navigation
89
+ }
90
+
91
+ protected function get_servers() {
92
+
93
+ $server = array(
94
+ 'alias' => 'Master',
95
+ 'scheme' => 'tcp',
96
+ );
97
+
98
+ foreach ( [ 'scheme', 'host', 'port', 'path', 'password', 'database' ] as $setting ) {
99
+ $constant = sprintf( 'WP_REDIS_%s', strtoupper( $setting ) );
100
+
101
+ if ( defined( $constant ) ) {
102
+ $server[ $setting ] = constant( $constant );
103
+ }
104
+ }
105
+
106
+ if ( defined( 'WP_REDIS_CLUSTER' ) ) {
107
+ $servers = WP_REDIS_CLUSTER;
108
+ }
109
+
110
+ if ( defined( 'WP_REDIS_SERVERS' ) ) {
111
+ $servers = WP_REDIS_SERVERS;
112
+ }
113
+
114
+ if ( ! isset( $servers ) ) {
115
+ $servers = array( $server );
116
+ }
117
+
118
+ return array_map(function($parameters) {
119
+ return is_string($parameters) ? Predis\Connection\Parameters::parse($parameters) : $parameters;
120
+ }, $servers);
121
+
122
+ }
123
+
124
+ }
languages/redis-cache.pot CHANGED
@@ -1,143 +1,136 @@
1
- # Copyright (C) 2015 Redis Object Cache
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.2.1\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/redis-cache\n"
7
- "POT-Creation-Date: 2015-09-15 02:23:52+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\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.2.1) #-#-#-#-#
16
  #. Plugin Name of the plugin/theme
17
  #: includes/admin-page.php:6 redis-cache.php:50
18
  msgid "Redis Object Cache"
19
  msgstr ""
20
 
21
- #: includes/admin-page.php:13
22
- msgid "Redis Status"
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
 
77
  #: redis-cache.php:51
78
  msgid "Redis"
79
  msgstr ""
80
 
81
- #: redis-cache.php:157
82
- msgid "Not installed"
83
  msgstr ""
84
 
85
- #: redis-cache.php:161
86
  msgid "Connected"
87
  msgstr ""
88
 
89
- #: redis-cache.php:161
90
- msgid "Not connected"
91
  msgstr ""
92
 
93
- #: redis-cache.php:164
94
  msgid "Unknown"
95
  msgstr ""
96
 
97
- #: redis-cache.php:186
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:192
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:208
109
  msgid "This plugin requires PHP 5.4 or greater."
110
  msgstr ""
111
 
112
- #: redis-cache.php:217
113
  msgid "Object Cache enabled."
114
  msgstr ""
115
 
116
- #: redis-cache.php:220
117
  msgid "Object Cache could not be enabled."
118
  msgstr ""
119
 
120
- #: redis-cache.php:223
121
  msgid "Object Cache disabled."
122
  msgstr ""
123
 
124
- #: redis-cache.php:226
125
  msgid "Object Cache could not be disabled."
126
  msgstr ""
127
 
128
- #: redis-cache.php:229
129
  msgid "Object Cache flushed."
130
  msgstr ""
131
 
132
- #: redis-cache.php:232
133
  msgid "Object Cache could not be flushed."
134
  msgstr ""
135
 
136
- #: redis-cache.php:235
137
  msgid "Drop-in updated."
138
  msgstr ""
139
 
140
- #: redis-cache.php:238
141
  msgid "Drop-in could not be updated."
142
  msgstr ""
143
 
@@ -147,8 +140,8 @@ msgstr ""
147
 
148
  #. Description of the plugin/theme
149
  msgid ""
150
- "A Redis backend for the WordPress Object Cache based on the Predis client "
151
- "library for PHP."
152
  msgstr ""
153
 
154
  #. Author of the plugin/theme
1
+ # Copyright (C) 2016 Redis Object Cache
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.3\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/redis-cache\n"
7
+ "POT-Creation-Date: 2016-04-29 01:44:38+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\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.3) #-#-#-#-#
16
  #. Plugin Name of the plugin/theme
17
  #: includes/admin-page.php:6 redis-cache.php:50
18
  msgid "Redis Object Cache"
19
  msgstr ""
20
 
21
+ #: includes/admin-page.php:8
22
+ msgid "Overview"
23
  msgstr ""
24
 
25
+ #: includes/admin-page.php:13
26
+ msgid "Status:"
27
  msgstr ""
28
 
29
+ #: includes/admin-page.php:19
30
  msgid "Client:"
31
  msgstr ""
32
 
33
+ #: includes/admin-page.php:26
34
+ msgid "Key Prefix:"
35
  msgstr ""
36
 
37
  #: includes/admin-page.php:33
38
+ msgid "Max. TTL:"
39
  msgstr ""
40
 
41
+ #: includes/admin-page.php:43
42
+ msgid "Flush Cache"
43
  msgstr ""
44
 
45
+ #: includes/admin-page.php:47
46
+ msgid "Enable Object Cache"
47
  msgstr ""
48
 
49
  #: includes/admin-page.php:49
50
+ msgid "Disable Object Cache"
 
 
 
 
 
 
 
 
51
  msgstr ""
52
 
53
+ #: includes/admin-page.php:54 includes/servers-list.php:9
54
+ msgid "Servers"
55
  msgstr ""
56
 
57
+ #: includes/servers-list.php:8
58
+ msgid "Server"
59
  msgstr ""
60
 
61
+ #: includes/servers-list.php:78
62
+ msgid "Yes"
63
  msgstr ""
64
 
65
+ #: includes/servers-list.php:78
66
+ msgid "No"
67
  msgstr ""
68
 
69
  #: redis-cache.php:51
70
  msgid "Redis"
71
  msgstr ""
72
 
73
+ #: redis-cache.php:141
74
+ msgid "Disabled"
75
  msgstr ""
76
 
77
+ #: redis-cache.php:146
78
  msgid "Connected"
79
  msgstr ""
80
 
81
+ #: redis-cache.php:150
82
+ msgid "Not Connected"
83
  msgstr ""
84
 
85
+ #: redis-cache.php:154
86
  msgid "Unknown"
87
  msgstr ""
88
 
89
+ #: redis-cache.php:211
90
  msgid ""
91
+ "The Redis object cache drop-in is outdated. Please <a href=\"%s\">update it "
92
+ "now</a>."
93
  msgstr ""
94
 
95
+ #: redis-cache.php:216
96
  msgid ""
97
+ "Another object cache drop-in was found. To use Redis, <a href=\"%s\">please "
98
+ "replace it now</a>."
99
  msgstr ""
100
 
101
+ #: redis-cache.php:232
102
  msgid "This plugin requires PHP 5.4 or greater."
103
  msgstr ""
104
 
105
+ #: redis-cache.php:241
106
  msgid "Object Cache enabled."
107
  msgstr ""
108
 
109
+ #: redis-cache.php:244
110
  msgid "Object Cache could not be enabled."
111
  msgstr ""
112
 
113
+ #: redis-cache.php:247
114
  msgid "Object Cache disabled."
115
  msgstr ""
116
 
117
+ #: redis-cache.php:250
118
  msgid "Object Cache could not be disabled."
119
  msgstr ""
120
 
121
+ #: redis-cache.php:253
122
  msgid "Object Cache flushed."
123
  msgstr ""
124
 
125
+ #: redis-cache.php:256
126
  msgid "Object Cache could not be flushed."
127
  msgstr ""
128
 
129
+ #: redis-cache.php:259
130
  msgid "Drop-in updated."
131
  msgstr ""
132
 
133
+ #: redis-cache.php:262
134
  msgid "Drop-in could not be updated."
135
  msgstr ""
136
 
140
 
141
  #. Description of the plugin/theme
142
  msgid ""
143
+ "A persistent object cache backend powered by Redis. Supports Predis, "
144
+ "PhpRedis, HHVM, replication and clustering."
145
  msgstr ""
146
 
147
  #. Author of the plugin/theme
readme.txt CHANGED
@@ -1,21 +1,21 @@
1
  === Redis Object Cache ===
2
  Contributors: tillkruess
3
  Donate link: https://www.paypal.me/tillkruss
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.4
7
- Stable tag: 1.2.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
 
@@ -26,15 +26,17 @@ For detailed installation instructions, please read the [standard installation p
26
 
27
  1. Make sure Redis in installed and running.
28
  2. Install and activate plugin.
29
- 3. Enable the object cache under _Tools -> Redis_.
30
  4. If necessary, adjust [connection parameters](http://wordpress.org/extend/plugins/redis-cache/other_notes/).
31
 
 
 
32
 
33
  == Connection Parameters ==
34
 
35
  By default the object cache drop-in will connect to Redis over TCP at `127.0.0.1:6379` and select database `0`.
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
 
@@ -64,16 +66,40 @@ To adjust the connection parameters, define the following constants in your `wp-
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
 
74
- The `WP_CACHE_KEY_SALT` constant is provided to add a prefix to all cache keys.
75
 
76
- Users with setups where multiple installs share a common `wp-config.php` or `$table_prefix` can use this constant to guarantee uniqueness for the keys generated by this object cache.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
  == Screenshots ==
@@ -83,6 +109,25 @@ Users with setups where multiple installs share a common `wp-config.php` or `$ta
83
 
84
  == Changelog ==
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  = 1.2.1 =
87
 
88
  * Added `composer.json`
@@ -104,7 +149,7 @@ Users with setups where multiple installs share a common `wp-config.php` or `$ta
104
  = 1.1 =
105
 
106
  * Added support for HHVM's Redis extension
107
- * Added support for PCEL Redis extension
108
  * Added `WP_REDIS_CLIENT` constant, to set prefered Redis client
109
  * Added `WP_REDIS_MAXTTL` constant, to force expiration of cache keys
110
  * Improved `add_or_replace()`, `get()`, `set()` and `delete()` methods
@@ -133,6 +178,18 @@ Users with setups where multiple installs share a common `wp-config.php` or `$ta
133
 
134
  == Upgrade Notice ==
135
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  = 1.2.1 =
137
 
138
  This update includes several improvements and compatibility fixes.
@@ -143,7 +200,7 @@ This update fixes critical bugs with the HHVM extension
143
 
144
  = 1.1 =
145
 
146
- This update includes bug fixes and adds supports for HHVM/PCEL Redis extensions.
147
 
148
  = 1.0.2 =
149
 
1
  === Redis Object Cache ===
2
  Contributors: tillkruess
3
  Donate link: https://www.paypal.me/tillkruss
4
+ Tags: redis, predis, hhvm, pecl, caching, cache, object cache, wp object cache, server, performance, optimize, speed, load, replication, clustering
5
  Requires at least: 3.3
6
+ Tested up to: 4.5
7
+ Stable tag: 1.3
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 Predis, PhpRedis, HHVM, replication and clustering.
12
 
13
 
14
  == Description ==
15
 
16
+ A persistent object cache backend powered by Redis. Supports [Predis](https://github.com/nrk/predis/), [HHVM's Redis extension](https://github.com/facebook/hhvm/tree/master/hphp/system/php/redis) and the [PECL Redis Extension](https://github.com/phpredis/phpredis).
17
 
18
+ To adjust the connection parameters, prefix cache keys or configure replication/clustering, please 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
 
26
 
27
  1. Make sure Redis in installed and running.
28
  2. Install and activate plugin.
29
+ 3. Enable the object cache under _Settings -> Redis_.
30
  4. If necessary, adjust [connection parameters](http://wordpress.org/extend/plugins/redis-cache/other_notes/).
31
 
32
+ If you server doesn't support the [WordPress Filesystem API](https://codex.wordpress.org/Filesystem_API), you have to manually copy the `object-cache.php` file from the `/plugins/redis-cache/includes/` directory to the `/wp-content/` directory.
33
+
34
 
35
  == Connection Parameters ==
36
 
37
  By default the object cache drop-in will connect to Redis over TCP at `127.0.0.1:6379` and select database `0`.
38
 
39
+ To adjust the connection parameters, define any of following constants in your `wp-config.php` file.
40
 
41
  * `WP_REDIS_CLIENT` [default: not set]
42
 
66
 
67
  Accepts a value used to authenticate with a Redis server protected by password with the `AUTH` command.
68
 
69
+
70
+ == Configuration Parameters ==
71
+
72
+ To adjust the configuration, define any of the following constants in your `wp-config.php` file.
73
+
74
+ * `WP_CACHE_KEY_SALT` [default: not set]
75
+
76
+ Set the prefix for all cache keys. Useful in setups where multiple installs share a common `wp-config.php` or `$table_prefix`, to guarantee uniqueness of cache keys.
77
+
78
  * `WP_REDIS_MAXTTL` [default: not set]
79
 
80
+ Set maximum time-to-live (in seconds) for cache keys with an expiration time of `0`.
81
 
82
 
83
+ == Replication & Clustering ==
84
 
85
+ To use Replication and Clustering, make sure your server is running PHP7, your setup is using Predis to connect to Redis and you consulted the [Predis documentation](https://github.com/nrk/predis).
86
 
87
+ For replication, use the `WP_REDIS_SERVERS` constant and for clustering the `WP_REDIS_CLUSTER` constant. You can use a named array or an URI string to specify the parameters.
88
+
89
+ __Master-Slave Replication Example:__
90
+
91
+ define( 'WP_REDIS_SERVERS', [
92
+ 'tcp://127.0.0.1:6379?database=15&alias=master',
93
+ 'tcp://127.0.0.2:6379?database=15&alias=slave-01',
94
+ ] );
95
+
96
+
97
+ __Clustering via Client-side Sharding Example:__
98
+
99
+ define( 'WP_REDIS_CLUSTER', [
100
+ 'tcp://127.0.0.1:6379?database=15&alias=node-01',
101
+ 'tcp://127.0.0.2:6379?database=15&alias=node-02',
102
+ ] );
103
 
104
 
105
  == Screenshots ==
109
 
110
  == Changelog ==
111
 
112
+ = 1.3 =
113
+
114
+ * New admin interface
115
+ * Added support for `wp_cache_get()`'s `$force` and `$found` parameter
116
+ * Added support for clustering and replication with Predis
117
+
118
+ = 1.2.3 =
119
+
120
+ * UI improvements
121
+
122
+ = 1.2.2 =
123
+
124
+ * Added `redis_object_cache_set` action
125
+ * Added `redis_object_cache_get` action and filter
126
+ * Prevented duplicated admin status messages
127
+ * Load bundled Predis library only if necessary
128
+ * Load bundled Predis library using `WP_CONTENT_DIR` constant
129
+ * Updated `stats()` method output to be uniform with WordPress
130
+
131
  = 1.2.1 =
132
 
133
  * Added `composer.json`
149
  = 1.1 =
150
 
151
  * Added support for HHVM's Redis extension
152
+ * Added support for PECL Redis extension
153
  * Added `WP_REDIS_CLIENT` constant, to set prefered Redis client
154
  * Added `WP_REDIS_MAXTTL` constant, to force expiration of cache keys
155
  * Improved `add_or_replace()`, `get()`, `set()` and `delete()` methods
178
 
179
  == Upgrade Notice ==
180
 
181
+ = 1.3 =
182
+
183
+ This update includes a new admin interface and support for clustering and replication with Predis.
184
+
185
+ = 1.2.3 =
186
+
187
+ This updated includes several UI improvements.
188
+
189
+ = 1.2.2 =
190
+
191
+ This updated includes several bug fixes and improvements.
192
+
193
  = 1.2.1 =
194
 
195
  This update includes several improvements and compatibility fixes.
200
 
201
  = 1.1 =
202
 
203
+ This update includes bug fixes and adds supports for HHVM/PECL Redis extensions.
204
 
205
  = 1.0.2 =
206
 
redis-cache.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
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.2.1
7
  Text Domain: redis-cache
8
  Domain Path: /languages
9
  Author: Till Krüss
@@ -85,6 +85,16 @@ class RedisObjectCache {
85
 
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
88
  public function add_plugin_actions_links( $links ) {
89
 
90
  // add settings link to plugin actions
@@ -109,60 +119,76 @@ class RedisObjectCache {
109
  }
110
 
111
  public function validate_object_cache_dropin() {
112
- return $this->object_cache_dropin_exists() && method_exists( $GLOBALS[ 'wp_object_cache' ], 'redis_status' );
113
- }
114
 
115
- public function get_redis_client_name() {
116
- global $wp_object_cache;
117
- return isset( $wp_object_cache->redis_client ) ? $wp_object_cache->redis_client : null;
118
- }
119
 
120
- public function get_redis_scheme() {
121
- return defined( 'WP_REDIS_SCHEME' ) ? WP_REDIS_SCHEME : 'tcp';
122
- }
123
 
124
- public function get_redis_host() {
125
- return defined( 'WP_REDIS_HOST' ) ? WP_REDIS_HOST : '127.0.0.1';
126
- }
127
 
128
- public function get_redis_port() {
129
- return defined( 'WP_REDIS_PORT' ) ? WP_REDIS_PORT : 6379;
130
- }
131
 
132
- public function get_redis_path() {
133
- return defined( 'WP_REDIS_PATH' ) ? WP_REDIS_PATH : null;
134
  }
135
 
136
- public function get_redis_database() {
137
- return defined( 'WP_REDIS_DATABASE' ) ? WP_REDIS_DATABASE : 0;
138
- }
139
 
140
- public function get_redis_password() {
141
- return defined( 'WP_REDIS_PASSWORD' ) ? WP_REDIS_PASSWORD : null;
142
- }
143
 
144
- public function get_redis_cachekey_prefix() {
145
- return defined( 'WP_CACHE_KEY_SALT' ) ? WP_CACHE_KEY_SALT : null;
146
- }
 
 
 
 
 
 
 
 
147
 
148
- public function get_redis_maxttl() {
149
- return defined( 'WP_REDIS_MAXTTL' ) ? WP_REDIS_MAXTTL : null;
150
  }
151
 
152
  public function get_redis_status() {
153
 
154
  global $wp_object_cache;
155
 
156
- if ( ! $this->object_cache_dropin_exists() ) {
157
- return __( 'Not installed', 'redis-cache' );
158
  }
159
 
160
- if ( $this->validate_object_cache_dropin() ) {
161
- return $wp_object_cache->redis_status() ? __( 'Connected', 'redis-cache' ) : __( 'Not connected', 'redis-cache' );
 
 
 
 
 
 
 
 
162
  }
163
 
164
- return __( 'Unknown', 'redis-cache' );
 
 
 
 
 
 
165
 
 
 
 
 
 
 
166
  }
167
 
168
  public function show_admin_notices() {
@@ -181,15 +207,13 @@ class RedisObjectCache {
181
  $dropin = get_plugin_data( WP_CONTENT_DIR . '/object-cache.php' );
182
  $plugin = get_plugin_data( plugin_dir_path( __FILE__ ) . '/includes/object-cache.php' );
183
 
184
- // outdated `object-cache.php` notice
185
  if ( version_compare( $dropin[ 'Version' ], $plugin[ 'Version' ], '<' ) ) {
186
- $message = sprintf( __( 'The Redis object cache drop-in is outdated. <a href="%s">Update it now</a>.', 'redis-cache' ), $url );
187
  }
188
 
189
  } else {
190
 
191
- // show foreign `object-cache.php` notice
192
- $message = sprintf( __( 'Another object cache drop-in is already active. To use Redis, <a href="%s">please replace it now</a>.', 'redis-cache' ), $url );
193
 
194
  }
195
 
2
  /*
3
  Plugin Name: Redis Object Cache
4
  Plugin URI: http://wordpress.org/plugins/redis-cache/
5
+ Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication and clustering.
6
+ Version: 1.3
7
  Text Domain: redis-cache
8
  Domain Path: /languages
9
  Author: Till Krüss
85
 
86
  }
87
 
88
+ public function show_servers_list() {
89
+
90
+ require_once plugin_dir_path( __FILE__ ) . '/includes/servers-list.php';
91
+
92
+ $table = new Servers_List;
93
+ $table->prepare_items();
94
+ $table->display();
95
+
96
+ }
97
+
98
  public function add_plugin_actions_links( $links ) {
99
 
100
  // add settings link to plugin actions
119
  }
120
 
121
  public function validate_object_cache_dropin() {
 
 
122
 
123
+ if ( ! $this->object_cache_dropin_exists() ) {
124
+ return false;
125
+ }
 
126
 
127
+ $dropin = get_plugin_data( WP_CONTENT_DIR . '/object-cache.php' );
128
+ $plugin = get_plugin_data( plugin_dir_path( __FILE__ ) . '/includes/object-cache.php' );
 
129
 
130
+ if ( strcmp( $dropin[ 'PluginURI' ], $plugin[ 'PluginURI' ] ) !== 0 ) {
131
+ return false;
132
+ }
133
 
134
+ return true;
 
 
135
 
 
 
136
  }
137
 
138
+ public function get_status() {
 
 
139
 
140
+ if ( ! $this->object_cache_dropin_exists() ) {
141
+ return __( 'Disabled', 'redis-cache' );
142
+ }
143
 
144
+ if ( $this->validate_object_cache_dropin() ) {
145
+ if ( $this->get_redis_status() ) {
146
+ return __( 'Connected', 'redis-cache' );
147
+ }
148
+
149
+ if ( $this->get_redis_status() === false ) {
150
+ return __( 'Not Connected', 'redis-cache' );
151
+ }
152
+ }
153
+
154
+ return __( 'Unknown', 'redis-cache' );
155
 
 
 
156
  }
157
 
158
  public function get_redis_status() {
159
 
160
  global $wp_object_cache;
161
 
162
+ if ( $this->validate_object_cache_dropin() ) {
163
+ return $wp_object_cache->redis_status();
164
  }
165
 
166
+ return;
167
+
168
+ }
169
+
170
+ public function get_redis_client_name() {
171
+
172
+ global $wp_object_cache;
173
+
174
+ if ( isset( $wp_object_cache->redis_client ) ) {
175
+ return $wp_object_cache->redis_client;
176
  }
177
 
178
+ if ( defined( 'WP_REDIS_CLIENT' ) ) {
179
+ return WP_REDIS_CLIENT;
180
+ }
181
+
182
+ return null;
183
+
184
+ }
185
 
186
+ public function get_redis_cachekey_prefix() {
187
+ return defined( 'WP_CACHE_KEY_SALT' ) ? WP_CACHE_KEY_SALT : null;
188
+ }
189
+
190
+ public function get_redis_maxttl() {
191
+ return defined( 'WP_REDIS_MAXTTL' ) ? WP_REDIS_MAXTTL : null;
192
  }
193
 
194
  public function show_admin_notices() {
207
  $dropin = get_plugin_data( WP_CONTENT_DIR . '/object-cache.php' );
208
  $plugin = get_plugin_data( plugin_dir_path( __FILE__ ) . '/includes/object-cache.php' );
209
 
 
210
  if ( version_compare( $dropin[ 'Version' ], $plugin[ 'Version' ], '<' ) ) {
211
+ $message = sprintf( __( 'The Redis object cache drop-in is outdated. Please <a href="%s">update it now</a>.', 'redis-cache' ), $url );
212
  }
213
 
214
  } else {
215
 
216
+ $message = sprintf( __( 'Another object cache drop-in was found. To use Redis, <a href="%s">please replace it now</a>.', 'redis-cache' ), $url );
 
217
 
218
  }
219