-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add Username, Password, Database and Unix Socket support. #352
base: develop
Are you sure you want to change the base?
Changes from all commits
55a5631
367d97c
14eca80
8c58de3
2258c1a
e489543
c30a622
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,8 +276,14 @@ public function nginx_helper_default_settings() { | |
'redis_hostname' => '127.0.0.1', | ||
'redis_port' => '6379', | ||
'redis_prefix' => 'nginx-cache:', | ||
'redis_unix_socket' => '', | ||
'redis_database' => 0, | ||
'redis_username' => '', | ||
'redis_password' => '', | ||
'purge_url' => '', | ||
'redis_enabled_by_constant' => 0, | ||
'redis_socket_enabled_by_constant' => 0, | ||
'redis_acl_enabled_by_constant' => 0, | ||
); | ||
|
||
} | ||
|
@@ -295,6 +301,7 @@ public function nginx_helper_settings() { | |
'redis_hostname' => '127.0.0.1', | ||
'redis_port' => '6379', | ||
'redis_prefix' => 'nginx-cache:', | ||
'redis_database' => 0, | ||
) | ||
); | ||
|
||
|
@@ -308,17 +315,24 @@ public function nginx_helper_settings() { | |
defined( 'RT_WP_NGINX_HELPER_REDIS_PORT' ) && | ||
defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) | ||
); | ||
|
||
$data['redis_acl_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_USERNAME') && defined('RT_WP_NGINX_HELPER_REDIS_PASSWORD'); | ||
$data['redis_socket_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET'); | ||
$data['redis_unix_socket'] = $data['redis_socket_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET : $data['redis_unix_socket']; | ||
$data['redis_username'] = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_USERNAME : $data['redis_username']; | ||
$data['redis_password'] = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_PASSWORD : $data['redis_password']; | ||
|
||
if ( ! $is_redis_enabled ) { | ||
return $data; | ||
} | ||
|
||
$data['redis_enabled_by_constant'] = $is_redis_enabled; | ||
$data['enable_purge'] = $is_redis_enabled; | ||
$data['cache_method'] = 'enable_redis'; | ||
$data['redis_hostname'] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; | ||
$data['redis_port'] = RT_WP_NGINX_HELPER_REDIS_PORT; | ||
$data['redis_prefix'] = RT_WP_NGINX_HELPER_REDIS_PREFIX; | ||
$data['redis_enabled_by_constant'] = $is_redis_enabled; | ||
$data['enable_purge'] = $is_redis_enabled; | ||
$data['cache_method'] = 'enable_redis'; | ||
$data['redis_hostname'] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; | ||
$data['redis_port'] = RT_WP_NGINX_HELPER_REDIS_PORT; | ||
$data['redis_prefix'] = RT_WP_NGINX_HELPER_REDIS_PREFIX; | ||
$data['redis_database'] = defined('RT_WP_NGINX_HELPER_REDIS_DATABASE') ? RT_WP_NGINX_HELPER_REDIS_DATABASE : 0; | ||
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. Fix indentation |
||
|
||
return $data; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,32 @@ public function __construct() { | |
try { | ||
|
||
$this->redis_object = new Redis(); | ||
|
||
$redis_acl = array(); | ||
|
||
$username = $nginx_helper_admin->options['redis_username']; | ||
$password = $nginx_helper_admin->options['redis_password']; | ||
|
||
if( $username && $password ) { | ||
$redis_acl['auth'] = array( $username, $password ); | ||
} | ||
|
||
$hostname = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_hostname'] : $nginx_helper_admin->options['redis_unix_socket']; | ||
$port = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_port'] : 0; | ||
|
||
$this->redis_object->connect( | ||
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. On my local setup, there’s no Nginx server or Redis installed. When I switch branches from master to your branch, the code throws a fatal error. The plugin is trying to connect, but the connection is being refused. If the plugin is attempting to make a connection, there should also be a fatal error in the master branch. Please take a look into this 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. @SH4LIN I am unable to replicate the issue on my end. Can you please share the error here if possible? 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. Sure. |
||
$nginx_helper_admin->options['redis_hostname'], | ||
$nginx_helper_admin->options['redis_port'], | ||
5 | ||
$hostname, | ||
$port, | ||
5, | ||
null, | ||
0, | ||
0, | ||
$redis_acl | ||
); | ||
|
||
if( $nginx_helper_admin->options['redis_database'] !== 0 ) { | ||
$this->redis_object->select($nginx_helper_admin->options['redis_database']); | ||
} | ||
|
||
} catch ( Exception $e ) { | ||
$this->log( $e->getMessage(), 'ERROR' ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ | |
'redis_hostname', | ||
'redis_port', | ||
'redis_prefix', | ||
'redis_database', | ||
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. Fix the indentation |
||
'redis_username', | ||
'redis_password', | ||
'redis_unix_socket', | ||
'redis_socket_enabled_by_constant', | ||
'redis_acl_enabled_by_constant', | ||
'purge_homepage_on_edit', | ||
'purge_homepage_on_del', | ||
'purge_url', | ||
|
@@ -246,7 +252,7 @@ | |
<tr> | ||
<th><label for="redis_hostname"><?php esc_html_e( 'Hostname', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) { | ||
|
||
|
@@ -256,12 +262,19 @@ | |
|
||
} | ||
?> | ||
<?php | ||
if ( $nginx_helper_settings['redis_unix_socket'] ) { | ||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' ); | ||
echo '</p>'; | ||
} | ||
?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th><label for="redis_port"><?php esc_html_e( 'Port', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) { | ||
|
||
|
@@ -271,8 +284,32 @@ | |
|
||
} | ||
?> | ||
<?php | ||
if ( $nginx_helper_settings['redis_unix_socket'] ) { | ||
|
||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' ); | ||
echo '</p>'; | ||
|
||
} | ||
?> | ||
</td> | ||
</tr> | ||
<tr> | ||
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. Fix the indentation and use tabs instead of the space |
||
<th><label for="redis_unix_socket"><?php esc_html_e( 'Socket Path', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_unix_socket" class="medium-text" type="text" name="redis_unix_socket" value="<?php echo esc_attr( $nginx_helper_settings['redis_unix_socket'] ); ?>" <?php echo ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) { | ||
|
||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); | ||
echo '</p>'; | ||
|
||
} | ||
?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th><label for="redis_prefix"><?php esc_html_e( 'Prefix', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
|
@@ -288,6 +325,53 @@ | |
?> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th><label for="redis_database"><?php esc_html_e( 'Database', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_database" class="medium-text" type="text" name="redis_database" value="<?php echo esc_attr( $nginx_helper_settings['redis_database'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) { | ||
|
||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); | ||
echo '</p>'; | ||
|
||
} | ||
?> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<th><label for="redis_username"><?php esc_html_e( 'Username', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_username" class="medium-text" type="text" name="redis_username" value="<?php echo esc_attr( $nginx_helper_settings['redis_username'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) { | ||
|
||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); | ||
echo '</p>'; | ||
|
||
} | ||
?> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<th><label for="redis_password"><?php esc_html_e( 'Password', 'nginx-helper' ); ?></label></th> | ||
<td> | ||
<input id="redis_password" class="medium-text" type="text" name="redis_password" value="<?php echo esc_attr( $nginx_helper_settings['redis_password'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> /> | ||
<?php | ||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) { | ||
|
||
echo '<p class="description">'; | ||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' ); | ||
echo '</p>'; | ||
|
||
} | ||
?> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> <!-- End of .inside --> | ||
</div> | ||
|
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.
Fix the indentation