Added redis to load

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-12 09:50:27 -04:00
parent 9f9d1fa916
commit 5adc1b46bf
7 changed files with 124 additions and 5 deletions
+4
View File
@@ -30,3 +30,7 @@ defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
| items. It can always be used within your own application too.
*/
defined('CI_DEBUG') || define('CI_DEBUG', true);
define('ENV_ID', 'DEVLP20233103-A3');
define('HOME_PAGE_BACKGROUND', 'api_bk.jpg');
define('CACHE_DOMAIN', 'wrench.dev');
+4
View File
@@ -19,3 +19,7 @@ error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE &
| release of the framework.
*/
defined('CI_DEBUG') || define('CI_DEBUG', false);
define('ENV_ID', 'PRAODUCTIONG20233103-A3');
define('HOME_PAGE_BACKGROUND', 'api_bk.jpg');
define('CACHE_DOMAIN', 'wrench.prod');
+4
View File
@@ -30,3 +30,7 @@ defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
| release of the framework.
*/
defined('CI_DEBUG') || define('CI_DEBUG', true);
define('ENV_ID', 'TESTING20233103-A3');
define('HOME_PAGE_BACKGROUND', 'api_bk.jpg');
define('CACHE_DOMAIN', 'wrench.test');
+6 -5
View File
@@ -22,7 +22,7 @@ class Cache extends BaseConfig
*
* @var string
*/
public $handler = 'file';
public $handler = 'redis';
/**
* --------------------------------------------------------------------------
@@ -35,7 +35,7 @@ class Cache extends BaseConfig
*
* @var string
*/
public $backupHandler = 'dummy';
public $backupHandler = 'file';
/**
* --------------------------------------------------------------------------
@@ -153,11 +153,12 @@ class Cache extends BaseConfig
* @var array<string, int|string|null>
*/
public $redis = [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'host' => '10.0.0.32',
'password' => '7f079034e166ecf52d82cbec9876e4dc8a154b0c37248f3fa1734d4eeab938d5',
'port' => 6378,
'timeout' => 0,
'database' => 0,
'prefix' => 'WRB',
];
/**
+19
View File
@@ -77,6 +77,25 @@ class Database extends Config
'foreignKeys' => true,
];
public $wrench_blog = [
'DSN' => '',
'hostname' => '10.10.33.60',
'username' => 'float',
'password' => 'float.user',
'database' => 'float_blog',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
];
public function __construct()
{
parent::__construct();
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Controllers;
class WrenchApi extends BaseController
{
public function index()
{
$data['envID'] = getenv('ENV_ID');
$data['home_background'] = getenv('HOME_PAGE_BACKGROUND');
return view('welcome_message',$data);
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace App\Controllers;
//use CodeIgniter\API\ResponseTrait;
class WrenchBlog extends BaseController
{
//use ResponseTrait;
protected $db;
public $con_name = 'wrench_blog';
private function apiData() {
$this->db = \Config\Database::connect($this->con_name);
$data = array();
try {
$mysql = "SELECT id, post_title, post_content,post_date,comment_count FROM wp_posts WHERE post_type='post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 9";
$mysql = "SELECT p1.id AS id, p1.*, wm2.meta_value FROM wp_posts p1 LEFT JOIN wp_postmeta wm1
ON (wm1.post_id = p1.id AND wm1.meta_value IS NOT NULL AND wm1.meta_key = '_thumbnail_id' )
LEFT JOIN
wp_postmeta wm2
ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file' AND wm2.meta_value IS NOT NULL )
WHERE
p1.post_status='publish'
AND p1.post_type='post'
ORDER BY p1.post_date DESC LIMIT 2000";
$query = $this->db->query($mysql);
$data['payload']['blogdata'] = $query->getResult('array');
$totalCount = count( $data['payload']['blogdata'] );
$randomIndex = rand(1, $totalCount);
$data['payload']['featured'] = $data['payload']['blogdata'][$randomIndex ];
$data['payload']['image_url'] = 'https://blog.float.sg/wp-content/uploads/';
$data['payload']['blog_url'] = 'https://blog.float.sg/';
$data['payload']['total'] = $totalCount;
} catch (Exception $ex) {
}
return $data;
}
public function blogData($endpoint,$raw_array)
{
/*
$rawData = $this->apiData();
// $res1= $rawData[0]['payload'];
$res1= $rawData; //[0]['payload'];
$this->saveCache('blogdata',$res1['payload']);
*/
$res1 = $this->getCache($endpoint);
if (count($res1)==0){
$rawData = $this->apiData();
$res1= $rawData['payload']; //[0]['payload'];
$this->saveCache($endpoint,$res1);
}
//$resJson = $this->response->setJson($res1);
return $res1;
}
public function index()
{
}
}