public function __construct($config) { $redis = new \redis(); if (isset($config['PCONNECT'])) { $redis->pconnect($config['HOST'], $config['PORT'], $config['TIMEOUT']); } else { $redis->connect($config['HOST'], $config['PORT'], $config['TIMEOUT']); } $redis->setOption(\redis::OPT_SERIALIZER, \redis::SERIALIZER_NONE); $redis->select($config['DB']); $this->redis = $redis; self::$config = $config; }
/** * Construct * * Do not use this directly. You can use getInstance() instead. * @param string $url url of Redis * @return void */ function __construct($url) { //$config['url'] = 'redis://localhost:6379/1'; $config['url'] = is_array($url) ? reset($url) : $url; if (!class_exists('Redis')) { return $this->status = false; } try { $this->redis = new Redis(); $info = parse_url($url); $this->redis->connect($info['host'], $info['port'], 0.15); if (isset($info['user']) || isset($info['pass'])) { $this->redis->auth(isset($info['user']) ? $info['user'] : $info['pass']); } if (isset($info['path']) && ($dbnum = intval(substr($info['path'], 1)))) { $this->redis->select($dbnum); } return $this->status = true; } catch (RedisException $e) { return $this->status = false; } }
protected function __construct() { $this->_redis = $this->connect(); $this->_redis->select(intval($this->_db)); }
function connectRedis($host, $port, $db = 0, $pwd = None) { $r = new redis(); $r->connect($host, $port); $r->select($db); if ($pwd) { $r->auth($pwd); } return $r; }