• As I have multiple WordPress builds all running on the same server, either NAMESPACING or DBID is a must.

    Currently the SET “Redis Database ID” seems to do nothing, as it does not WRITE to that DB ID (but instead chooses by BUILD order…so the first site setup was given 1…second was given 2…etc etc).

    This would be fine … if on PURGE the DB ID stayed the same … but as you’d imagine it does not.

    So because of how DB and Object caching work, Website ABC … has pieces of Website CBA … and Website XYZ has pieces of CBA…etc etc

    Please verify that the SET DBID actually works. And please also (for safety purposes) modify the “KEY” name to either include this DB ID or add some type of GLOBAL ID value.

    Obviously “Multi-site” provided the “Blog_ID” … but for those who are not using Multi-Site there needs to be a more robust solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter webmdt

    (@webmdt)

    Update: After properly purging the Cache from Redis, I can clearly see that the plugin is not using the “DB ID” at all. It instead defaults to write ALL cache to the “DB 1”.

    Running a Select Query within REDIS-CLI, I can see all of the cache pooling into DB 1.

    I have fixed the NAMESPACING issue when running multiple WordPress Installs on the same sub-domain,

    Cache_Base.php LINE 180 (add the new function “getSiteInfo” and modify the “*key*” functions)

    	/**
    	 * Grabs the DB Name 	
    	 *	
    	*/	
    	public function getSiteInfo(){
    		
    		/*Grab the RAW DB from the WP Config*/
    		$rawDB = DB_NAME;
    		
    		/*Force the info to be lowercase*/
    		$siteInfo = strtolower($rawDB);
    		
    		/*If an underscore exists .. only output everything AFTER it*/
    		if (($underscoreCheck = strpos($rawDB, "_")) !== FALSE) { 
    			$siteInfo = substr($siteInfo, $underscoreCheck + 1); 
    		}
    			
    		return $siteInfo;
    	}
    
    	/**
    	 * Constructs key version key
    	 *
    	 * @param unknown $group
    	 * @return string
    	 */
    	protected function _get_key_version_key( $group = '' ) {	
    		return sprintf( 'w3tc_%s_%d_%s_%s_%d_key_version', $this->getSiteInfo(), $this->_blog_id, $this->_module, $group, $this->_instance_id );
    	}
    
    	/**
    	 * Constructs item key
    	 *
    	 * @param unknown $name
    	 * @return string
    	 */
    	public function get_item_key( $name ) {
    		$key = sprintf( 'w3tc_%s_%s_%d_%s_%s', $this->getSiteInfo(), $this->_host, $this->_blog_id, $this->_module, $name );
    		return $key;
    	}

    Note: This fix works by taking the Table DB Name, and using it to modify the key name. You can modify this function as you see fit

    Hey @webmdt,

    Nice catch on the Redis DB issue.

    I see that you have found a workaround that works for you.

    If you’re still interested in how to make W3TC use the correct Redis DB, here’s the patch: https://github.com/charlesLF/fix-w3tc/commit/c35f7815d173489655835bf2f6f4bf3a777e0628

    Cheers

    Thread Starter webmdt

    (@webmdt)

    Hello Charles,

    Wow this is very helpful. My FIX doesn’t solve the DB ID issue, it merely just namespaces the KEYS to ensure there isn’t any collisions between the WordPress Builds.

    This fix looks great, I’ll apply this on my next deployment.

    Thanks

    I think I will use your patch (or a variation of it) for the key namespacing on my local installs. This is indeed helpful for the cases where different WP installs reside on different subfolders of the same domain.

    I’ll push it to the same repo branch when done, so you might want to keep an eye ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Redis DB Instances – Fail’ is closed to new replies.