Redis updates

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-09 13:36:51 -04:00
parent b66a233d6b
commit a4a0345055
4 changed files with 58 additions and 18 deletions
+44 -11
View File
@@ -5,12 +5,15 @@ namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Cache\CacheInterface;
class FloatWeb extends BaseController
{
use ResponseTrait;
protected $db;
public $con_name = 'float_blog';
private function apiData() {
$this->db = \Config\Database::connect($this->con_name);
@@ -520,23 +523,53 @@ variations from the norm, and in addition other reproductive organ issue
public function blogData()
{
$rawData = $this->apiData();
$res1= $rawData[0]['payload'];
// var_dump($res1);
return $this->response->setJson($res1);
// $res1= $rawData[0]['payload'];
$res1= $rawData; //[0]['payload'];
$this->runCache('blogdata',$res1['payload']);
$resJson = $this->response->setJson($res1);
return $resJson;
}
private function runCache($cacheKey,$data){
$cache = \Config\Services::cache();
if (! $foo = cache($cacheKey)) {
echo 'Saving to the cache!<br>';
cache()->save($cacheKey, $this->data_stringify($data), 3000);
}
// $foo = $cache->get('foo');
}
private function data_stringify($data) {
switch (gettype($data)) {
case 'string' : return '\''.addcslashes($data, "'\\").'\'';
case 'boolean': return $data ? 'true' : 'false';
case 'NULL' : return 'null';
case 'object' :
case 'array' :
$expressions = [];
foreach ($data as $c_key => $c_value) {
$expressions[] = $this->data_stringify($c_key).' => '.
$this->data_stringify($c_value);
}
return gettype($data) === 'object' ?
'(object)['.implode(', ', $expressions).']' :
'['.implode(', ', $expressions).']';
default: return (string)$data;
}
}
public function index()
{
$rawData = $this->apiData();
// $res1= $rawData[0]['payload'];
$res1= $rawData; //['payload'];
// $rawData = $this->apiData();
// // $res1= $rawData[0]['payload'];
// $res1= $rawData; //['payload'];
//
// // var_dump($res1);
//
// return $this->response->setJson($res1);
// $cache = \Config\Services::cache();
// var_dump($res1);
// $foo = $cache->get('foo');
return $this->response->setJson($res1);
}