Drupal cache clear also clearing Redis

Created on 2 November 2023, 8 months ago
Updated 20 May 2024, about 1 month ago

Problem/Motivation

We want to empty the Redis cache at the same time as we do a drupal Cache Clear via drush.

There are 3 issues with activity on this issue in the last year.
We are using the MR from one of these closed issues.
I opened this new issue to see if we can restart the discussion, or perhaps reopen the issue with the most comments on this.

Proposed resolution

Use the code from the MR in this issue: https://www.drupal.org/project/redis/issues/2765895 πŸ› Currently Drush Cr or Cache Clear UI does not flush Redis cache Fixed

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands Johan den Hollander

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Johan den Hollander
  • First commit to issue fork.
  • πŸ‡«πŸ‡·France pbonnefoi

    @johan-den-hollander I opened an MR with the patch from #2765895 (with little improvements) I have other ideas, but need to find time to implement it.

    I made this feature as an option with the following settings :

    You can set flush_redis_on_drupal_flush_cache to TRUE to flush Redis cache when clearing all Drupal cache.

    $settings['flush_redis_on_drupal_flush_cache'] = TRUE;

    You can set flushdb and flushdb_async to TRUE to use the Redis native flushDB when clearing Drupal cache.

    $settings['redis_flushdb'] = TRUE;
    $settings['redis_flushdb_async'] = TRUE;

    You need to set a redis base properly to use this feature. By default, Redis gets cleared getting all keys using cache_prefix. This is not recommended on production as it could be an expensive task to clear all the keys.

  • πŸ‡³πŸ‡±Netherlands Johan den Hollander

    Thanks. Will give this a try.
    We use the clearing of the Redis on drush cr on two identical sites.
    However one of the sites is giving zend_memory_heap error when we do so.
    When we first do a redis-flush and then a drush cr without the patch from this issue we have no errors.

    The other site has no problem clearing Redis via a drush cr.

    I'm not sure if this error is only because of using this patch or that maybe we have some other issues like hosting configuration.
    Althoug both of these sites are configured in the same way...

  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany Harlor Berlin

    The redis client does not necessarily have databases. For instance the redis cluster cleint ✨ Implement initial RedisCluster client integration Needs work does not have databases.

    How ever with redis_flushdb=FALSE one actually does not need the DB index anyway - So I would suggest to move the redis index/DB safety checks and the ->select into the flushdb block.

  • πŸ‡«πŸ‡·France saadaouiyos

    saadaouiyos β†’ changed the visibility of the branch 3398797-drupal-cache-clear to hidden.

  • πŸ‡ΈπŸ‡°Slovakia hideaway

    There is a problem with the patch when prefix is an array and results into an error when logging messages. Correct version in the last else statement should be '@prefix' => $p:

    else {
      foreach ($prefix as $p) {
        $keys = $redis->keys('*' . $p . '*');
        $redis->del($keys);
        Drupal::logger('redis')->info(t('Redis Keys deleted for prefix @prefix', ['@prefix' => $p]));
        Drupal::messenger()->addMessage(t('Redis Keys deleted for prefix @prefix', ['@prefix' => $p]));
      }
    }
    

    As we don't use MR diff or patch files in our builds as they are dangerous, attaching a patch file to have working static patch.

  • πŸ‡ΈπŸ‡°Slovakia hideaway

    Forgotten patch file :)

Production build 0.69.0 2024