Jenner\SimpleFork\Queue\RedisQueue::__construct PHP Method

__construct() public method

public __construct ( string $host = '127.0.0.1', integer $port = 6379, integer $database, string $channel = 'cache', string $prefix = 'simple-fork-' )
$host string redis server host
$port integer redis server port
$database integer redis server database num
$channel string redis queue key
$prefix string prefix of redis queue key
    public function __construct($host = '127.0.0.1', $port = 6379, $database = 0, $channel = 'cache', $prefix = 'simple-fork-')
    {
        $this->redis = new \Redis();
        $connection_result = $this->redis->connect($host, $port);
        if (!$connection_result) {
            throw new \RuntimeException('can not connect to the redis server');
        }
        if ($database != 0) {
            $select_result = $this->redis->select($database);
            if (!$select_result) {
                throw new \RuntimeException('can not select the database');
            }
        }
        if (empty($channel)) {
            throw new \InvalidArgumentException('channel can not be empty');
        }
        $this->channel = $channel;
        if (empty($prefix)) {
            return;
        }
        $set_option_result = $this->redis->setOption(\Redis::OPT_PREFIX, $prefix);
        if (!$set_option_result) {
            throw new \RuntimeException('can not set the \\Redis::OPT_PREFIX Option');
        }
    }