1.连接函数
/**
* Connects to a Redis instance.
*
* @param string $host can be a host, or the path to a unix domain socket
* @param int $port optional
* @param float $timeout value in seconds (optional, default is 0.0 meaning unlimited)
* @param null $reserved should be null if $retry_interval is specified
* @param int $retry_interval retry interval in milliseconds.
* @return bool TRUE on success, FALSE on error.
*/
public function connect( $host, $port = 6379, $timeout = 0.0, $reserved = null, $retry_interval = 0 ) {}
2.默认端口连接
<?php
namespace app\index\controller;
use Redis;
class Index
{
public function index()
{
$redis = new Redis();
$con = $redis->connect('127.0.0.1');
var_dump($con);//bool(true)
}
}
3.端口连接(默认端口6379)
<?php
namespace app\index\controller;
use Redis;
class Index
{
public function index()
{
$redis = new Redis();
$con = $redis->connect('127.0.0.1',6379);
var_dump($con);//bool(true)
}
}
4.超时放弃连接
<?php
namespace app\index\controller;
use Redis;
class Index
{
public function index()
{
$redis = new Redis();
//默认为0,即连接没有限制,此处为短连接,超过3秒放弃连接
$con = $redis->connect('127.0.0.1',6379,3);
var_dump($con);//bool(true)
}
}
备注:open()用法同connect()