Wp redis object cache

From Lonsdale201/wp-agent-skills · View interactive version

Wp redis object cache is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Configure, audit, troubleshoot, and extend the Redis Object Cache plugin (`redis-cache`) for WordPress persistent object caching. Covers the `wp-content/object-cache.php` drop-in, `wp redis status|enable|disable|update-dropin`, `WP_REDIS_*` constants, Predis/PhpRedis/Relay client selection, cache gr

How to use this skill

Skill file

Redis Object Cache

Redis Object Cache is a WordPress persistent object-cache drop-in manager. The plugin being active is not enough: persistent caching only runs when a valid wp-content/object-cache.php drop-in exists, WP_REDIS_DISABLED is not true, and WordPress can connect to Redis.

This skill is about WordPress/plugin integration with the OSS redis-cache plugin. It is not a Redis server installation or Linux service hardening guide.

When to use this skill

Trigger when ANY of the following is true:

Non-destructive checks first

Run these before changing anything:

wp redis status
wp help redis
wp eval 'echo defined( "WP_REDIS_VERSION" ) ? WP_REDIS_VERSION : "not-loaded";'
wp eval 'var_export( file_exists( WP_CONTENT_DIR . "/object-cache.php" ) );'

Do not run wp redis enable, wp redis disable, wp redis update-dropin, wp cache flush, or admin "Flush Cache" actions as a casual check. Those commands touch the drop-in or flush Redis data.

Mental model

| Layer | What it means | Source behavior |

|---|---|---|

| Plugin active | Admin UI, CLI command, diagnostics, helpers are loaded | redis-cache.php registers the plugin and wp redis command |

| Drop-in installed | wp-content/object-cache.php exists | copied from includes/object-cache.php |

| Drop-in valid | Drop-in header matches this plugin URI | checked by Plugin::validate_object_cache_dropin() |

| Drop-in current | Drop-in version matches plugin version | checked by Plugin::object_cache_dropin_outdated() |

| Redis connected | $wp_object_cache->redis_status() returns true | reported as Connected; otherwise Not connected |

wp redis status can say Not enabled even when the plugin is active. That usually means the drop-in is missing. If the drop-in exists but Redis is down, the status moves toward Not connected.

Status meanings

| Status | Read it as | Fix path |

|---|---|---|

| Disabled | WP_REDIS_DISABLED is true | remove/flip the constant if Redis should run |

| Not enabled | no valid drop-in | check Redis connectivity, then enable intentionally |

| Drop-in is invalid | another object-cache drop-in owns the file | audit before overwriting; update-dropin replaces it |

| Drop-in is outdated | plugin updated but drop-in stayed old | update the drop-in after review |

| Not connected | drop-in exists but Redis connection failed | check host, port, socket, auth, TLS, server state |

| Connected | persistent object cache is active | proceed with normal cache/API work |

Configuration constants

Define constants in wp-config.php, above the WordPress bootstrap line.

Basic connection:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
define( 'WP_REDIS_RETRY_INTERVAL', null );

Authentication:

define( 'WP_REDIS_PASSWORD', 'secret' );
define( 'WP_REDIS_USERNAME', 'default' ); // Redis ACL user, when used.

Socket/TLS:

define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );

define( 'WP_REDIS_SCHEME', 'tls' );
define( 'WP_REDIS_SSL_CONTEXT', array(
    'verify_peer' => true,
) );

Prefixing and safe flushes:

define( 'WP_REDIS_PREFIX', 'example.com:' );
define( 'WP_REDIS_SELECTIVE_FLUSH', true );

If WP_REDIS_PREFIX is not defined, the drop-in maps WP_CACHE_KEY_SALT to WP_REDIS_PREFIX. On shared Redis, set a unique prefix or salt before enabling Redis. Without WP_REDIS_SELECTIVE_FLUSH, a full object-cache flush uses flushdb() for the selected database.

Performance and behavior:

define( 'WP_REDIS_CLIENT', 'phpredis' ); // predis, phpredis, relay, credis.
define( 'WP_REDIS_IGBINARY', true );     // only if the igbinary extension is loaded.
define( 'WP_REDIS_MAXTTL', DAY_IN_SECONDS );
define( 'WP_REDIS_FLUSH_TIMEOUT', 5 );
define( 'WP_REDIS_GRACEFUL', true );
define( 'WP_REDIS_DISABLE_METRICS', true );

Groups:

define( 'WP_REDIS_IGNORED_GROUPS', array( 'my-runtime-only' ) );
define( 'WP_REDIS_UNFLUSHABLE_GROUPS', array( 'my-critical-group' ) );
define( 'WP_REDIS_DISABLE_GROUP_FLUSH', false );

WP_REDIS_GLOBAL_GROUPS replaces the plugin's default global groups, it does not merge with them. Prefer wp_cache_add_global_groups() in plugin code unless the whole install is deliberately redefining the global group list.

Advanced topology:

define( 'WP_REDIS_SERVERS', array( 'tcp://127.0.0.1:6379' ) );
define( 'WP_REDIS_SENTINEL', 'mymaster' );
define( 'WP_REDIS_CLUSTER', array( 'tcp://10.0.0.1:6379', 'tcp://10.0.0.2:6379' ) );
define( 'WP_REDIS_SHARDS', array( 'tcp://10.0.0.1:6379', 'tcp://10.0.0.2:6379' ) );

Do not use WP_REDIS_SERIALIZER; version 2.7.0 removed it. Use WP_REDIS_IGBINARY when igbinary is installed and desired.

Client selection

The drop-in chooses a client in this order:

Do not assume all topology modes work with every client. Relay in this plugin does not support sharding or cluster mode. Predis handles the broadest pure-PHP topology set because the plugin bundles Predis.

WP-CLI behavior

wp redis status is read-only and prints diagnostics from includes/diagnostics.php.

wp redis enable:

wp redis disable:

wp redis update-dropin:

Treat update-dropin as a deliberate operation. It can replace another plugin's object-cache drop-in.

Correct plugin cache usage

Use WordPress cache APIs. Do not instantiate Redis directly from normal plugin code.

$key   = 'report:' . md5( wp_json_encode( $args ) );
$group = 'myplugin_reports';

$value = wp_cache_get( $key, $group, false, $found );
if ( ! $found ) {
    $value = myplugin_build_report( $args );
    wp_cache_set( $key, $value, $group, HOUR_IN_SECONDS );
}

return $value;

Always use the $found parameter because a cached value may legitimately be false, 0, '', or an empty array.

Use groups intentionally:

add_action( 'init', static function (): void {
    wp_cache_add_non_persistent_groups( array( 'myplugin_request_only' ) );
    wp_cache_add_global_groups( array( 'myplugin_network_config' ) );
} );

Flush a group only after checking support:

if ( wp_cache_supports( 'flush_group' ) ) {
    wp_cache_flush_group( 'myplugin_reports' );
}

This drop-in reports support for add_multiple, set_multiple, get_multiple, delete_multiple, flush_runtime, and flush_group.

Hooks and filters

Lifecycle:

Runtime/cache events:

Behavior filters:

Metrics and diagnostics

Metrics are enabled unless WP_REDIS_DISABLE_METRICS is true, but they record only when Redis is connected and the drop-in exposes info() and redis_instance(). WP_REDIS_METRICS_MAX_TIME controls retention; default is one hour.

Diagnostics intentionally masks WP_REDIS_PASSWORD and password query parameters in WP_REDIS_SERVERS, but still avoid pasting full diagnostics into public tickets without checking for hostnames, usernames, paths, and topology.

Critical rules

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.