## Flush redis cache daily via wpcron
```php
// 1. Flush Redis cache function
function flush_redis_cache_daily() {
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
error_log('Redis cache flushed at: ' . current_time('Y-m-d H:i:s'));
}
}
add_action('flush_redis_cache_event', 'flush_redis_cache_daily');
// 2. Schedule the event at 1 AM if not already scheduled
function schedule_redis_cache_cron() {
if (!wp_next_scheduled('flush_redis_cache_event')) {
// Schedule at next 1:00 AM in the WordPress timezone
$timezone = wp_timezone(); // WordPress timezone setting
$datetime = new DateTime('tomorrow 1:00', $timezone);
wp_schedule_event($datetime->getTimestamp(), 'daily', 'flush_redis_cache_event');
}
}
add_action('init', 'schedule_redis_cache_cron');
```