webman为什么Redis 和 Cache默认保存到了同一个redis空间中,如果自动分配redis空间?

Leoba

问题描述

1、config/redis.php 配置如下:

 return [
    'default' => [
        'host'     => '127.0.0.1',
        'password' => null,
        'port'     => 6379,
        'database' => 10,
    ],

    'cache' => [
        'host'     => '127.0.0.1',
        'password' => null,
        'port'     => 6379,
        'database' => 0,
    ],

];

2、业务操作如下:

<?php
namespace app\controller;

use support\Request;
use support\Cache;
use support\Redis;

class TestcacheController
{
    public function index(Request $request)
    {
        Cache::set('aaaa','cache_v');
        Redis::set('aaaa',time());
    }
}

3、结果被存到了同一空间中,且只有一套数据,redis覆盖了cache数据
截图

368 3 0
3个回答

yzh52521

多看看手册

Redis::connection('cache');
  • Leoba 2023-08-29

    刚刚准备补充,你这样的确可以,那Redis::connection('cache');相当于等价于Cache::connection('cache'); 那几乎引用support\Cache已经没有意义了

efnic

缓存 和 缓存驱动,不能混为一谈;
缓存实现\Symfony\Component\Cache\Psr16Cache 接口。

  • 暂无评论
小W

https://symfony.com/doc/current/components/cache.html

其实也可以直接用redis组件

  • 暂无评论
🔝