wip redis

This commit is contained in:
2024-12-18 00:21:43 +08:00
parent 0df4578e09
commit 256248f635
7 changed files with 55 additions and 17 deletions

View File

@@ -1,7 +1,15 @@
APP_TITLE='Плейлисты IPTV'
APP_URL=http://localhost:8080
APP_URL=http://localhost:${IPTV_NGNIX_PORT}
TWIG_CACHE=1
TWIG_DEBUG=0
FLIGHT_CASE_SENSITIVE=0
FLIGHT_HANDLE_ERRORS=1
FLIGHT_LOG_ERRORS=1
REDIS_HOST=iptv-keydb
REDIS_PORT=6379
REDIS_DB=0
REDIS_USER=
REDIS_PASS=

View File

@@ -4,6 +4,7 @@
"ext-json": "*",
"ext-curl": "*",
"ext-fileinfo": "*",
"ext-redis": "*",
"mikecao/flight": "^3.12",
"symfony/dotenv": "^7.1",
"twig/twig": "^3.14"

View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1aaea4609092e8a88074f050dab42323",
"content-hash": "4d763eef27bbfd40014e392726e5afc1",
"packages": [
{
"name": "mikecao/flight",
@@ -244,8 +244,8 @@
"type": "library",
"extra": {
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
@@ -323,8 +323,8 @@
"type": "library",
"extra": {
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
@@ -397,8 +397,8 @@
"type": "library",
"extra": {
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
@@ -455,16 +455,16 @@
},
{
"name": "twig/twig",
"version": "v3.16.0",
"version": "v3.17.1",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "475ad2dc97d65d8631393e721e7e44fb544f0561"
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/475ad2dc97d65d8631393e721e7e44fb544f0561",
"reference": "475ad2dc97d65d8631393e721e7e44fb544f0561",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71",
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71",
"shasum": ""
},
"require": {
@@ -519,7 +519,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.16.0"
"source": "https://github.com/twigphp/Twig/tree/v3.17.1"
},
"funding": [
{
@@ -531,7 +531,7 @@
"type": "tidelift"
}
],
"time": "2024-11-29T08:27:05+00:00"
"time": "2024-12-12T09:58:10+00:00"
}
],
"packages-dev": [],
@@ -541,10 +541,11 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^8.2",
"php": "^8.4",
"ext-json": "*",
"ext-curl": "*",
"ext-fileinfo": "*"
"ext-fileinfo": "*",
"ext-redis": "*"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"

View File

@@ -4,14 +4,16 @@ declare(strict_types=1);
return [
// https://flightphp.com/learn#configuration
'flight.base_url' => env('APP_URL', 'http://localhost:8080'),
'flight.base_url' => env('APP_URL', 'http://localhost:' . env('IPTV_NGNIX_PORT')),
'flight.case_sensitive' => bool(env('FLIGHT_CASE_SENSITIVE', false)),
'flight.handle_errors' => bool(env('FLIGHT_HANDLE_ERRORS', true)),
'flight.log_errors' => bool(env('FLIGHT_LOG_ERRORS', true)),
'flight.views.path' => views_path(),
'flight.views.extension' => '.twig',
'twig.cache' => bool(env('TWIG_CACHE', true)) ? cache_path() . '/views' : false,
'twig.debug' => bool(env('TWIG_DEBUG', false)),
'app.title' => env('APP_TITLE', 'IPTV Playlists'),
'app.pls_encodings' => [
'UTF-8',
@@ -19,4 +21,10 @@ return [
// 'CP866',
// 'ISO-8859-5',
],
'redis.host' => env('REDIS_HOST', 'iptv-keydb'),
'redis.port' => (int)env('REDIS_PORT', 6379),
// 'redis.user' => env('REDIS_USER'),
// 'redis.password' => env('REDIS_PASS'),
'redis.database' => (int)env('REDIS_DB', 0),
];

View File

@@ -21,6 +21,8 @@ class HomeController extends Controller
*/
public function index(int $page = 1): void
{
$redis = Flight::get('redis');
// если пришёл любой get-параметр, то считаем его как id плейлиста и перебрасываем на страницу о нём
if (Flight::request()->query->count() > 0) {
$id = Flight::request()->query->keys()[0];

View File

@@ -71,4 +71,21 @@ final class Bootstrapper
Flight::route($route, $handler);
}
}
public static function bootRedis(): void
{
$options = [
'host' => config('redis.host'),
'port' => config('redis.port'),
// 'username' => config('redis.user'),
// 'pass' => config('redis.password'),
'connectTimeout' => 1,
];
$redis = new \Redis($options);
$redis->select((int)config('redis.database'));
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_JSON);
Flight::set('redis', $redis);
}
}

View File

@@ -17,4 +17,5 @@ Bootstrapper::bootSettings();
Bootstrapper::bootTwig();
Bootstrapper::bootCore();
Bootstrapper::bootRoutes();
Bootstrapper::bootRedis();
Flight::start();