首页 > 其他 > 详细

TP5连接redis

时间:2021-05-20 15:13:56      阅读:21      评论:0      收藏:0      [点我收藏+]
$arrConfig = Config::get(‘redis.default‘);
$objRedis = new \Redis();
if(!$arrConfig[‘pconnect‘])
    $objRedis->connect($arrConfig[‘hostname‘], $arrConfig[‘port‘],$arrConfig[‘timeout‘]);
else
    $objRedis->pconnect($arrConfig[‘hostname‘], $arrConfig[‘port‘],$arrConfig[‘timeout‘]);
$objRedis->auth($arrConfig[‘auth‘]);
if(!$objRedis) parent::returnCode(1999,‘数据库连接失败!‘);
return $objRedis;

##config.php
/*redis链接*/
    ‘redis‘ => [
        ‘default‘ => [
            ‘type‘ => ‘redis‘,
            ‘debug‘ => true,
            ‘hostname‘ => ‘127.0.0.1‘,
            ‘port‘ => 6379,
            ‘auth‘ => ‘‘,
            ‘timeout‘ => 3,//单位秒
            ‘pconnect‘ => 0,
            ‘autoconnect‘ => 0
        ]
    ],
```php

TP5连接redis

原文:https://www.cnblogs.com/ljkltt/p/14789044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!