Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow redis cache storage to delete only cached keys #43719

Open
wants to merge 2 commits into
base: 4.4-dev
Choose a base branch
from

Conversation

yossibeck
Copy link

since the same redis can be used for cache + session (or other stuff) only keys that match the -cache- should be used

Pull Request for Issue #43718

Summary of Changes

this code would delete ALL keys that aren't in a group regardless of being a cache or not
e.g. deleting keys that handle session or any other stuff

            if (strpos($key, $secret . self::CACHE_KEY . $group . '-') !== 0 && $mode !== 'group') {
                static::$_redis->del($key);

the code
static::$_redis->keys('*' . self::CACHE_KEY . '*');
instead of
static::$_redis->keys('*');
makes sure redis cache ONLY handles cache keys

Testing Instructions

  1. setup a redis server
  2. define that server as a cache_handler + session_handler
  3. use the same server for redis_server_host + session_redis_server_host
  4. start caching stuff - and login
    on the first delete of a non group cache - you'll lose all of your sessions
    the easiest way to do that is to connect to redis with
redis-cli -h <host name>
HOST-NAME:PORT>monitor

and you'll see after a while these commands:

HOST-NAME:PORT>KEYS "*"
HOST-NAME:PORT>DEL <session-id 1>
HOST-NAME:PORT>DEL <session-id 2>
HOST-NAME:PORT>DEL <session-id 3>
....

Actual result BEFORE applying this Pull Request

seeing the

HOST-NAME:PORT>KEYS "*"
HOST-NAME:PORT>DEL <session-id 1>
HOST-NAME:PORT>DEL <session-id 2>
HOST-NAME:PORT>DEL <session-id 3>
....

Expected result AFTER applying this Pull Request

not seeing

HOST-NAME:PORT>KEYS "*"
HOST-NAME:PORT>DEL <session-id 1>
HOST-NAME:PORT>DEL <session-id 2>
HOST-NAME:PORT>DEL <session-id 3>
....

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

since the same redis can be used for cache + session (or other stuff)
only keys that match the *-cache-* should be used
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
* This constant is used as a prefix for all cache keys to ensure they are easily identifiable
* and to avoid potential conflicts with other keys in the Redis store.
*
* @since 4.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 4.4
* @since __DEPLOY_VERSION__

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

Successfully merging this pull request may close these issues.

None yet

4 participants