Skip to content

Commit

Permalink
Merge pull request #344 from tillkruss/patch-3
Browse files Browse the repository at this point in the history
Support Relay via `WP_REDIS_USE_RELAY`
  • Loading branch information
Daniel Bachhuber authored Feb 18, 2022
2 parents 44d3903 + ddee391 commit 61ea059
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ This assumes you have a PHP environment with the [required PhpRedis extension](h
4. Engage thrusters: you are now backing WP's Object Cache with Redis.
5. (Optional) To use the `wp redis` WP-CLI commands, activate the WP Redis plugin. No activation is necessary if you're solely using the object cache drop-in.
6. (Optional) To use the same Redis server with multiple, discreet WordPress installs, you can use the `WP_CACHE_KEY_SALT` constant to define a unique salt for each install.
7. (Optional) To use true cache groups, with the ability to delete all keys for a given group, register groups with `wp_cache_add_redis_hash_groups()`, or define the `WP_REDIS_USE_CACHE_GROUPS` constant to true to enable with all groups. However, when enabled, the expiration value is not respected because expiration on group keys isn't a feature supported by Redis.
7. (Optional) To use true cache groups, with the ability to delete all keys for a given group, register groups with `wp_cache_add_redis_hash_groups()`, or define the `WP_REDIS_USE_CACHE_GROUPS` constant to `true` to enable with all groups. However, when enabled, the expiration value is not respected because expiration on group keys isn't a feature [supported by Redis](https://github.com/redis/redis/issues/6620).
8. (Optional) On an existing site previously using WordPress' transient cache, use WP-CLI to delete all (`%_transient_%`) transients from the options table: `wp transient delete-all`. WP Redis assumes responsibility for the transient cache.
9. (Optional) To use [Relay](https://relaycache.com) instead of PhpRedis as the client define the `WP_REDIS_USE_RELAY` constant to `true`.

## WP-CLI Commands ##

Expand Down
6 changes: 5 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,11 @@ public function build_client_parameters( $redis_server ) {
* @return Redis Redis client.
*/
public function prepare_client_connection( $client_parameters ) {
$redis = new Redis;
if ( defined( 'WP_REDIS_USE_RELAY' ) && WP_REDIS_USE_RELAY ) {
$redis = new Relay\Relay;
} else {
$redis = new Redis;
}

$redis->connect(
$client_parameters['host'],
Expand Down

0 comments on commit 61ea059

Please sign in to comment.