Support » Plugin: Redis Object Cache » Flush Redis from a PHP command?

  • Resolved Thomas Jarvis

    (@thomasjarvisdesign)


    We have REDIS running and WP-Rocket on this site.

    We use WP All Import to sync pricing and stock. At the end of the sync run WP-Rocket is cleared using a purge cache command via a small php snippet. This happens automatically after the import finishes.

    Some of the prices shown on the home page seem to be cached causing incorrect prices after a data import.

    Is there a way to run the flush redis cache action via a php command that I could insert at the end of my import? This would clear the object cache at the same time as the page cache preventing outdated prices showing.

    Set up wp config as below with the domains and ports changed:

    define(‘WP_CACHE_KEY_SALT’, ‘domainname.com’ );
    define(‘WP_REDIS_PASSWORD’, ‘ourredisdbpassword’ );
    define(‘WP_REDIS_HOST’, ‘127.0.0.123’);
    define(‘WP_REDIS_PORT’, ‘1234’);
    define(‘WP_REDIS_DATABASE’, 1 );
    define(‘WP_REDIS_SELECTIVE_FLUSH’, true);
    define(‘WP_REDIS_MAXTTL’, ‘1800’);

    • This topic was modified 1 month, 3 weeks ago by Thomas Jarvis. Reason: more info

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Julie

    (@julieadrienne)

    Yes, you can flush using wp_cache_flush(). Ideally run it before and after the import.

    Thread Starter Thomas Jarvis

    (@thomasjarvisdesign)

    Think this would work?

    <?php

    function redispurge_after_xml_import( $import_id, $import ) {
    // Specify ID of import
    if ($import_id == 25) {
    // Clear redis cache.
    wp_cache_flush();
    // Clear wp-rocket cache.
    // Also preload the cache if the Preload is enabled.
    if ( function_exists( ‘rocket_clean_domain’ ) ) {
    rocket_clean_domain();
    }
    // Clear minified CSS and JavaScript files.
    if ( function_exists( ‘rocket_clean_minify’ ) ) {
    rocket_clean_minify();
    }
    }
    }

    add_action( ‘pmxi_after_xml_import’, ‘redispurge_after_xml_import’, 10, 2 );

    ?>

    • This reply was modified 1 month, 2 weeks ago by Thomas Jarvis.
    • This reply was modified 1 month, 2 weeks ago by Thomas Jarvis. Reason: Feedback from Till Kruss
    Plugin Author Till Krüss

    (@tillkruess)

    No, you can’t declare functions inside of functions. Just call wp_cache_flush().

    Thread Starter Thomas Jarvis

    (@thomasjarvisdesign)

    Thanks @tillkruess!

    I have edited my previous post.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.