-
-
Notifications
You must be signed in to change notification settings - Fork 160
WP_REDIS_SERVERLESS_WORKAROUND #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ustramooner
wants to merge
36
commits into
rhubarbgroup:develop
Choose a base branch
from
campaign-in-a-box:WP_REDIS_SERVERLESS_WORKAROUND
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
83ea358
remove old rules
tillkruss 7e3a04a
Merge remote-tracking branch 'origin/develop'
tillkruss 0293eb1
Merge remote-tracking branch 'origin/develop'
tillkruss c4b5f7c
Merge remote-tracking branch 'origin/develop'
tillkruss 1148bf6
Merge remote-tracking branch 'origin/develop'
tillkruss 60467c1
Merge remote-tracking branch 'origin/develop'
tillkruss 89e69d6
Merge remote-tracking branch 'origin/develop'
tillkruss 326d8a1
Merge remote-tracking branch 'origin/develop'
tillkruss 856f496
Merge remote-tracking branch 'origin/develop'
tillkruss e580c96
Merge remote-tracking branch 'origin/develop'
tillkruss 14d740b
Merge branch 'develop'
tillkruss b397939
bump tested version
tillkruss 872ad76
adds support for ssl context in redis clusters (#518)
mbrowngold c6b91f0
drop 7.2 linting
tillkruss c4c3d73
Fixed issue with Predis and replication connection (#520)
yatsukhnenko c3e1b89
Fixed loading textdomain in show_error_and_die (#533)
yatsukhnenko 352c9f2
Introduce WP_REDIS_DISABLE_GROUP_FLUSH to disable group flushing (#532)
yatsukhnenko 81a0406
Fix Redis version determination for predis replication connection (#522)
yatsukhnenko 0ebd266
Fix Predis cluster flush (#529)
yatsukhnenko 1816d87
document WP_REDIS_DISABLE_COMMENT
tillkruss b6ef5a8
Add filter to allow customizing who can flush the cache (#535)
pmgarman 7ea28cf
remove whitespace [skip ci]
tillkruss 034def1
Update phpstan.dist.neon
tillkruss 6848677
ignore warning
tillkruss 19a6e16
Update CHANGELOG.md [skip ci]
tillkruss 9a123ef
tag v2.5.3
tillkruss 3e97403
update pot file
tillkruss 9b49863
Merge remote-tracking branch 'origin/develop'
tillkruss df6b081
Merge remote-tracking branch 'origin/develop'
tillkruss 10e4627
Merge remote-tracking branch 'origin/develop'
tillkruss 5bfcc7d
bump pot file
tillkruss 6880fdd
Merge remote-tracking branch 'origin/develop'
tillkruss 53e8f95
Merge remote-tracking branch 'origin/develop'
tillkruss 6a002ca
WP_REDIS_SERVERLESS_WORKAROUND
ustramooner 1d2c1f4
implement pconnect
ustramooner b929e42
Merge branch 'main' of github.com:rhubarbgroup/redis-cache into WP_RE…
ustramooner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -640,6 +640,7 @@ protected function build_parameters() { | |
| 'timeout', | ||
| 'read_timeout', | ||
| 'retry_interval', | ||
| 'persistent', | ||
| ]; | ||
|
|
||
| foreach ( $settings as $setting ) { | ||
|
|
@@ -657,7 +658,7 @@ protected function build_parameters() { | |
| $this->diagnostics[ 'timeout' ] = $parameters[ 'timeout' ]; | ||
| $this->diagnostics[ 'read_timeout' ] = $parameters[ 'read_timeout' ]; | ||
| $this->diagnostics[ 'retry_interval' ] = $parameters[ 'retry_interval' ]; | ||
|
|
||
| $this->diagnostics[ 'persistent' ] = $parameters[ 'persistent' ]; | ||
| return $parameters; | ||
| } | ||
|
|
||
|
|
@@ -705,11 +706,23 @@ protected function connect_using_phpredis( $parameters ) { | |
| } else { | ||
| $this->redis = new Redis(); | ||
|
|
||
| if ( $parameters['persistent'] ) { | ||
| $persistent_id = sprintf( | ||
| '%s:%s:%s:%s', | ||
| $parameters['host'], | ||
| $parameters['port'], | ||
| $parameters['database'], | ||
| isset( $parameters['password'] ) ? hash( 'sha256', json_encode( $parameters['password'] ) ) : '' | ||
| ); | ||
| }else{ | ||
| $persistent_id = ''; | ||
| } | ||
|
|
||
| $args = [ | ||
| 'host' => $parameters['host'], | ||
| 'port' => $parameters['port'], | ||
| 'timeout' => $parameters['timeout'], | ||
| '', | ||
| $persistent_id, | ||
| 'retry_interval' => (int) $parameters['retry_interval'], | ||
| ]; | ||
|
|
||
|
|
@@ -734,7 +747,8 @@ protected function connect_using_phpredis( $parameters ) { | |
| $args['port'] = -1; | ||
| } | ||
|
|
||
| call_user_func_array( [ $this->redis, 'connect' ], array_values( $args ) ); | ||
| call_user_func_array( [ $this->redis, $parameters['persistent'] ? 'pconnect' : 'connect' ], array_values( $args ) ); | ||
| $args['persistent'] = $parameters['persistent']; | ||
|
|
||
| if ( isset( $parameters['password'] ) ) { | ||
| $args['password'] = $parameters['password']; | ||
|
|
@@ -1083,6 +1097,8 @@ public function fetch_info() { | |
| $info = $this->is_predis() | ||
| ? $this->redis->getClientBy( 'id', $connectionId )->info() | ||
| : $this->redis->info( $connectionId ); | ||
| } else if ($this->is_predis() && $this->redis->getConnection() instanceof Predis\Connection\Replication\MasterSlaveReplication) { | ||
| $info = $this->redis->getClientBy( 'role' , 'master' )->info(); | ||
| } else { | ||
| if ( $this->is_predis() ) { | ||
| $connection = $this->redis->getConnection(); | ||
|
|
@@ -1215,6 +1231,9 @@ protected function add_multiple_at_once( array $data, $group = 'default', $expir | |
|
|
||
| $san_key = $this->sanitize_key_part( $key ); | ||
| $derived_key = $derived_keys[ $key ] = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a README entry with explanation |
||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| $args = [ $derived_key, $this->maybe_serialize( $value ) ]; | ||
|
|
||
|
|
@@ -1313,6 +1332,9 @@ protected function add_or_replace( $add, $key, $value, $group = 'default', $expi | |
| $san_group = $this->sanitize_key_part( $group ); | ||
|
|
||
| $derived_key = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| // Save if group not excluded and redis is up. | ||
| if ( ! $this->is_ignored_group( $san_group ) && $this->redis_status() ) { | ||
|
|
@@ -1404,6 +1426,9 @@ public function delete( $key, $group = 'default', $deprecated = false ) { | |
| $san_group = $this->sanitize_key_part( $group ); | ||
|
|
||
| $derived_key = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->srem(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| if ( array_key_exists( $derived_key, $this->cache ) ) { | ||
| unset( $this->cache[ $derived_key ] ); | ||
|
|
@@ -1639,11 +1664,22 @@ public function flush() { | |
| $start_time = microtime( true ); | ||
|
|
||
| if ( $salt && $selective ) { | ||
| $script = $this->get_flush_closure( $salt ); | ||
| $results = $this->execute_lua_script( $script ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $results = $this->redis->smembers(WP_REDIS_SERVERLESS_WORKAROUND); | ||
| foreach ($results as $key) { | ||
| $this->redis->srem(WP_REDIS_SERVERLESS_WORKAROUND, $key); | ||
| $this->redis->del($key); | ||
| } | ||
| if (empty($results)) { | ||
| return false; | ||
| } | ||
| } else { | ||
| $script = $this->get_flush_closure($salt); | ||
| $results = $this->execute_lua_script($script); | ||
|
|
||
| if ( empty( $results ) ) { | ||
| if (empty($results)) { | ||
| return false; | ||
| } | ||
| } | ||
| } else { | ||
| if ( defined( 'WP_REDIS_CLUSTER' ) ) { | ||
|
|
@@ -2147,6 +2183,9 @@ public function set( $key, $value, $group = 'default', $expiration = 0 ) { | |
| $san_group = $this->sanitize_key_part( $group ); | ||
|
|
||
| $derived_key = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| // Save if group not excluded from redis and redis is up. | ||
| if ( ! $this->is_ignored_group( $group ) && $this->redis_status() ) { | ||
|
|
@@ -2257,6 +2296,9 @@ protected function set_multiple_at_once( array $data, $group = 'default', $expir | |
| foreach ( $data as $key => $value ) { | ||
| $san_key = $this->sanitize_key_part( $key ); | ||
| $derived_key = $derived_keys[ $key ] = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| /** | ||
| * Filters the cache expiration time | ||
|
|
@@ -2340,6 +2382,9 @@ public function increment( $key, $offset = 1, $group = 'default' ) { | |
| $san_group = $this->sanitize_key_part( $group ); | ||
|
|
||
| $derived_key = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| // If group is a non-Redis group, save to internal cache, not Redis. | ||
| if ( $this->is_ignored_group( $group ) || ! $this->redis_status() ) { | ||
|
|
@@ -2417,6 +2462,9 @@ public function decrement( $key, $offset = 1, $group = 'default' ) { | |
| $san_group = $this->sanitize_key_part( $group ); | ||
|
|
||
| $derived_key = $this->fast_build_key( $san_key, $san_group ); | ||
| if (defined('WP_REDIS_SERVERLESS_WORKAROUND') && WP_REDIS_SERVERLESS_WORKAROUND ) { | ||
| $this->redis->sadd(WP_REDIS_SERVERLESS_WORKAROUND, $derived_key); | ||
| } | ||
|
|
||
| // If group is a non-Redis group, save to internal cache, not Redis. | ||
| if ( $this->is_ignored_group( $group ) || ! $this->redis_status() ) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
| $filesystem_writable = $roc->test_filesystem_writing(); | ||
|
|
||
| $diagnostics = $roc->get_diagnostics(); | ||
|
|
||
| ?> | ||
|
|
||
| <?php if ( is_string( $redis_connection ) ) : ?> | ||
|
|
@@ -226,6 +225,13 @@ | |
| </tr> | ||
| <?php endif; ?> | ||
|
|
||
| <?php if ( isset( $diagnostics['persistent'] ) ) : ?> | ||
| <tr> | ||
| <th><?php esc_html_e( 'Persistent Connection:', 'redis-cache' ); ?></th> | ||
| <td><code><?php echo esc_html( $diagnostics['persistent'] ? 'Yes' : 'No' ); ?></code></td> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure these are translatable. |
||
| </tr> | ||
| <?php endif; ?> | ||
|
|
||
| <?php if ( isset( $diagnostics['read_timeout'] ) ) : ?> | ||
| <tr> | ||
| <th><?php esc_html_e( 'Read Timeout:', 'redis-cache' ); ?></th> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs several changelog entries.