diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 0ec580df..1817e397 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use Redis; use Option; use Carbon\Carbon; use App\Models\User; @@ -249,8 +250,26 @@ class AdminController extends Controller }) ->handle(); + $redis = Option::form('redis', 'Redis', function ($form) { + $form->checkbox('enable_redis')->label(); + }); + + if (option('enable_redis')) { + try { + Redis::ping(); + $redis->addMessage(trans('options.redis.connect.success'), 'success'); + } catch (\Exception $e) { + $redis->addMessage( + trans('options.redis.connect.failed', ['msg' => $e->getMessage()]), + 'danger' + ); + } + } + + $redis->handle(); + return view('admin.resource') - ->with('forms', compact('resources')); + ->with('forms', compact('resources', 'redis')); } public function getUserData(Request $request) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 476a633c..47e3f524 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use Blade; use Event; +use Redis; use App\Events; use App\Models\User; use ReflectionException; @@ -44,6 +45,15 @@ class AppServiceProvider extends ServiceProvider } catch (ReflectionException $e) { throw new PrettyPageException(trans('errors.cipher.unsupported', ['cipher' => config('secure.cipher')])); } + + try { + if (Redis::ping()) { + config(['cache.default' => 'redis']); + config(['session.driver' => 'redis']); + } + } catch (\Exception $e) { + // + } } /** diff --git a/config/app.php b/config/app.php index e9bd7b36..fa88a66b 100644 --- a/config/app.php +++ b/config/app.php @@ -220,7 +220,7 @@ return [ 'Password' => Illuminate\Support\Facades\Password::class, 'Queue' => Illuminate\Support\Facades\Queue::class, 'Redirect' => Illuminate\Support\Facades\Redirect::class, - 'Predis' => Illuminate\Support\Facades\Redis::class, + 'Redis' => Illuminate\Support\Facades\Redis::class, 'Request' => Illuminate\Support\Facades\Request::class, 'Response' => Illuminate\Support\Facades\Response::class, 'Route' => Illuminate\Support\Facades\Route::class, diff --git a/resources/lang/en/options.yml b/resources/lang/en/options.yml index c7b7546a..8a502ab1 100644 --- a/resources/lang/en/options.yml +++ b/resources/lang/en/options.yml @@ -124,6 +124,17 @@ announ: announcement: description: Styling with Markdown is supported. You can also specify a different announcement for each language. To edit a specific language's corresponding announcement, please switch to that language and submit your edit. +meta: + title: SEO tags + meta_keywords: + title: Keywords + hint: Split with commas. + meta_description: + title: Description + hint: Description defined in "general options" will be used if you left it empty. + meta_extras: + title: Other Custom Tags + resources: title: Resource Files hint: Please check these options if you enabled CDN for your site. @@ -151,13 +162,10 @@ resources: all the files of that directory will be loaded as CDN.
How to verify? Verify if {Your CDN URL}/app/index.js can be accessed. -meta: - title: SEO tags - meta_keywords: - title: Keywords - hint: Split with commas. - meta_description: - title: Description - hint: Description defined in "general options" will be used if you left it empty. - meta_extras: - title: Other Custom Tags +redis: + enable_redis: + title: Enable + label: Enable Redis + connect: + success: Connected to Redis server successfully. + failed: 'Failed to connect Redis server. Error: :msg' diff --git a/resources/lang/zh_CN/options.yml b/resources/lang/zh_CN/options.yml index 12f960d0..5193e987 100644 --- a/resources/lang/zh_CN/options.yml +++ b/resources/lang/zh_CN/options.yml @@ -124,6 +124,17 @@ announ: announcement: description: 可使用 Markdown 进行排版。每种支持的语言都可以对应不同的站点公告,如果想要编辑某种特定语言下的公告,请在右上角切换至该语言后再提交修改。 +meta: + title: SEO 标签 + meta_keywords: + title: 关键词 + hint: 使用半角逗号分隔 + meta_description: + title: 描述 + hint: 留空以使用 站点配置 中的站点描述 + meta_extras: + title: 其它自定义 标签 + resources: title: 资源文件配置 hint: 如果启用了 CDN 缓存请适当修改这些配置 @@ -150,13 +161,10 @@ resources: 填写的 CDN 地址必须是 /public 目录的镜像,此目录下的所有文件都将会从 CDN 加载。
测试方法:检查 {填写的地址}/app/index.js 是否能够访问。 -meta: - title: SEO 标签 - meta_keywords: - title: 关键词 - hint: 使用半角逗号分隔 - meta_description: - title: 描述 - hint: 留空以使用 站点配置 中的站点描述 - meta_extras: - title: 其它自定义 标签 +redis: + enable_redis: + title: 启用 + label: 使用 Redis + connect: + success: 成功连接 Redis 服务器。 + failed: '连接 Redis 服务器失败。错误消息: :msg' diff --git a/resources/views/admin/resource.blade.php b/resources/views/admin/resource.blade.php index b4706c6e..f059d4c8 100644 --- a/resources/views/admin/resource.blade.php +++ b/resources/views/admin/resource.blade.php @@ -22,6 +22,7 @@
+ {!! $forms['redis']->render() !!}
diff --git a/tests/AdminControllerTest.php b/tests/AdminControllerTest.php index bdb24b8f..cc06da90 100644 --- a/tests/AdminControllerTest.php +++ b/tests/AdminControllerTest.php @@ -2,6 +2,7 @@ namespace Tests; +use Redis; use App\Models\User; use App\Models\Player; use App\Models\Texture; @@ -167,6 +168,18 @@ class AdminControllerTest extends BrowserKitTestCase ->type('', 'cdn_address') ->press('submit_resources'); $this->visit('/')->dontSee('url/app/index.js'); + + $this->visit('/admin/resource') + ->check('enable_redis') + ->press('submit_redis'); + $this->assertTrue(option('enable_redis')); + + Redis::shouldReceive('ping')->once()->andReturn(true); + $this->visit('/admin/resource')->see(trans('options.redis.connect.success')); + + Redis::shouldReceive('ping')->once()->andThrow(new \Exception('fake')); + $this->visit('/admin/resource') + ->see(trans('options.redis.connect.failed', ['msg' => 'fake'])); } public function testUsers()