From 8f9eacee646462c07a3cf6dac47d68dca8ac38f4 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 12 May 2016 00:46:41 +0900 Subject: [PATCH] Add DB number to redis cache settings, and set the default to 1 --- common/framework/drivers/cache/redis.php | 4 ++-- modules/admin/admin.admin.controller.php | 4 ++++ modules/admin/admin.admin.view.php | 3 +++ modules/admin/lang/en.php | 1 + modules/admin/lang/ja.php | 1 + modules/admin/lang/ko.php | 1 + modules/admin/tpl/config_advanced.html | 1 + modules/admin/tpl/js/config.js | 14 ++++++++++---- 8 files changed, 23 insertions(+), 6 deletions(-) diff --git a/common/framework/drivers/cache/redis.php b/common/framework/drivers/cache/redis.php index aec267e06..87dd9e51c 100644 --- a/common/framework/drivers/cache/redis.php +++ b/common/framework/drivers/cache/redis.php @@ -29,12 +29,13 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface { try { - $this->_conn = new \Redis; + $this->_conn = null; foreach ($config as $url) { $info = parse_url($url); if (isset($info['host']) && isset($info['port'])) { + $this->_conn = new \Redis; $this->_conn->connect($info['host'], $info['port'], 0.15); if(isset($info['user']) || isset($info['pass'])) { @@ -47,7 +48,6 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface break; } } - $this->_conn = null; } catch (\RedisException $e) { diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index 595662f38..707b3436f 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -675,6 +675,10 @@ class adminAdminController extends admin if ($vars->object_cache_type === 'memcached' || $vars->object_cache_type === 'redis') { $cache_servers = array($vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port)); + if ($vars->object_cache_type === 'redis') + { + $cache_servers[0] .= '/' . intval($vars->object_cache_dbnum); + } } else { diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index cbcc8d196..74e1e6d02 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -515,11 +515,14 @@ class adminAdminView extends admin { Context::set('object_cache_host', parse_url(array_first($cache_servers), PHP_URL_HOST) ?: null); Context::set('object_cache_port', parse_url(array_first($cache_servers), PHP_URL_PORT) ?: null); + $cache_dbnum = preg_replace('/[^\d]/', '', parse_url(array_first($cache_servers), PHP_URL_PATH)); + Context::set('object_cache_dbnum', $cache_dbnum === '' ? 1 : intval($cache_dbnum)); } else { Context::set('object_cache_host', null); Context::set('object_cache_port', null); + Context::set('object_cache_dbnum', 1); } // Thumbnail settings diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index 2b42c904f..20c7e796b 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -106,6 +106,7 @@ $lang->use_object_cache = 'Use Cache'; $lang->cache_default_ttl = 'Cache default TTL'; $lang->cache_host = 'Host'; $lang->cache_port = 'Port'; +$lang->cache_dbnum = 'DB Number'; $lang->msg_cache_handler_not_supported = 'Your server does not support the selected cache method, or Rhymix is unable to use the cache with the given settings.'; $lang->msg_invalid_default_url = 'The default URL is invalid.'; $lang->msg_default_url_ssl_inconsistent = 'In order to use SSL always, the default URL must also begin with https://'; diff --git a/modules/admin/lang/ja.php b/modules/admin/lang/ja.php index 61d8c023e..5b83904d5 100644 --- a/modules/admin/lang/ja.php +++ b/modules/admin/lang/ja.php @@ -96,6 +96,7 @@ $lang->about_delay_session = 'Varnishなどのプロキシキャッシュサー $lang->use_object_cache = 'キャッシュ使用'; $lang->cache_host = 'ホスト'; $lang->cache_port = 'ポート'; +$lang->cache_dbnum = 'DB番号'; $lang->msg_cache_handler_not_supported = '選択したキャッシュ方式をサーバーでサポートされていないか、与えられた情報でキャッシュにアクセスすることができません。'; $lang->msg_invalid_default_url = '基本URLが正しくありません。'; $lang->msg_default_url_ssl_inconsistent = 'SSLを常に使用する場合、基本URLもhttps://で始まる必要があります。'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index b0a0a8edd..e6a4b8e4f 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -106,6 +106,7 @@ $lang->use_object_cache = '캐시 사용'; $lang->cache_default_ttl = '캐시 기본 TTL'; $lang->cache_host = '호스트'; $lang->cache_port = '포트'; +$lang->cache_dbnum = 'DB번호'; $lang->msg_cache_handler_not_supported = '선택하신 캐시 방식을 서버에서 지원하지 않거나, 주어진 정보로 캐시에 접속할 수 없습니다.'; $lang->msg_invalid_default_url = '기본 URL이 올바르지 않습니다.'; $lang->msg_default_url_ssl_inconsistent = 'SSL을 항상 사용하실 경우 기본 URL도 https://로 시작해야 합니다.'; diff --git a/modules/admin/tpl/config_advanced.html b/modules/admin/tpl/config_advanced.html index 85619aab7..073170cb7 100644 --- a/modules/admin/tpl/config_advanced.html +++ b/modules/admin/tpl/config_advanced.html @@ -80,6 +80,7 @@ diff --git a/modules/admin/tpl/js/config.js b/modules/admin/tpl/js/config.js index af2d62a3a..89ca1bd87 100644 --- a/modules/admin/tpl/js/config.js +++ b/modules/admin/tpl/js/config.js @@ -12,11 +12,17 @@ jQuery(function($){ if (!$("#object_cache_port").val()) { $("#object_cache_port").val($(this).val().match(/memcache/) ? '11211' : '6379'); } - if ($(this).val().match(/memcache/) && $("#object_cache_port").val() == '6379') { - $("#object_cache_port").val('11211'); + if ($(this).val().match(/memcache/)) { + if ($("#object_cache_port").val() == '6379') { + $("#object_cache_port").val('11211'); + } + $("#object_cache_dbnum").parents("label").hide(); } - if ($(this).val().match(/redis/) && $("#object_cache_port").val() == '11211') { - $("#object_cache_port").val('6379'); + if ($(this).val().match(/redis/)) { + if ($("#object_cache_port").val() == '11211') { + $("#object_cache_port").val('6379'); + } + $("#object_cache_dbnum").parents("label").show(); } } else { $("#object_cache_additional_config").hide();