Skip to content

Commit 9bb17c4

Browse files
authored
Merge pull request #152 from vincent-lu/master
Allow override Redis host/port/prefix via defines
2 parents dfc2af1 + 66043f6 commit 9bb17c4

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ To purge a page immediately, follow these instructions:
9494
* Needless to say, this won't work, if you have a page or taxonomy called 'purge'.
9595

9696

97+
### FAQ - Nginx Redis Cache ###
98+
99+
**Q. Can I override the redis hostname, port and prefix?**
100+
101+
Yes, you can force override the redis hostname, port or prefix by using defines. For example:
102+
103+
`define('RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1');`
104+
105+
`define('RT_WP_NGINX_HELPER_REDIS_PORT', '6000');`
106+
107+
`define('RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:');`
108+
109+
97110
### FAQ - Nginx Map ###
98111

99112
**Q. My multisite already uses `WPMU_ACCEL_REDIRECT`. Do I still need Nginx Map?**

admin/lib/nginx-general.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,34 @@ function nginx_general_options_page()
173173
$redis_hostname = ( empty( $rt_wp_nginx_helper->options['redis_hostname'] ) ) ? '127.0.0.1' : $rt_wp_nginx_helper->options['redis_hostname'];
174174
$redis_port = ( empty( $rt_wp_nginx_helper->options['redis_port'] ) ) ? '6379' : $rt_wp_nginx_helper->options['redis_port'];
175175
$redis_prefix = ( empty( $rt_wp_nginx_helper->options['redis_prefix'] ) ) ? 'nginx-cache:' : $rt_wp_nginx_helper->options['redis_prefix'];
176+
177+
$redis_hostname = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $redis_hostname;
178+
$redis_port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $redis_port;
179+
$redis_prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $redis_prefix;
180+
181+
$redis_hostname_readonly = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? 'readonly="readonly"' : '';
182+
$redis_port_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? 'readonly="readonly"' : '';
183+
$redis_prefix_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? 'readonly="readonly"' : '';
176184
?>
177185
<tr>
178186
<th><label for="redis_hostname"><?php _e( 'Hostname', 'nginx-helper' ); ?></label></th>
179187
<td>
180-
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo $redis_hostname; ?>" />
188+
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo $redis_hostname; ?>" <?php echo $redis_hostname_readonly; ?> />
189+
<?php if ($redis_hostname_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
181190
</td>
182191
</tr>
183192
<tr>
184193
<th><label for="redis_port"><?php _e( 'Port', 'nginx-helper' ); ?></label></th>
185194
<td>
186-
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo $redis_port; ?>" />
195+
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo $redis_port; ?>" <?php echo $redis_port_readonly; ?> />
196+
<?php if ($redis_port_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
187197
</td>
188198
</tr>
189199
<tr>
190200
<th><label for="redis_prefix"><?php _e( 'Prefix', 'nginx-helper' ); ?></label></th>
191201
<td>
192-
<input id="redis_prefix" class="medium-text" type="text" name="redis_prefix" value="<?php echo $redis_prefix; ?>" />
202+
<input id="redis_prefix" class="medium-text" type="text" name="redis_prefix" value="<?php echo $redis_prefix; ?>" <?php echo $redis_prefix_readonly; ?> />
203+
<?php if ($redis_prefix_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
193204
</td>
194205
</tr>
195206
</table>

includes/redis-delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
global $myredis, $rt_wp_nginx_helper, $redis_api, $lua, $rt_wp_nginx_purger;
77

8-
$host = $rt_wp_nginx_helper->options['redis_hostname'];
9-
$port = $rt_wp_nginx_helper->options['redis_port'];
8+
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
9+
$port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $rt_wp_nginx_helper->options['redis_port'];
1010
$redis_api = '';
1111

1212
if ( class_exists( 'Redis' ) ) { // Use PHP5-Redis if installed.

redis-purger.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ function purgeUrl( $url, $feed = true ) {
220220
$parse['path'] = '';
221221
}
222222

223-
$host = $rt_wp_nginx_helper->options['redis_hostname'];
223+
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
224224

225-
$prefix = $rt_wp_nginx_helper->options['redis_prefix'];
225+
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
226226

227227
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
228228

@@ -675,7 +675,8 @@ function purge_on_check_ajax_referer( $action, $result )
675675
function true_purge_all()
676676
{
677677
global $rt_wp_nginx_helper;
678-
$prefix = trim( $rt_wp_nginx_helper->options['redis_prefix'] );
678+
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
679+
$prefix = trim( $prefix );
679680

680681
$this->log( '* * * * *' );
681682

@@ -698,8 +699,8 @@ function purge_urls()
698699
global $rt_wp_nginx_helper;
699700

700701
$parse = parse_url( site_url() );
701-
$host = $rt_wp_nginx_helper->options['redis_hostname'];
702-
$prefix = $rt_wp_nginx_helper->options['redis_prefix'];
702+
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
703+
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
703704
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
704705

705706
$purge_urls = isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ?

0 commit comments

Comments
 (0)