Giter Site home page Giter Site logo

rhubarbgroup / redis-cache Goto Github PK

View Code? Open in Web Editor NEW
401.0 21.0 143.0 4.14 MB

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

Home Page: https://wordpress.org/plugins/redis-cache/

License: GNU General Public License v3.0

CSS 1.13% PHP 86.48% JavaScript 5.81% Shell 0.40% HTML 6.18%
wordpress-plugin redis predis phpredis php cache wordpress relay

redis-cache's People

Contributors

a5hleyrich avatar alexva24 avatar aytackokus avatar carlalexander avatar davefx avatar desaiuditd avatar ethitter avatar fleandro-obs avatar jack9603301 avatar jerclarke avatar klawrence-fs avatar lhmook avatar martinkrcho avatar matzekitt avatar naxvog avatar nickchomey avatar ocean90 avatar pnu avatar ravloony avatar rbackert avatar rfair404 avatar rkaiser0324 avatar scott-kennedy avatar szepeviktor avatar tillkruss avatar tkalimullin-coludlinux avatar todiadiyatmo avatar wilburpowery avatar yannux avatar zaherg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redis-cache's Issues

Redis Not Installed

Posted the same on Wordpress - not sure which one you prefer

I use roots.io/bedrock and am trying to get object caching to work. I have redis installed and the following works fine:

<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server sucessfully";
   //check whether server is running or not
   echo "Server is running: "+ $redis->ping();
?>

I can see the ping through redis-cli monitor

Unfortunately, using your plugin, it shows that Redis is not installed (using the same 127.0.0.1/6379).

I also get the following:
Notice: Undefined property: WP_Object_Cache::$redis_client in /srv/http/site/web/wp/wp-includes/cache.php on line 327

WP_CACHE_KEY_SALTis not unique if undefined in wp-config

In file:
redis-cache/includes/object-cache.php

    /**
     * This approach is borrowed from Sivel and Boren. Use the salt for easy cache invalidation and for
     * multi single WP installs on the same server.
     */
    if ( ! defined( 'WP_CACHE_KEY_SALT' ) ) {
        define( 'WP_CACHE_KEY_SALT', '' );
    }

This doesn't work as it simply sets the WP_CACHE_KEY_SALT to null.

I have tested with multiple WP sites on the same host and the 2nd blog fails.

Does persistent connection help on anything?

I am getting around 4k AUTH requests on my Redis instance per minute. I was thinking about enabling Predis persistence in order to drop this number, but as I can see inside object-cache, there's no config option to set it before the connection happens.

First of all, will a persistent connection work with the way the plugin works today?
Will this help on anything or is it just a non effective approach?

Thanks for this awesome plugin,
Vinicius

Enabling object cache breaks wp-admin

Thanks for your work on this. I've had it working but when I recently disabled & re-enabled the cache, I'm left with the following:

screen shot 2015-05-01 at 09 27 36

URI: /wp-admin/upgrade.php?_wp_http_referer=%2Fwp%2Fwp-admin%2Ftools.php%3Fpage%3Dredis-cache%26message%3Dcache-enabled

Wherever I navigate in the admin, I'm redirected to the above. This doesn't affect the front-end of the site which continues to work as normal.

WordPress: 4.2.1
Redis Object Cache: 1.1.1

The cause could be another plugin but it's worth opening an issue here because this might be a common problem.

respect key salt when purging?

i don't know about anyone else, but i was kind of assuming that having defined a specific salt for a given WP site that when i used the "flush cache" button in the redis settings for that WP site that i would only be flushing cache entries that matched that key salt.

for a server that has more than one WP site, and if you are also using redis for page caching like i am, hitting that flush cache button can have a pretty big unintended effect. i built my own command line flush using redis-cli that lets me be a little more precise about what i am flushing, but i still think it would be cool to have the flush cache button respect the key salt if possible.

having done some poking around, i see why it is the way it is. telling redis to flushdb is fast, easy, atomic and easy to implement with any back end to redis. there are various hacks around for doing wildcard purging on redis. my command line purger uses one of them based on redis SCAN which works fine for my purposes but it is not guaranteed atomic.

