Laravel检查是否存在缓存标记

时间:2018-01-05 19:10:20

标签: php laravel caching redis

我想检查是否存在laravel缓存标记。我怎么能这样做。

这是如何获取缓存项,但如何验证缓存标记是否存在。

$john = Cache::tags(['people', 'artists'])->get('John');

$anne = Cache::tags(['people', 'authors'])->get('Anne');

2 个答案:

答案 0 :(得分:0)

如果 $ john 为false,则为null或''它不会传递if语句

if ($john) {
    // It has valid data
}

或者您可以使用以下方法检查空对象/集合:

$john->isEmpty();

你也可以使用:

检查count()方法
if ($jhon->count()) {
    // do something
}

答案 1 :(得分:0)

我知道这是一个较旧的问题,但是您可以这样做:

Cache::tags(['people', 'artists'])->has('John');

这将检查人物或艺术家标签中是否存在John的密钥。

相关问题