webman Cache 返回错误

youfeed

出现BUG原因

webman/support/helpers.php
里面 测试时候写个 测试函数

我 Youfeed 猪头三

bug描述

在 functions 里将Cache 封成方法调用,set成功 get 返回 $redis

辅助函数 app/functions.php

use support\Db;
use support\Redis;
use support\Cache;

/*
* Redis 缓存设置
* @$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"

确认下 在辅助方法里面 是否可以调用 Cache::get

composer.json

"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"
  },
669 2 0
2个回答

yzh52521

测试没问题

喵了个咪

估计是开启了redis事务吧

年代过于久远,无法发表回答
🔝