what seems like the best approach if you want an atomic wildcard delete is using a small lua script against the redis db (something like http://blog.code4hire.com/2016/09/Deleting-keys-with-wildcards-in-Redis/).

is this something you'd be interested in incorporating into the plugin? if so, when i get some time i'd be willing to try adding it to the existing flush method in object-cache.php and sending a PR if i get it working. if not, i'm ok with my command-line tools.

Issue with Redis-Cache & Cache Invalidation / Update

Hi,

Currently we're running redis-cache in production. It appears there is sometimes an edge-case once our redis store has many keys ( 7mill+ ) where once a key is set, eg user_meta the key even when updated via update_user_meta, it is never updated in the redis-cache. This is no bueno as even when the user_meta is changed in DB... the redis-cache continues serving stale values.

It's only when we forcefully DELETE the key where everything works fine. However this only happens when the redis DB has been operational for a while, and we slam it with requests to get & update_user_meta.

It seems there is some logic when updating user_meta where, if the value isn't updated in the database ( values are the same ), the redis cache is not invalidated, or updated.

“Not Allowed to Access this Page” Error in WordPress

Today when clicked to enable redis object cache inside plugin dashboard, I received following error:
“Not Allowed to Access this Page”.

I had to delete object-cache.php fom WordPress folder to resolve issue.

Now plugin is not working on my site, though.

Anyone know how to fix this and make plugin work again?

Database 0 is used instead of WP_REDIS_DATABASE

Hey,

i used define(WP_REDIS_DATABASE, 4) to select database 4 but instead db0 is used.

redis-cli -> info prints out following

db0:keys=579,expires=19,avg_ttl=96766820
db4:keys=1,expires=19,avg_ttl=32306

The admin page shows me correctly that database 4 is used.

Shared environment security

Redis is designed to only be accessed by trusted users. Some other WP Redis plugins have a NONCE_SALT variable that I assume is used for this issue.

I'd like to deploy a shared instance where multiple users will be sharing a single Redis instance. The issue is that any user can overwrite any other user's data. A malicious user could easily replace another user's cached content and for example, deface another website or cause all sorts of other issues.

Not that I'm directly asking for a solution for this plugin, but does anything at all come to mind to somehow secure Redis or provide NONCE functionality in the plugin?

Redis master-slave replication

Support for Redis master-slave replication. To implement it this plugin needs to additionally direct reads and writes to different redis servers.

Batcache compatibility

This plugin has a great opportunity to be compatible with Batcache page cache which is built for memcached but would happily use Redis to speed up webpages. The only problem is that Batcache checks for support for the 'inc' method in the WP_Object_Cache but this plugin replaces the class but instead of inc names the method increment.

Is this done to avoid any known issues and if not would you consider a patch to rename the method?

Please add filters/actions to get/set/delete calls so we can set up logging/fix bugs in core

Hi and thanks for the plugin!

Context
After having redis-object-cache on for a few weeks we got a steady stream of instances where sites would white-screen-of-death on both the theme and admin. The only thing that fixed it was flushing the object cache, and I tracked it down to a bug in core WP related to how it stores and updates alloptions. There is a race condition where two processes updating an autoloaded option step on each other's edits because they don't refresh their internal copy of alloptions before inserting the single value they needed to change.
https://core.trac.wordpress.org/ticket/31245

In our case these collisions caused the WSOD, but to figure that out we had to add logging of SET/DELETE commands to track when/how the problem was triggered. To solve the problem we had to look through the logs and find the code that was re-saving options too often, as well as adding a hack that resets alloptions whenever it's saved (i'll make another ticket about that).

Either way we had to change our copy of object-cache.php to get it done, and we're hoping you can incorporate some similar changes into the official version since they are harmless and simple.

What we need

The essence of what we want is just an action and a filter in each of the main Redis command methods (GET, SET, DELETE and any others you consider appropriate, those where the ones we needed).

Action example: At the end of WP_Object_Cache->set()

    do_action('redis_object_cache_set', $key, $value, $group, $expiration);

Filter+action example: At the end of WP_Object_Cache->get()

    $value = is_object( $value ) ? clone $value : $value;
    do_action('redis_object_cache_set', $key, $value, $group);
    return apply_filters('redis_object_cache_get', $value, $key, $group);

IMHO it's worth adding both a filter and action to GET and SET though in our case we only really need the filter on GET, so if you want to limit the number of filters for some reason then we'd be satisfied if the other methods only got actions.

