Skip to content

Conversation

@Dyras
Copy link
Contributor

@Dyras Dyras commented Oct 10, 2025

Hello! As mentioned in this thread:
https://discourse.roots.io/t/trellis-v1-26-1-released/29972

wp cache flush seems to remove everything inside of Redis. This includes anything added by the Redis Facade which is a bit of a problem since I (at least) am storing stuff in there. 😅

This pull request adds a check to see if Redis is enabled. If so, redis-cli is used to clean up the namespaces used by Redis Object Cache which in practice means "wp" and "site_name_wp".

@Dyras
Copy link
Contributor Author

Dyras commented Oct 13, 2025

Update:

I originally only tested this on staging and testing where it works fine, but on a larger production site, this is incredibly slow. Here's an alternative solution:

shell: >
      redis-cli --scan --pattern '*' |
      grep -E "^{{ (vault_wordpress_sites[item.key].db_user | default(item.key | underscore)) }}_wp:|^wp:" |
      sed 's/^/UNLINK /' |
      redis-cli --pipe

This is also quite slow, but you can actually notice the keys leaving the database by using "INFO memory" so it's infinitely faster compared to the alternative.

Any other suggestions appreciated :)

@swalkinshaw
Copy link
Member

Yeah I don't think we can (or should) include this solution for those issues. Ideally your non-object cache Redis key are stored separately. Can you use a separate DB for them? Not sure how the wp flush cache would know about the Redis DB

@Dyras
Copy link
Contributor Author

Dyras commented Oct 14, 2025

Yeah it makes little to no sense to me that wp cache flush should clear out the entire Redis. The behavior is really odd, to say the least.

I could definitely try to use a separate DB, but there has to be a clean way to prevent it from deleting the entire database. Hmm. If not, I suppose I could look at setting up a separate DB.

@Dyras
Copy link
Contributor Author

Dyras commented Oct 14, 2025

Ok I did some more digging around. Apparently, adding..
Config::define('WP_REDIS_SELECTIVE_FLUSH', true);
.. to development.php seems to make wp cache flush behave as intended. The Facade keys are untouched but the object cache is emptied.

Would you be open to adding that to application.php? If so, I can do a PR.

If not, maybe we can add it somewhere in the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants