| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- /**
- * Created by PhpStorm.
- * User: scstf
- * Date: 2018/9/14
- * Time: 13:01
- */
- namespace Biz\Db\Redis;
- // ini_set('display_errors', 1);
- // error_reporting(E_ALL);
- class RedisOP
- {
- private $_redis;
- public $expire;
- private $timeout = 15;
- public function __construct()
- {
- if (class_exists ('Redis')) {
- $redis = new \Redis();
- $config = include ROOT_PATH . '/Config/Redis.php';
- if (!isset($config['host'])) return null;//throw new \ErrorException('服务器不存在!');
- $host = $config['host'];
- $port = isset($config['port']) ? $config['port'] : 6379;
- try{
- $redis->connect ($host, $port, $this->timeout);// or die('连接失败!');
- }catch (\ErrorException $e)
- {
- $this->_redis = null;
- }
- if (isset($config['password'])) {
- $password = $config['password'];
- $redis->auth ($password);
- }
- $this->_redis = $redis;
- $this->expire = 300;
- } else {
- $this->_redis = null;
- }
- }
- function get()
- {
- return $this->_redis;
- }
- }
|