Support » Plugin: WP Redis » The wp_cache_incr() function doesn’t work as expected

  • Resolved Gioni

    (@gioni)


    Hi Daniel!

    I’ve got the problem. The function always returns false when the plugin is active (the file is in the wp-content folder).

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

    (@danielbachhuber)

    Can you share steps to reproduce, please?

    And, just to confirm, the cache key you’re trying to increment already exists? wp_cache_incr() requires the key to already exist with a value:

    
    public function incr( $key, $offset = 1, $group = 'default' ) {
    	if ( empty( $group ) )
    		$group = 'default';
    
    	if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
    		$key = $this->blog_prefix . $key;
    
    	if ( ! $this->_exists( $key, $group ) )
    		return false;
    

    Thanks, I’ll try the code you’ve suggested.

    To be exact I’m trying to get the plugin working together with Batcache https://wordpress.org/plugins/batcache/. Batcache uses object cache to store rendered pages. To clear the cache it uses the following code

    $url_key = md5( $url );
    wp_cache_add("{$url_key}_version", 0, $batcache->group);
    $retval = wp_cache_incr("{$url_key}_version", 1, $batcache->group);

    It seems that code is not working now because I’m unable to clear the cache this way.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    That’s odd.

    Can you debug a bit further into the object cache code to see where specifically it might be failing?

    Hi, Daniel!

    It seems that it’s solved. There was an issue with default REDIS configuration. Sometimes REDIS wrote to the log: “Can’t save in background: fork: Cannot allocate memory”. After I had allowed overcommitting memory the issue was gone.

    Just in case:

    1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf
    2. Run the command sysctl vm.overcommit_memory=1

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Glad you were able to sort it out, @gioni. When in doubt, always check the logs 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘The wp_cache_incr() function doesn’t work as expected’ is closed to new replies.