lihaotian/think-redis

There is no license information available for the latest version (v1.0.2) of this package.

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.0.2 2019-08-05 07:07 UTC

This package is not auto-updated.

Last update: 2021-01-28 17:39:36 UTC


README

默认连接的为redis2.conf 配置文件中的 default 的库

$config = [
    'default' => [
        'host' => '127.0.0.1',
        'select' => 5
    ],
    'read' => [
        'host' => '127.0.0.3',
        'select' => 6
    ],
    'save' => [
        'host' => '127.0.0.2',
        'select' => 10
    ]
];

使用方法: 在任何需要使用的类库 use GetRedis 即可

<?php

namespace app\index\controller;

use lee\redis\GetRedis;
use think\Controller;

class Data extends Controller
{
    use GetRedis;

    public function index()
    {
        # 往写库里面写入数据
        $this->redis('save')->hSet('user', '1', ['id' => 1, 'name' => 'test']);

        # 从读库里面读取数据
        $data = $this->redis('save')->hGet('user', '1');

        var_dump($data);
        
        # 销毁save库的连接
        $this->destroyRedis('user');

        # 销毁所有库的连接
        $this->destroyRedis();
    }
}