Support » Plugin: WP Redis » Document how to use wp_cache_add_redis_hash_groups()?

  • Resolved Jonathan Stegall

    (@jonathanstegall)



    Could you provide some documentation for how to use wp_cache_add_redis_hash_groups()? I’ve been looking through this forum and GitHub, and I think it might be helpful for me but I’ve been unable to figure out exactly what to do with it.

    The problem I hope to solve is that I was using the Redis Object Cache plugin, but I ran into two significant problems:

    1. The server ran into memory overload issues. Redis had 1GB of memory allocated to it, and our host is confident this should be enough for anything normal.
    2. We had users who were constantly being required to log in again multiple times within a day.

    Redis is clearly causing WordPress to ignore this code, which should keep users logged in for one year:

    
    if ( ! function_exists( 'keep_me_logged_in_for_1_year' ) ) :
    	add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );
    	function keep_me_logged_in_for_1_year( $expirein ) {
    		return 31556926; // 1 year in seconds
    	}
    endif;
    

    So my thinking was that if I could get Redis to ignore the group that stores user login information, maybe I could solve both issues.

    I’m curious if this seems like a reasonable expectation, and if it does, how I might use wp_cache_add_redis_hash_groups() to achieve this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    Hi @jonathanstegall,

    Thanks for the report.

    Based on what you’ve described, I don’t believe wp_cache_add_redis_hash_groups() is the appropriate solution for your problem. The function makes it possible to delete all cache values of a given group; it doesn’t exclude a cache group from the persistent object cache. For the latter, you’ll want to use the wp_cache_add_non_persistent_groups() function, which is also documented in the README. You’ll also need to track down which groups WordPress uses to store logged-in user data (I don’t recall off the top of my head).

    Before you go down this route, I’d recommend verifying that this is in fact your problem. You’ll want to explore what’s stored in Redis via Redis CLI and verify that it’s your user data that comprises the majority of data stored in Redis.

    Lastly, auth_cookie_expiration seems like a red-herring. It’s not related to the object cache.

    Thanks @danielbachhuber. I was assuming that I could separate the storage into groups in order to skip one or more of them, but I think you’re saying it would b ebetter to specify non persistent groups instead.

    Also, I thought the auth cookie was getting bypassed because of the Redis storage, but if that is not the case that makes sense.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    I was assuming that I could separate the storage into groups in order to skip one or more of them, but I think you’re saying it would b ebetter to specify non persistent groups instead.

    Correct — although the cache values will need to be set into separate groups by WordPress in the first place (e.g. wp_cache_set( 'user_data', $data, 'cache_group' );).

    @danielbachhuber do you have any knowledge of whether my issue with users having to log in every day is, in fact, Redis related? I’ve been looking through all the instances of wp_cache_set in core and in all my active plugins, and I’ve not been able to find anything that uses it to store user information at all, which is odd. But in any case, I’m not sure exactly how to determine whether Redis is at fault, and if it is, how to isolate it from Redis.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hand Built

    do you have any knowledge of whether my issue with users having to log in every day is, in fact, Redis related?

    I don’t off the top of my head, no. I haven’t come across this problem before, so I’d need to be able to debug to understand it further.

    If this is a Pantheon site, then you could create a cse environment and I could take a quick look to see if I could track it down. Pantheon doesn’t offer plugin debugging support outside of Pantheon sites though.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.