There's no real penalty to having filters/actions until they are used, so adding these shouldn't affect the performance of anyone unless they start writing code to interact with them. To me this kind of action/filter usage is a best-practice and great future-proofing. They will let us fix our own problems easily and give you time to integrate fixes when convenient without us having to constantly fork the object-cache.php file.

Thanks again for the plugin and for considering this request! Looking forward to the next version :)

Auto activate?

Is there a way to auto-activate the cache?
I'm adding this to a Docker deployment and I'd like a way to activate the cache automatically.

Consider: Add fix for WP Core's alloptions race condition bug into redis-object-cache

There is a terrible bug in WP Core that specifically affects persistent object caches like this one:

https://core.trac.wordpress.org/ticket/31245

(The thread is mostly about the idea of replacing the whole alloptions system with a one-at-a-time approach when a persistent object cache is installed. IMHO this is a bad plan and predictably nothing has happened because of concerns over back-compat with all the existing object-cache.php implementations. If you get to the bottom you'll see my proposals which explain our much more straightforward and probably performant solution).

It's been known for 10 months but IMHO goes back much farther and accounts for white-screen-of-death bugs on our site even back when we used the APC Object Cache. The bug isn't specific to Redis in any way, but in our testing we were able to fix it at the object caching layer by using a simple action hook we added to WP_Object_Cache->set(), so if you want, you can fix this for other users of your plugin by integrating the same fix (at least until Core fixes it, maybe in 4.5 but I won't hold my breath).

To summarize the situation:

  • As most devs know, WP fetches all options with autoload=1 in a single query at the beginning of the pageload to avoid hundreds of fast but separate MySQL queries.
  • When a persistent object cache is installed there is no way to have "autoload=1" as part of the query, so they instead store the entire set of autoloaded options in a cache with name=alloptions group=options
  • When a pageload updates an autoload=1 option it updates the object cache for that option, but also has to update alloptions since it isn't reloaded automatically.

And now the bug:

  • When a pageload updates alloptions it does so using the original value it started with when first fetching alloptions from the object cache, inserting the changed value and resaving alloptions.
  • When two concurrent pageloads change separate options their changes will overwrite each other. The change from the first to save will be overwritten by the other.
  • The result is options WP expects to find in alloptions are totally missing, and in many cases it can't handle it at all, resulting in WSOD in our case.
  • The whole wp-cron system exacerbates the problem dramatically on sites that are rarely visited, since cold caches co-incide with the need for a cron refresh and create the perfect storm for the bug to thrive in.

As I said above, the main solution they were considering in the ticket was to remove alloptions entirely and rely on either the speed of the object cache to make it okay to fetch each option separately, or a get_multi() functionality that would pull in all autoloaded options with one query. This is complicated and likely to remain quagmired in compatibility concerns.

My solution is way more simple: _Just reload the alloptions cache (triggering a single MySQL query for autoload=1 options) whenever one of it's autoloaded options is updated._

The result is that alloptions gets dropped a lot, but it reloads quickly and on the vast majority of pageloads where no options are changed there is no affect on performance at all.

Solving this in core would involve replacing the system that manages updates to alloptions (pretty simple) but solving it at the object-cache.php level is even simpler: Delete the alloptions cache whenever it's updated. It sounds counter-intuitive, but the effect is basically the same as if core just didn't update the value at all: alloptions is reloaded from the db, including updates done by any processes, the next time it's required.

Here's the code we're using to fix this bug on our sites.

/**
 * Redis object cache: Delete the alloptions cache whenever it is updated (SET) in the
 * object cache.
 * 
 * Fixes bug in core that creates race condition when multiple processes update options in the alloptions cache.
 * By deleting the cache for all options we can be confident that any mistakes (inserting the new value in an out-of-date
 * version of the alloptions array) won't carry forward into other processes and cause WSOD.
 * 
 * Shouldn't be necessary if that bug is ever fixed. 
 * 
 * Relies on 'redis_object_cache_set' action in redis' object-cache.php (WP_Object_Cache->set()) which we added manually for now (2015-12-09)
 * 
 * @see https://core.trac.wordpress.org/ticket/31245
 */
function gv_redis_object_cache_delete_alloptions($key, $value, $group, $expiration) {
    if ('alloptions' == $key && 'options' == $group)
        wp_cache_delete('alloptions', 'options');
}
add_action('redis_object_cache_set', 'gv_redis_object_cache_delete_alloptions', 10, 4);

As it states in the PHPDoc, we're relying on an action we added to WP_Object_Cache->set() in object-cache.php for this to work, so anyone trying to use this will need to copy the action into their version of the file until/unless the plugin is updated with our proposed actions+filters from ticket #18

If you wanted, you could add the same fix directly into WP_Object_Cache->set() without having the filter, up to you. IMHO it would be better to keep it as a filter since ideally it can be removed entirely once the core bug is fixed.

If you don't consider this something that your plugin needs to resolve I understand completely. I wanted to lay out the parameters here either way in case someone else using the plugin has the same problems as us and wants to use our fix. Also I'm hoping it empasizes the value of having the actions+filters proposed in #18 added into your plugin so we don't need to keep patching it in the future to maintain our fix.

Thanks!

Make Redis Object Cache Full compatible with the Batcache Plugin

Hi,

Batcache is a full page cache plugin using an object cache plugin. It could cache pages in the memory.

I install the Redis Object Cache and Batcache. However, I could not get the cached page even I refresh the page for many times. Batcache just recreate a new page cache when I refresh the page. It did not send the old cached page.

Is there any compatible issues between Redis Object Cache and the Batcache Plugin? Thanks.

Batcache: https://wordpress.org/plugins/batcache/

Master/Slave with phpredis

Hey Till,

I saw you integrated Master/Slave with predis already, but predis is way too slow/ressource intensive for a live environment.
Could you integrate the master/slave with phpredis too?

"flush cache" flush all cache on shared redis

I try setup two wordpress instances and setup unique WP_CACHE_KEY_SALT for each one. When I click "flush cache", plugins flush cache of two instances instead of flushing cache only on that wordpress instance

PHP TypeError when using Sentinel

Hi!

I'm trying to use redis-cache in conjunction with sentinel. I've configured it as mentioned in README.MD except i'm just using one sentinel server for development purposes:

define( 'WP_REDIS_CLIENT', 'predis' );
define( 'WP_REDIS_SENTINEL', 'mymaster' );
define( 'WP_REDIS_SERVERS', [
    'tcp://127.0.0.1:26379'
] );

When running a WP-CLI command such as wp redis status i get the following:

Fatal error: Uncaught TypeError: Argument 3 passed to Predis\Connection\Aggregate\SentinelReplication::__construct() must be an instance of Predis\Connection\Aggregate\ConnectionFactoryInterface, instance of Predis\Connection\Factory given, called in /www/wp-content/plugins/redis-cache/includes/predis.php on line 9744 and defined in /www/wp-content/plugins/redis-cache/includes/predis.php:12183

According to the commit logs, this plugin uses v1.1.1 of predis. Looking at line 10685 of includes/predis.php here, this version of predis.php however differs from the v1.1.1 release here

If I change line 10685 in includes/predis.php to read
use Predis\Connection\FactoryInterface as ConnectionFactoryInterface;

instead of

use Predis\Connection\FactoryInterface;

Then the plugin works without problems. PHP Version is 7.1.14 with WordPress 4.8.2

PHP Fatal error: Uncaught Error: Call to undefined method WP_Object_Cache::redis_status()

I'm getting a PHP Fatal Error with 1.3.8. I'm not sure what I'm missing, but I've made sure to update the object-cache.php file. From what I can tell, seems that object-cache.php isn't being included? Any thoughts?

PHP Fatal error:  Uncaught Error: Call to undefined method WP_Object_Cache::redis_status() in /opt/local/apache/appdata/wp-content/plugins/redis-cache/redis-cache.php:171
Stack trace:
#0 /opt/local/apache/appdata/wp-content/plugins/redis-cache/redis-cache.php(153): RedisObjectCache->get_redis_status()
#1 /opt/local/apache/appdata/wp-content/plugins/redis-cache/includes/admin-page.php(14): RedisObjectCache->get_status()
#2 /opt/local/apache/appdata/wp-content/plugins/redis-cache/redis-cache.php(92): require_once('/opt/local/apac...')
#3 /opt/local/apache/appdata/wp-includes/class-wp-hook.php(286): RedisObjectCache->show_admin_page('')
#4 /opt/local/apache/appdata/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#5 /opt/local/apache/appdata/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#6 /opt/local/apache/appdata/wp-admin/admin.php(224): do_action('settings_page_r...')
#7 /opt/local/apache/appdata/wp-admin/options-general.php(10): require_once('/opt/local/apac...')
#8 {main}
  thrown in /opt/local/apache/appdata/wp-content/plugins/redis-cache/redis-cache.php on line 171

Not working with advanced-cache.php

I'm using this with batcache and getting this error:
Fatal error: Call to undefined function maybe_unserialize()

Adding this to object-cache.php did the trick:

if (!function_exists('maybe_unserialize')) {
    require_once(ABSPATH . 'wp-includes/functions.php' );
}

Support redis-sentinel configuration

Currently this plugin does not support red-sentinel configuration. Although since it does support Predis this is very straight forward.

The issue is in the configuration approach:

    // ...
                if ( defined( 'WP_REDIS_SERVERS' ) ) {
                    $parameters = WP_REDIS_SERVERS;
                    $options[ 'replication' ] = true;
                }
                if ( ( defined( 'WP_REDIS_SERVERS' ) || defined( 'WP_REDIS_CLUSTER' ) ) && defined( 'WP_REDIS_PASSWORD' ) ) {
                    $options[ 'parameters' ][ 'password' ] = WP_REDIS_PASSWORD;
                }
                $this->redis = new Predis\Client( $parameters, $options );
                $this->redis->connect();

The replication option needs to be set to 'sentinel' not true. So would it not be better to have the value of WP_REDIS_SERVERS passed directly into the $options[ 'replication' ] variable?

Also a new config param service would need to be added... perhaps we could have a new constant called WP_REDIS_SENTINEL=true and then WP_REDIS_CLUSTER could be set as an array of sentinels.

I would happily write a PR to do this.

1.2.1 fatal error with HHVM 3.11.0

Hallo Till,

I get the following error with WordPress when using HipHop VM 3.11.0 (rel), all works fine with PHP 5.6. The object-cache.php file is equal to redis-cache/includes/object-cache.php. It does not matter if the plugin is active or not.

WordPress: 4.4
Redis-Cache: 1.2.1

Fatal error: Uncaught TypeError: Argument 2 passed to stream_set_blocking() must be an instance of int, bool given in /srv/www/40/wordpress/object-cache.php:377\nStack trace:\n#0 /srv/www/40/wordpress/object-cache.php(377): Redis->connect()\n#1 /srv/www/40/wordpress/object-cache.php(158): WP_Object_Cache->__construct()\n#2 /srv/www/40/wordpress/wp-includes/load.php(473): wp_cache_init()\n#3 /srv/www/40/wordpress/wp-settings.php(95): wp_start_object_cache()\n#4 /srv/www/40/wordpress/wp-config.php(124): include()\n#5 /srv/www/40/wordpress/wp-load.php(37): include()\n#6 /srv/www/quadzero/40/wp-blog-header.php(12): include()\n#7 /srv/www/quadzero/40/index.php(17): include()\n#8 {main}

Warning: strcasecmp() expects parameter 2 to be string, null given in /srv/www/40/wordpress/object-cache.php on line 358

Wrong version/label reported

Unless I'm missing something, the version number reported in diagnostics is the version of PhpRedis, not the version of Redis itself.

For instance, PhpRedis is on version 3.1.1 while Redis itself is on version 3.2.8.

For the short-term I think it might be a good idea to re-label that key just to avoid confusing sysadmins (like me). In the long term it might be better to query $redis->info( 'server' ) and grab the redis_version key from that array.

If this is correct I can send a PR for one or the other above although I'm not sure how to show the server version if there are multiple servers defined.

Version 1.3.6 breaks wp sites on some servers

The latest version of the plugin causes a fatal error on some servers, disabling the whole site
Fatal error: require(): Failed opening required 'phar://predis.phar/Autoloader.php' (include_path='.:/opt/sp/php7.1/lib/php') in /srv/.../public/wp-content/plugins/redis-cache/includes/predis.php on line 7

This makes the frontend and wp-admin unusable, the only solution was to reverse the plugin version.

PHP version was switched between 7.0, 7.1 and 7.2, each with same result

Can you help with this?

Cheers

Composer Installation Path Differs from WordPress Repository Path

As the title says, when installing the plugin from github via composer (as I did to get the fix for #36) the same include path does not work because it checks for WP_PLUGIN_DIR . '/redis-cache/includes/predis.php. With composer (from github) the plugin resides in /redis-object-cache/.
I am aware of a workaround (targeting this package explicitly in installer-paths), what do you think would be a viable solution to this? Changing the composer package name?

Repo management feedback

I've been watching this project for some time now and just about every issue that has been reported or PR submitted as resulted in "I'll see if more people report this". No offense but you need to keep in mind that a vast majority of WP users haven't the slightest idea of GIT or Github and it's rather uninspiring to watch developers have their contributions snuffed - there has been some nice solutions to some issues that apply regardless of how many users "report it".

For example, I work for a company who has some pretty popular plugins who would benefit from such a Redis caching module however it's difficult to suggest this solution when I know I'll have to explain to either define a manual key salt or patch the code - for an issue I submitted a valid PR for: #5 .

With that said and with the highest respect as a fellow dev, would it be an issue to fork this project and maintain it a different way? I know it's a permissive license however, I'm from the game dev world where devs whine constantly over someone using their work (regardless of what license) so I thought I'd ask first.

Thanks!

Remove `comments` from the ignored groups for WP 4.6

Since 4.6 comments can be cached by a persisten storage, would be nice to reflect this here. However I was not sure how this should be handled. I think there are 2 options.

  1. Add a note to the docs saying that when you are on 4.6 you should define WP_REDIS_IGNORED_GROUPS with ['counts']
  2. Add a WP version compare check to the WP_Object_Cache constructor and remove comments if WP_REDIS_IGNORED_GROUPS is not set.

Happy to make a PR but wanted to check in first to see which route would be considered best in this plugin.

Reference: https://make.wordpress.org/core/2016/07/18/comments-in-4-6-can-now-be-cached-by-a-persistent-object-cache/

Add Diagnostics

  • Is Redis installed.
  • HHVM or PHP Version.
  • What are the config values?

Caching WP JSON API?

Apologies if this is not an issue -- my Google fu is failing me here. I'm using WP as a headless CMS and would ideally love to cache the calls from /wp-json/v2 out of the box. It doesn't look like that's happening though -- is it supposed to? If not, is there a way to do it? Is that something in the scope of redis-cache or should this ticket be closed outright in favor of some other solution?

Sentinel configuration doesn't work

I followed the directions in the readme and entered the following in my wp-config.php:

define( 'WP_REDIS_CLIENT', 'predis' );
define( 'WP_REDIS_SENTINEL', 'mysentinelname' );
define( 'WP_REDIS_SERVERS', [
  'tcp://10.10.11.11:7010',
  'tcp://10.10.11.12:7010',
] );
define( 'WP_CACHE_KEY_SALT', 'mysalt_' );
define( 'WP_REDIS_SELECTIVE_FLUSH', true );

Of course Redis Sentinel instances are running on the above address. I've confirmed I can connect to the addresses via redis-cli.

In Redis Object Cache settings, however, I see this:

PHP Version: 7.1.9-1+0~20170902060745.8+stretch~1.gbpebe5d6
Multisite: Yes
Redis: 3.1.2
Predis: 1.1.1
Status: Not Connected
Client: Predis (v1.1.1)
WP_REDIS_CLIENT: "predis"
WP_REDIS_SERVERS: ["tcp:\/\/10.10.11.11:7010","tcp:\/\/10.10.11.12:7010"]
WP_REDIS_MAXTTL: "2678400"
WP_CACHE_KEY_SALT: "mysalt_"
Drop-in: Valid
Global Prefix: ""
Blog Prefix: 1
Global Groups: ["blog-details","blog-id-cache","blog-lookup","global-posts","networks","rss","sites","site-details","site-lookup","site-options","site-transient","users","useremail","userlogins","usermeta","user_meta","userslugs"]
Ignored Groups: ["counts","plugins","blog-details","blog-id-cache","blog-lookup","global-posts","networks","rss","sites","site-details","site-lookup","site-options","site-transient","users","useremail","userlogins","usermeta","user_meta","userslugs","themes"]

It seems Redis Object Cache is interpreting the Redis Sentinels as regular Redis servers. Am I doing something wrong?

Enabling object cache breaks wordpress.

Update redis plugin Version 1.3.7 .
Activate.
Site unavailable.

[Thu Mar 22 15:45:00.200457 2018] [php7:error] [pid 13828] [client 192.168.0.100:52850] PHP Fatal error: Uncaught Error: Class 'Predis\\Configuration\\ConnectionFactoryOption' not found in /home/user/Projects/wordpress.site.com/wp-content/plugins/redis-cache/includes/predis.php:9610\nStack trace:\n#0 /home/user/Projects/wordpress.site.com/wp-content/plugins/redis-cache/includes/predis.php(9665): Predis\\Configuration\\Options->getDefault('connections')\n#1 /home/user/Projects/wordpress.site.com/wp-content/plugins/redis-cache/includes/predis.php(8863): Predis\\Configuration\\Options->__get('connections')\n#2 /home/user/Projects/wordpress.site.com/wp-content/plugins/redis-cache/includes/predis.php(8804): Predis\\Client->createConnection(Array)\n#3 /home/user/Projects/wordpress.site.com/wp-content/object-cache.php(488): Predis\\Client->__construct(Array, Array)\n#4 /home/user/Projects/wordpress.site.com/wp-content/object-cache.php(183): WP_Object_Cache->__construct()\n#5 /home/user/Projects/wordpress.site.com/wp-includes/load.php(516): wp_cache_init()\n#6 /home/user in /home/user/Projects/wordpress.site.com/wp-content/plugins/redis-cache/includes/predis.php on line 9610

igbinary support

More of a question or feature request, but have you done any work or testing using igbinary as the serializer?

My understanding is that its usage is pretty easy. Just replace the calls to serialize and unserialize with igbinary_serialize and igbinary_unserialize, provided that you compiled PHP with the igbinary extension.

Seems it could save a lot of memory for object cache values, and reduce over-the-wire traffic when communicating with an external redis cache when using multiple web nodes.

Ability to disable caching from config file constant?

During development, I'd like to have caching turned off. Is there a way I can set a config constant like WP_DISABLE_REDIS_CACHE that would turn off the object caching? If this isn't available, I'll suggest doing something like the following (which could replace the current object-cache.php drop-in file and still make everything function the same when not disabled):

wp-content/object-cache.php

<?php
/*
Plugin Name: Redis Object Cache
Plugin URI: http://wordpress.org/plugins/redis-cache/
Description: A persistent object cache backend powered by Redis. Supports HHVM's Redis extension, the PCEL Redis Extension and the Predis library for PHP.
Version: 1.2.2
Author: Till Krüss
Author URI: http://till.kruss.me/
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Based on Eric Mann's and Erick Hitter's Redis Object Cache:
https://github.com/ericmann/Redis-Object-Cache
*/

// Don't use cache if disabled from the config file, instead, use the WP default
if(WP_DISABLE_REDIS_CACHE === true) return require_once realpath(__DIR__.'/../wp-includes/cache.php');

// Use redis-cache plugin if not disabled.
return require_once(realpath(__DIR__.'/plugins/redis-cache/includes/object-cache.php'));

It basically just tells it to use the WP default if the WP_DISABLE_REDIS_CACHE constant is set to true in the config, otherwise, it loads up the plugin normally.

Page Cache

If anyone is interested in helping me test a Batcache fork to enable page caching, leave a comment below.

wp_cache_flush clears entire Redis and not just current site?

Hi there, thanks so much for this plugin! It's got all the features we need so really appreciated.

Looking at $wp_object_cache->flush it seems like any time wp_cache_flush() is called, the entire Redis library gets cleared. Is that right, or is it only keys related to the current site that would get flushed?

We're running Redis and your plugin on a huge server with dozens of sites, each identified by the WP_CACHE_KEY_SALT constant (using their db names). It seems to me that if wp_cache_flush() is run on one of those sites it should only clear the keys for that site.

Thanks for any clarification! We're trying to make sure it's working properly and seeing a regular emptying of Redis so I want to discount this fear as a possibility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.