Skip to content

缓存组件redis使用长连接后,0号库读写存在问题 #3063

@sky66666666

Description

@sky66666666

所属功能组件

缓存(Cache)

ThinkPHP 版本

6.0

操作系统

Ubuntu

错误信息

cache.php配置如下

return [
    'default' => 'redis',
    'stores'    =>    [
        // 文件缓存
        'file'   =>  [
            // 驱动方式
            'type'   => 'file',
            // 设置不同的缓存保存目录
            'path'   => '../runtime/file/',
        ],
        // redis缓存
        'redis'   =>  [
            // 驱动方式
            'type'   => 'redis',
            // 服务器地址
            'host'       => 'xxx',
            'port'       => '6379',
            'password'       => '',
            'select'       => 1,
            'persistent' => true,
            'prefix'     => '',
            'serialize'  => true,
        ],
        'test00' => [
            'type'       => 'redis',
            'host'       => 'xxx',
            'port'       => 6379,
            'password'   => '',
            'select'     => 0,
            'timeout'    => 0,
            'expire'     => 0,
            'persistent' => true,
            'prefix'     => '',
            'serialize'  => true,
        ]
    ],
];

控制器代码如下:

public function test()
{
    \think\facade\Cache::store('test00')->set('test00', 'test00');
    return 'success';
}

执行控制器代码,此时test00这个key写在了1号库没有按照配置写入0号库
另外修改配置,将persistent都改成false这时候正常写入,又或者将源码中的if判断注释,强制进行select,,则能正常读写
微信截图_20240910152519

其它说明

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions