TP5使用predis

1、安装

composer require predis/predis

2、使用

use ...;
use Predis\Client;
-----------------------------------------------
class Index
{
    /*
     * 使用predis
     */
    public function index()
    {
    //配置连接的IP、端口、以及相应的数据库
        $server = array(
            'host' => '192.168.0.1',//IP
            'port' => 6379,         //端口
            'database' => 15,       
            'password' => '******'  //密码
        );
        $redis = new Client($server);

    //普通set/get操作
        $redis->set('library', 'Predis');
        $retval = $redis->get('library');
        echo $retval;  //显示 'predis'
    }

效果:TP5使用predis_第1张图片

你可能感兴趣的:(Thinkphp)