webman/support/helpers.php
里面 測試時候?qū)憘€ 測試函數(shù)
我 Youfeed 豬頭三
在 functions 里將Cache 封成方法調(diào)用,set成功 get 返回 $redis
use support\Db;
use support\Redis;
use support\Cache;
/*
* Redis 緩存設(shè)置
* @$key,$val[]
*/
if(!function_exists('cache_set')){
function cache_set($key,$val,$second=10){
return Cache::set("cache-$key",$val,$second);
}
}
/*
* Redis 緩存獲取
* @$key
*/
if(!function_exists('cache_get')){
function cache_get($key){
return Cache::get("cache-$key");
}
}
控制器代碼 app/controller/IndexController.php
<?php
namespace app\controller;
use support\Request;
class ApiController
{
// 測試
public function test()
{
$set = cache_set('x','123456',60); // TRUE
$get = cache_get('x'); // $redis
return [$set,$get];
}
}
期望:cache_get('x'); 返回set的值
實際:cache_get('x'); 返回 "$redis"
確認(rèn)下 在輔助方法里面 是否可以調(diào)用 Cache::get
"require": {
"php": ">=7.2",
"workerman/webman-framework": "^1.4.7",
"monolog/monolog": "^2.0",
"psr/container": "^1.1.1",
"illuminate/database": "^8.83",
"illuminate/redis": "^8.2.0",
"illuminate/events": "^8.83",
"symfony/cache": "^5.2",
"webman/console": "^1.2.12"
},