Commit 16999962 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch 'development' into 'master'

Development

See merge request !1904
parents 1bec83f4 fcbe0956
......@@ -22,6 +22,7 @@ CACHE_DRIVER=redis
SESSION_DRIVER=file
QUEUE_CONNECTION=sync
REDIS_CACHE_CONNECTION=cache
REDIS_CACHE_HOST=redis
REDIS_HOST=redis
REDIS_PASSWORD=null
......
......@@ -4,7 +4,6 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Monospice\LaravelRedisSentinel\RedisSentinel;
class AppendLogs extends Command
{
......@@ -47,22 +46,17 @@ class AppendLogs extends Command
{
$redis = null;
if (config("database.redis.cache.driver", "redis") === "redis") {
$redis = Redis::connection('cache');
} elseif (config("database.redis.cache.driver", "redis") === "redis-sentinel") {
$redis = RedisSentinel::connection('cache');
}
$redis = Redis::connection(config('cache.stores.redis.connection'));
if ($redis === null) {
$this->error("No valid Redis Connection specified");
return;
}
$elements = [];
$reply = $redis->pipeline(function ($pipe) use ($elements) {
$pipe->lrange(\App\Console\Commands\AppendLogs::LOGKEY, 0, -1);
$pipe->del(\App\Console\Commands\AppendLogs::LOGKEY);
});
$elements = $reply[0];
$elementCount = $redis->llen(\App\Console\Commands\AppendLogs::LOGKEY);
$elements = $redis->lpop(\App\Console\Commands\AppendLogs::LOGKEY, $elementCount);
if (!is_array($elements) || sizeof($elements) <= 0) {
return;
}
......
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Cache;
class FillCache extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cache:fill';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$writtenBytes = 0;
$lastStatus = microtime(true);
while (true) {
$key = $this->getRandomString(rand(50, 100));
$value = $this->getRandomString(rand(1024*100, 1024*10000));
Cache::put($key, $value);
$writtenBytes += mb_strlen(Cache::get($key));
if(microtime(true) - $lastStatus > 1){
echo "Stored " . $this->formatBytes($writtenBytes) . "." . PHP_EOL;
$lastStatus = microtime(true);
}
}
return 0;
}
function getRandomString($n) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
}
}
......@@ -306,10 +306,8 @@ class HumanVerification extends Controller
abort(404);
}
Redis::connection("cache")->pipeline(function ($redis) use ($key) {
$redis->rpush($key, true);
$redis->expire($key, 30);
});
Redis::connection(config('cache.stores.redis.connection'))->rpush($key, true);
Redis::connection(config('cache.stores.redis.connection'))->expire($key, 30);
return response(view('layouts.resultpage.verificationCss'), 200)->header("Content-Type", "text/css");
}
......
......@@ -9,6 +9,7 @@ use Jenssegers\Agent\Agent;
use LaravelLocalization;
use Illuminate\Support\Facades\Redis;
use Response;
use Cache;
class StartpageController extends Controller
{
......
......@@ -58,7 +58,7 @@ class BrowserVerification
if (!preg_match("/^[a-f0-9]{32}$/", $mgv)) {
abort(404);
}
$result = Redis::connection("cache")->blpop($mgv, 5);
$result = Redis::connection(config('cache.stores.redis.connection'))->blpop($mgv, 5);
if ($result !== null) {
$request->request->add(["headerPrinted" => false, "jskey" => $mgv]);
return $next($request);
......@@ -74,7 +74,7 @@ class BrowserVerification
echo(view('layouts.resultpage.verificationHeader')->with('key', $key)->render());
flush();
$answer = Redis::connection("cache")->blpop($key, 2);
$answer = Redis::connection(config('cache.stores.redis.connection'))->blpop($key, 2);
if ($answer !== null) {
echo(view('layouts.resultpage.resources')->render());
flush();
......
......@@ -318,7 +318,7 @@ class MetaGer
}
if (!empty($this->jskey)) {
$js = Redis::connection('cache')->lpop("js" . $this->jskey);
$js = Redis::connection(config('cache.stores.redis.connection'))->lpop("js" . $this->jskey);
if ($js !== null && boolval($js)) {
$this->javascript = true;
}
......@@ -652,19 +652,10 @@ class MetaGer
public function checkCache()
{
if ($this->canCache()) {
$keys = [];
foreach ($this->engines as $engine) {
$keys[] = $engine->hash;
}
# Noch searchengines enabled
if (empty($keys)) {
return;
}
$cacheValues = Cache::many($keys);
foreach ($this->engines as $engine) {
if ($cacheValues[$engine->hash] !== null) {
if(Cache::has($engine->hash)){
$engine->cached = true;
$engine->retrieveResults($this, $cacheValues[$engine->hash]);
$engine->retrieveResults($this, Cache::get($engine->hash));
}
}
}
......@@ -1514,9 +1505,9 @@ class MetaGer
$logEntry = preg_replace("/\n+/", " ", $logEntry);
if (config("database.redis.cache.driver", "redis") === "redis") {
Redis::connection('cache')->rpush(\App\Console\Commands\AppendLogs::LOGKEY, $logEntry);
Redis::connection(config('cache.stores.redis.connection'))->rpush(\App\Console\Commands\AppendLogs::LOGKEY, $logEntry);
} elseif (config("database.redis.cache.driver", "redis") === "redis-sentinel") {
RedisSentinel::connection('cache')->rpush(\App\Console\Commands\AppendLogs::LOGKEY, $logEntry);
RedisSentinel::connection(config('cache.stores.redis.connection'))->rpush(\App\Console\Commands\AppendLogs::LOGKEY, $logEntry);
}
} catch (\Exception $e) {
Log::error($e->getMessage());
......
......@@ -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": "3baedf432da7113511d963ffc92ade1e",
"content-hash": "d1864366bb8932b5fbc6cb8fe773e467",
"packages": [
{
"name": "asm89/stack-cors",
......@@ -2175,6 +2175,72 @@
],
"time": "2020-07-20T17:29:33+00:00"
},
{
"name": "predis/predis",
"version": "v1.1.7",
"source": {
"type": "git",
"url": "https://github.com/predis/predis.git",
"reference": "b240daa106d4e02f0c5b7079b41e31ddf66fddf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/predis/predis/zipball/b240daa106d4e02f0c5b7079b41e31ddf66fddf8",
"reference": "b240daa106d4e02f0c5b7079b41e31ddf66fddf8",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"suggest": {
"ext-curl": "Allows access to Webdis when paired with phpiredis",
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
},
"type": "library",
"autoload": {
"psr-4": {
"Predis\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla@gmail.com",
"homepage": "http://clorophilla.net",
"role": "Creator & Maintainer"
},
{
"name": "Till Krüss",
"homepage": "https://till.im",
"role": "Maintainer"
}
],
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
"homepage": "http://github.com/predis/predis",
"keywords": [
"nosql",
"predis",
"redis"
],
"support": {
"issues": "https://github.com/predis/predis/issues",
"source": "https://github.com/predis/predis/tree/v1.1.7"
},
"funding": [
{
"url": "https://github.com/sponsors/tillkruss",
"type": "github"
}
],
"time": "2021-04-04T19:34:46+00:00"
},
{
"name": "promphp/prometheus_client_php",
"version": "v2.2.2",
......
......@@ -70,7 +70,7 @@ return [
'redis' => [
'driver' => env('REDIS_CACHE_DRIVER', 'redis'),
'connection' => 'cache',
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
],
],
......
......@@ -111,23 +111,39 @@ return [
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'cluster' => false,
'options' => [
'cluster' => 'redis',
'parameters' => [
'password' => env('REDIS_CACHE_PASSWORD', null),
],
],
'default' => [
'read_write_timeout' => -1,
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'read_write_timeout' => -1,
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'cache' => [
'driver' => env('REDIS_CACHE_DRIVER', 'redis'),
'host' => env('REDIS_CACHE_HOST', 'localhost'),
'password' => env('REDIS_CACHE_PASSWORD', null),
'port' => env('REDIS_CACHE_PORT', 6379),
'database' => 0,
],
"clusters" => [
'clustercache' => [[
'host' => env('REDIS_CACHE_HOST', 'localhost'),
'password' => env('REDIS_CACHE_PASSWORD', null),
'port' => env('REDIS_CACHE_PORT', 6379),
'database' => 0,
]],
]
],
];
......@@ -70,8 +70,8 @@ return [
|
*/
'connection' => "cache",
'connection' => env('REDIS_SESSION_CONNECTION', 'cache'),
/*
|--------------------------------------------------------------------------
| Session Database Table
......
......@@ -243,10 +243,8 @@ Route::get('index.js', function (Request $request) {
abort(404);
}
Redis::connection("cache")->pipeline(function ($redis) use ($key) {
$redis->rpush("js" . $key, true);
$redis->expire($key, 30);
});
Redis::connection(config('cache.stores.redis.connection'))->rpush("js" . $key, true);
Redis::connection(config('cache.stores.redis.connection'))->expire($key, 30);
return response("", 200)->header("Content-Type", "application/javascript");
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment