Title: Flush Redis from a PHP command?
Last modified: January 11, 2024

---

# Flush Redis from a PHP command?

 *  Resolved [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/)
 * (@thomasjarvisdesign)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/)
 * 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 2 years, 5 months ago by [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/).
      Reason: more info
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fflush-redis-from-a-php-command%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [Julie](https://wordpress.org/support/users/julieadrienne/)
 * (@julieadrienne)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/#post-17338991)
 * Yes, you can flush using `wp_cache_flush()`. Ideally run it before and after 
   the import.
 *  Thread Starter [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/)
 * (@thomasjarvisdesign)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/#post-17339033)
 * Think this would work?
 * > <?php
   > function redispurge_after_xml_import( $import_id, $import ) {
   > // Specify ID
   > of importif ($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 2 years, 5 months ago by [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/).
    -  This reply was modified 2 years, 5 months ago by [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/).
      Reason: Feedback from Till Kruss
 *  Plugin Author [Till Krüss](https://wordpress.org/support/users/tillkruess/)
 * (@tillkruess)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/#post-17339051)
 * No, you can’t declare functions inside of functions. Just call `wp_cache_flush()`.
 *  Thread Starter [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/)
 * (@thomasjarvisdesign)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/#post-17339085)
 * Thanks [@tillkruess](https://wordpress.org/support/users/tillkruess/)!
 * I have edited my previous post.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Flush Redis from a PHP command?’ is closed to new replies.

 * ![](https://ps.w.org/redis-cache/assets/icon-256x256.gif?rev=2568513)
 * [Redis Object Cache](https://wordpress.org/plugins/redis-cache/)
 * [Support Threads](https://wordpress.org/support/plugin/redis-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/redis-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redis-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redis-cache/reviews/)

## Tags

 * [automated](https://wordpress.org/support/topic-tag/automated/)
 * [cache](https://wordpress.org/support/topic-tag/cache/)
 * [clear cache](https://wordpress.org/support/topic-tag/clear-cache/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [redis](https://wordpress.org/support/topic-tag/redis/)

 * 5 replies
 * 3 participants
 * Last reply from: [thomasjarvisdesign](https://wordpress.org/support/users/thomasjarvisdesign/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/flush-redis-from-a-php-command/#post-17339085)
 * Status: resolved