function clear_wp_redis_cache() { include_once "predis5.2.php"; //we need this to use Redis inside of PHP $args = array('post_type' => 'any', 'posts_per_page' => -1); $wp_query = new WP_Query($args); // to get all Posts $redis = new Predis_Client(); // Loop all posts and clear the cache $i = 0; while ($wp_query->have_posts()) { $wp_query->the_post(); $incremented = false; $permalink = get_permalink(); $redis_key = md5($permalink); $redis_ssl_key = 'ssl_' . $redis_key; if ($redis->exists($redis_key) == true) { $redis->del($redis_key); $i++; $incremented = true; } if ($redis->exists($redis_ssl_key) == true) { $redis->del($redis_ssl_key); if (!$incremented) { $i++; } } } echo $i . " of " . $wp_query->found_posts . " posts was cleared in cache"; die; }
} } catch (Predis_ClientException $e) { // catch predis-thrown exception die("Predis not found on your server or was unable to run. Error message: " . $e->getMessage()); } catch (Exception $e) { // catch other exceptions require $wp_blog_header_path; die("Error occurred. Error message: " . $e->getMessage()); } } //Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment if (refreshHasSecret($secret_string) || requestHasSecret($secret_string) || isRemotePageLoad($current_url, $websiteIp)) { if ($debug) { echo "<!-- manual refresh was required -->\n"; } $redis->del($redis_key); $redis->del("ssl_" . $redis_key); require $wp_blog_header_path; //$unlimited = get_option('wp-redis-cache-debug',false); $seconds_cache_redis = get_option('wp-redis-cache-seconds', 86400); // This page is cached, lets display it } else { if ($redis->exists($redis_key)) { if ($debug) { echo "<!-- serving page from cache: key: {$redis_key} -->\n"; } $cache = true; $html_of_page = $redis->get($redis_key); if ($compress) { $html_of_page = gzuncompress($html_of_page); }
public static function zsetAddAndReturn(Predis_Client $client, $keyName, array $values, $wipeOut = 0) { // $values: array(SCORE => VALUE, ...); if ($wipeOut == true) { $client->del($keyName); } foreach ($values as $value => $score) { $client->zadd($keyName, $score, $value); } return $values; }
/** * Required to pass unit tests * * @param string $id * @return void */ public function ___expire($id) { $this->_redis->del(self::PREFIX_KEY . $id); }
/** * @see sfCache */ public function remove($key) { return $this->redis->del($this->getKey($key), $this->getKey($key, '_lastmodified')); }