Skip to content

Commit 48b6406

Browse files
committed
wip
1 parent e0b80a4 commit 48b6406

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Renamed `.redis-write-test.tmp` test file to `object-cache.tmp`
1010
- Call `redis_object_cache_error` action before `wp_die()`
1111
- Allow `WP_REDIS_PLUGIN_PATH` to be defined elsewhere
12+
- Added experimental flush timeout (defaults to `5` seconds)
1213

1314
## 2.4.4
1415

FAQ.md

+8
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ This can happen when Redis Server runs out of memory and no `maxmemory-policy` w
138138
Alternatively, you can set the `WP_REDIS_MAXTTL` constant to something relatively low (like `3600` seconds) and flush the cache.
139139
</details>
140140

141+
<details>
142+
<summary><code>Flushing the cache causes timeout</code></summary>
143+
144+
This can happen when the dataset in Redis Server is quite large. Consider increasing `WP_REDIS_READ_TIMEOUT` and `WP_REDIS_FLUSH_TIMEOUT` to 5-10 seconds.
145+
146+
Alternatively, starting with Redis 6.2, setting the `lazyfree-lazy-user-flush` in the `redis.conf` configuration directive to `yes` changes the default flush mode to be asynchronous.
147+
</details>
148+
141149
<details>
142150
<summary>Unable to flush the cache</summary>
143151

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ The Redis Object Cache plugin comes with vast set of configuration options. If y
3636
| `WP_REDIS_PATH` | | The path to the unix socket of the Redis server |
3737
| `WP_REDIS_SCHEME` | `tcp` | The scheme used to connect: `tcp` or `unix` |
3838
| `WP_REDIS_DATABASE` | `0` | The database used by the cache: `0-15` |
39-
| `WP_REDIS_PREFIX` | | The prefix used for all cache keys to avoid data collisions, replaces `WP_CACHE_KEY_SALT`. Should be human readable, not a "salt". |
40-
| `WP_REDIS_PASSWORD` | | The password of the Redis server. Supports Redis ACLs arrays: `['user', 'password']` |
39+
| `WP_REDIS_PREFIX` | | The prefix used for all cache keys to avoid data collisions (replaces `WP_CACHE_KEY_SALT`), should be human readable and not a "salt" |
40+
| `WP_REDIS_PASSWORD` | | The password of the Redis server, supports Redis ACLs arrays: `['user', 'password']` |
4141
| `WP_REDIS_MAXTTL` | `0` | The maximum time-to-live of cache keys |
42-
| `WP_REDIS_CLIENT` | | The client used to communicate with Redis. Defaults to `phpredis` when installed, otherwise `predis`. Supports `phpredis`, `predis`, `relay` |
42+
| `WP_REDIS_CLIENT` | | The client used to communicate with Redis (defaults to `phpredis` when installed, otherwise `predis`), supports `phpredis`, `predis`, `relay` |
4343
| `WP_REDIS_TIMEOUT` | `1` | The connection timeout in seconds |
4444
| `WP_REDIS_READ_TIMEOUT` | `1` | The timeout in seconds when reading/writing |
45-
| `WP_REDIS_FLUSH_TIMEOUT` | `5` | The timeout in seconds when flushing |
4645
| `WP_REDIS_IGNORED_GROUPS` | `[]` | Groups that should not be cached between requests in Redis |
4746

4847
<details>
@@ -51,7 +50,8 @@ The Redis Object Cache plugin comes with vast set of configuration options. If y
5150
| Configuration constant | Default | Description |
5251
| ------------------------------------ | ----------- | --------------------------------------------- |
5352
| `WP_CACHE_KEY_SALT` | | Deprecated. Replaced by `WP_REDIS_PREFIX` |
54-
| `WP_REDIS_RETRY_INTERVAL` | | The number of milliseconds between retries |
53+
| `WP_REDIS_FLUSH_TIMEOUT` | `5` | Experimental. The timeout in seconds when flushing |
54+
| `WP_REDIS_RETRY_INTERVAL` | | The number of milliseconds between retries (PhpRedis only) |
5555
| `WP_REDIS_GLOBAL_GROUPS` | `[]` | Additional groups that are considered global on multisite networks |
5656
| `WP_REDIS_METRICS_MAX_TIME` | `3600` | The maximum number of seconds metrics should be stored |
5757
| `WP_REDIS_IGBINARY` | `false` | Whether to use the igbinary PHP extension for serialization |
@@ -70,11 +70,11 @@ The Redis Object Cache plugin comes with vast set of configuration options. If y
7070

7171
Options that exist, but **should not**, **may break without notice** in future releases and **won't receive any support** whatsoever from our team:
7272

73-
| Configuration constant | Default | Description |
74-
| ----------------------------- | ----------- | ------------------------------------------------------------------- |
73+
| Configuration constant | Default | Description |
74+
| ----------------------------- | ----------- | --------------------------------------------------------------------- |
7575
| `WP_REDIS_GRACEFUL` | `false` | Prevents exceptions from being thrown, but will cause data corruption |
76-
| `WP_REDIS_SELECTIVE_FLUSH` | `false` | Uses terribly slow Lua script for flushing |
77-
| `WP_REDIS_UNFLUSHABLE_GROUPS` | `[]` | Uses terribly slow Lua script to prevent groups from being flushed |
76+
| `WP_REDIS_SELECTIVE_FLUSH` | `false` | Uses terribly slow Lua script for flushing |
77+
| `WP_REDIS_UNFLUSHABLE_GROUPS` | `[]` | Uses terribly slow Lua script to prevent groups from being flushed |
7878

7979
</details>
8080

includes/class-plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ public function on_deactivation( $plugin ) {
15221522
wp_unschedule_event( $timestamp, 'rediscache_discard_metrics' );
15231523
}
15241524

1525-
wp_cache_flush();
1525+
(new Predis)->flush();
15261526

15271527
if ( $this->validate_object_cache_dropin() && $this->initialize_filesystem( '', true ) ) {
15281528
$wp_filesystem->delete( WP_CONTENT_DIR . '/object-cache.php' );

includes/class-predis.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Predis {
2222
/**
2323
* Connect to Redis.
2424
*
25+
* @param int|null $read_timeout The read timeout in seconds.
2526
* @return void
2627
*/
2728
public function connect( $read_timeout = null ) {
@@ -130,7 +131,7 @@ public function connect( $read_timeout = null ) {
130131
/**
131132
* Flushes the entire Redis database using the `WP_REDIS_FLUSH_TIMEOUT`.
132133
*
133-
* @param bool $throw_exception Whether to throw exception on error.
134+
* @param bool $throw_exception Whether to throw exception on error.
134135
* @return bool
135136
*/
136137
public function flush( $throw_exception = false ) {
@@ -167,19 +168,16 @@ public function flush( $throw_exception = false ) {
167168
}
168169

169170
try {
170-
// TODO: test Predis return value...
171-
172-
var_dump($this->redis->flushdb());
173-
exit;
174-
175-
return $this->redis->flushdb();
171+
$this->redis->flushdb();
176172
} catch ( Exception $exception ) {
177173
if ( $throw_exception ) {
178174
throw $exception;
179175
}
180176

181177
return false;
182178
}
179+
180+
return true;
183181
}
184182

185183
/**

0 commit comments

Comments
 (0)