示例#1
0
 public function test_wp_redis_get_info()
 {
     if (!class_exists('Redis')) {
         $this->markTestSkipped('PHPRedis extension not available.');
     }
     $data = wp_redis_get_info();
     $this->assertEquals('connected', $data['status']);
     $this->assertInternalType('int', $data['key_count']);
     $this->assertRegExp('/[\\d]+\\/sec/', $data['instantaneous_ops']);
     $this->assertRegExp('/[\\d]+\\sdays/', $data['uptime']);
 }
示例#2
0
 /**
  * Provide details on the Redis connection.
  *
  * ## OPTIONS
  *
  * [--reset]
  * : Reset Redis stats. Only affects `lifetime_hitrate` currently.
  *
  * [--field=<field>]
  * : Get the value of a particular field.
  *
  * [--format=<format>]
  * : Render results in a particular format.
  * ---
  * default: table
  * options:
  *   - table
  *   - json
  *   - yaml
  * ---
  *
  * ## EXAMPLES
  *
  *     $ wp redis info
  *     +-------------------+-----------+
  *     | Field             | Value     |
  *     +-------------------+-----------+
  *     | status            | connected |
  *     | used_memory       | 529.25K   |
  *     | uptime            | 0 days    |
  *     | key_count         | 20        |
  *     | instantaneous_ops | 9/sec     |
  *     | lifetime_hitrate  | 53.42%    |
  *     | redis_host        | 127.0.0.1 |
  *     | redis_port        | 6379      |
  *     | redis_auth        |           |
  *     | redis_database    | 0         |
  *     +-------------------+-----------+
  *
  *     $ wp redis info --field=used_memory
  *     529.38K
  *
  *     $ wp redis info --reset
  *     Success: Redis stats reset.
  */
 public function info($_, $assoc_args)
 {
     global $wp_object_cache, $redis_server;
     if (!defined('WP_REDIS_OBJECT_CACHE') || !WP_REDIS_OBJECT_CACHE) {
         WP_CLI::error('WP Redis object-cache.php file is missing from the wp-content/ directory.');
     }
     if ($wp_object_cache->is_redis_connected && WP_CLI\Utils\get_flag_value($assoc_args, 'reset')) {
         // Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928
         if ($wp_object_cache->redis->eval("return redis.call('CONFIG','RESETSTAT')")) {
             WP_CLI::success('Redis stats reset.');
         } else {
             WP_CLI::error("Couldn't reset Redis stats.");
         }
     } else {
         $data = wp_redis_get_info();
         if (is_wp_error($data)) {
             WP_CLI::error($data);
         }
         $formatter = new \WP_CLI\Formatter($assoc_args, array_keys($data));
         $formatter->display_item($data);
     }
 }