123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\api\actions;
- use think\facade\Cache;
- trait ZskkCache
- {
- protected $redis_name = 'db_config_private';
- public function getCache($key, $default = false ,$time = 86400) {
- $value = false;
- try {
- // $value = Cache::store($this->redis_name)->get($key);
- if($value !== false) {
- if(strpos($key,'TOKEN_WXA_') === 0){
- $value = json_decode(json_decode($value),true);
- }
- return $value;
- }
- $val = Cache::get($key);
- if($val !== false) {
- return $val;
- }
- return $default;
- } catch(\Exception $e) {
- }
- return $default;
- }
- public function setCache($key, $value, $time = 86400) {
- $res2 = false;
- try {
- // $res2 = Cache::store($this->redis_name)->set($key, $value, $time);
- if($res2 == false){
- $res = Cache::set($key, $value, $time);
- if($res !== false){
- return $res;
- }
- }
- } catch(\Exception $e) {
- }
- return $res2;
- }
- public function delCache($key)
- {
- $info = false;
- // $info = Cache::store($this->redis_name)->rm($key);
- if(!$info){
- $data = Cache::rm($key);
- if($data){
- return $data;
- }
- }
- return $info;
- }
- public function updateCache($key,$value)
- {
- $info = false;
- // if( Cache::store($this->redis_name)->get($key)){
- // $data = Cache::store($this->redis_name)->rm($key);
- // $info = Cache::store($this->redis_name)->set($key,$value,86400);
- // }
- if(Cache::get($key)){
- $data = Cache::rm($key);
- $info = Cache::set($key,$value,86400);
- }
- return $info;
- }
- }
|