Plugin Directory

Changeset 1196126


Ignore:
Timestamp:
07/10/2015 09:01:07 AM (11 years ago)
Author:
rahul286
Message:

Improved Redis Support

Location:
nginx-helper/trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • nginx-helper/trunk/admin/admin.php

    r1146795 r1196126  
    119119                return;
    120120            }
    121             $purge_url = esc_url( add_query_arg( array( 'nginx_helper_action' => 'purge', 'nginx_helper_urls' => 'all' ) ) );
     121            $purge_url = add_query_arg( array( 'nginx_helper_action' => 'purge', 'nginx_helper_urls' => 'all' ) );
    122122            $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
    123123            $admin_bar->add_menu( array( 'id' => 'nginx-helper-purge-all', 'title' => __( 'Purge Cache', 'nginx-helper' ), 'href' => $nonced_url, 'meta' => array( 'title' => __( 'Purge Cache', 'nginx-helper' ), ), ) );
  • nginx-helper/trunk/admin/install.php

    r827352 r1196126  
    9494        $rt_wp_nginx_helper_get_options[ 'purge_page_on_deleted_comment' ] = 1;
    9595
     96        $rt_wp_nginx_helper_get_options[ 'purge_method' ] = 'get_request';
     97
    9698        return $rt_wp_nginx_helper_get_options;
    9799    }
  • nginx-helper/trunk/admin/lib/nginx-general.php

    r1190839 r1196126  
    387387                        fclose( $log );
    388388                    }
    389                     if ( is_writable( $path . 'nginx.log' ) ) {
    390                         $rt_wp_nginx_purger->log( "+++++++++" );
    391                         $rt_wp_nginx_purger->log( "+Log Test" );
    392                         $rt_wp_nginx_purger->log( "+++++++++" );
    393                     }
     389                   
    394390                    if ( !is_writable( $path . 'nginx.log' ) ) {
    395391                        ?>
  • nginx-helper/trunk/includes/redis-delete.php

    r1190839 r1196126  
    33//TODO:: phpRedis based implementation https://github.com/phpredis/phpredis#eval
    44//include predis (php implementation for redis)
    5 require_once 'predis.php';
    6 Predis\Autoloader::register();
    75
    8 global $myredis, $rt_wp_nginx_helper;
     6global $myredis, $rt_wp_nginx_helper, $redis_api, $lua;
    97
    108$host = $rt_wp_nginx_helper->options['redis_hostname'];
    119$port = $rt_wp_nginx_helper->options['redis_port'];
     10$redis_api = '';
     11
     12if ( class_exists( 'Redis' ) ) { // Use PHP5-Redis if installed.
     13    try {
     14        $myredis = new Redis();
     15        $myredis->connect( $host, $port );
     16        $redis_api = 'php-redis';
     17    } catch ( Exception $e ) {}
     18} else {
     19    if( ! class_exists( 'Predis\Autoloader' ) ) {
     20        require_once 'predis.php';
     21    }
     22    Predis\Autoloader::register();
     23   
     24    //redis server parameter
     25    $myredis = new Predis\Client( [
     26        'host' => $host,
     27        'port' => $port,
     28    ] );
     29    //connect
     30    try {
     31        $myredis->connect();
     32        $redis_api = 'predis';
     33    } catch ( Exception $e ) {}
     34}
    1235
    1336//Lua Script
     
    2245LUA;
    2346
    24 //redis server parameter
    25 $myredis = new Predis\Client( [
    26     'host' => $host,
    27     'port' => $port,
    28         ] );
    29 
    30 //connect
    31 try {
    32     $myredis->connect();
    33 } catch ( Exception $e ) {
    34    
    35 }
    36 
    37 
    3847/*
    3948  Delete multiple single keys without wildcard using redis pipeline feature to speed up things
     
    4251function delete_multi_keys( $key )
    4352{
    44     global $myredis;
    45     $matching_keys = $myredis->keys( $key );
    46     foreach ( $matching_keys as $key => $value ) {
    47         $myredis->executeRaw( ['DEL', $value ] );
    48     }
     53    global $myredis, $redis_api;
     54    if ( !empty( $myredis ) ) {
     55        $matching_keys = $myredis->keys( $key );
     56        if( $redis_api == 'predis') {
     57            foreach ( $matching_keys as $key => $value ) {
     58                $myredis->executeRaw( ['DEL', $value ] );
     59            }
     60        } else if( $redis_api == 'php-redis') {
     61            return $myredis->del( $matching_keys );
     62        }
     63    } else {
     64        return false;
     65    }
    4966}
    5067
     
    7087function delete_single_key( $key )
    7188{
    72     global $myredis;
     89    global $myredis, $redis_api;
     90   
    7391    if ( !empty( $myredis ) ) {
    74         return $myredis->executeRaw( ['DEL', $key ] );
     92        if( $redis_api == 'predis') {
     93            return $myredis->executeRaw( ['DEL', $key ] );
     94        } else if( $redis_api == 'php-redis') {
     95            return $myredis->del( $key );
     96        }
    7597    } else {
    7698        return false;
     
    85107function delete_keys_by_wildcard( $pattern )
    86108{
    87     global $myredis, $lua;
     109    global $myredis, $lua, $redis_api;
    88110    /*
    89111      Lua Script block to delete multiple keys using wildcard
     
    95117      Call redis eval and return value from lua script
    96118     */
    97     if ( !empty( $myredis ) ) {
    98         return $myredis->eval( $lua, 1, $pattern );
    99     } else {
     119    if ( ! empty( $myredis ) ) {
     120        if( $redis_api == 'predis') {
     121            return $myredis->eval( $lua, 1, $pattern );
     122        } else if( $redis_api == 'php-redis') {
     123            return $myredis->eval( $lua, array( $pattern ), 1 );
     124        }
     125    } else {
    100126        return false;
    101127    }
  • nginx-helper/trunk/nginx-helper.php

    r1191882 r1196126  
    33  Plugin Name: Nginx Helper
    44  Plugin URI: https://rtcamp.com/nginx-helper/
    5   Description: Cleans nginx's fastcgi/proxy cache whenever a post is edited/published. Also does few more things.
    6   Version: 1.9.2
     5  Description: Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does few more things.
     6  Version: 1.9.3
    77  Author: rtCamp
    88  Author URI: https://rtcamp.com
     
    129129            $skip_status = array( 'auto-draft', 'draft', 'inherit', 'trash', 'pending' );
    130130            $purge_status = array( 'publish', 'future' );
    131            
     131
    132132            if ( !$this->options['enable_purge'] || in_array( $old_status, $skip_status ) ) {
    133133                return;
    134134            }
    135            
     135
    136136            if( in_array( $old_status, $purge_status ) || in_array( $new_status, $purge_status ) ) {
    137137                $rt_wp_nginx_purger->log( "Purge post on transition post STATUS from " . $old_status . " to " . $new_status );
  • nginx-helper/trunk/readme.txt

    r1191882 r1196126  
    11=== Nginx Helper ===
    2 Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, Darren Slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel
    3 Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, rewrite, permalinks
     2Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123
     3Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
    44Requires at least: 3.0
    55Tested up to: 4.2.2
    6 Stable tag: 1.9.2
    7 later (of-.1course)
    8 Fix purging for custom post types
    9 
     6Stable tag: 1.9.3
    107License: GPLv2 or later (of-course)
    118License URI: http://www.gnu.org/licenses/gpl-2.0.html
    129Donate Link: http://rtcamp.com/donate/
    1310
    14 Cleans nginx's fastcgi/proxy cache whenever a post is edited/published. Also does a few more things.
     11Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does few more things.
    1512
    1613== Description ==
    1714
    18151. Removes `index.php` from permalinks when using WordPress with nginx.
     161. Adds support for purging redis-cache when used as full-page cache created using [nginx-srcache-module](https://github.com/openresty/srcache-nginx-module#caching-with-redis)
    19171. Adds support for nginx fastcgi_cache_purge & proxy_cache_purge directive from [module](https://github.com/FRiCKLE/ngx_cache_purge "ngx_cache_purge module"). Provides settings so you can customize purging rules.
    20181. Adds support for nginx `map{..}` on a WordPress-multisite network installation. Using it, Nginx can serve PHP file uploads even if PHP/MySQL crashes. Please check the tutorial list below for related Nginx configurations.
     
    117115== Changelog ==
    118116
     117= 1.9.3 =
     118* Added PhpRedis API support.
     119* Added redis-lua script support to purge complete cache very fast.
     120* Added composer.json support
     121* Fixed cache purging link in admin bar.
     122* Updated the initial settings to include the 'purge_method' [#99](https://github.com/rtCamp/nginx-helper/pull/99) - by
     123[gagan0123](https://github.com/gagan0123)
     124
    119125= 1.9.2 =
    120126Fix purging for Redis cache and FastCGI cache
     
    306312== Upgrade Notice ==
    307313
    308 = 1.9 =
    309 Added Redis cache purge support.
     314= 1.9.3 =
     315* Added PhpRedis API support.
     316* Fixed cache purging link in admin bar.
  • nginx-helper/trunk/redis-purger.php

    r1191882 r1196126  
    663663            $this->log( "* Purged Everything!" );
    664664            $this->log( "* * * * *" );
    665             delete_multi_keys("*");
    666         }
     665            //delete_multi_keys("*");
     666            delete_keys_by_wildcard("*");
     667        }
    667668
    668669    }
  • nginx-helper/trunk/tests/functional/src/purge-method-get-request-page-test.js

    r1190839 r1196126  
    5454      .url(data.URLS.LOGIN + urlp)
    5555      .click('.post-edit-link')
    56 
    57       .clearValue('textarea[id="content"]')
    58       .setValue('textarea[id="content"]', "test page content updated")
     56      .clearValue('#title')
     57      .setValue('#title', "test page title updated")
    5958      .click('#publish')
     59      .pause(2000)
    6060      .wplogout()
    6161      .url(data.URLS.LOGIN + urlp)
    62       .assert.containsText("#main", "test page content updated")
     62      .verify.containsText(".entry-title", "test page title updated")
     63      .verify.containsText(".site-main", "test page created for testing")
    6364},
    6465
  • nginx-helper/trunk/tests/functional/src/purge-method-unlink-files-page-test.js

    r1190839 r1196126  
    5454      .url(data.URLS.LOGIN + urlp)
    5555      .click('.post-edit-link')
    56 
    57       .clearValue('textarea[id="content"]')
    58       .setValue('textarea[id="content"]', "test page content updated")
     56      .clearValue('#title')
     57      .setValue('#title', "test page title updated")
    5958      .click('#publish')
     59      .pause(2000)
    6060      .wplogout()
    6161      .url(data.URLS.LOGIN + urlp)
    62       .assert.containsText("#main", "test page content updated")
     62      .verify.containsText(".entry-title", "test page title updated")
     63      .verify.containsText(".site-main", "test page created for testing")
    6364},
    6465
Note: See TracChangeset for help on using the changeset viewer.