yf_queue_driver_redis class

Fileplugins/queue/classes/queue/yf_queue_driver_redis.class.php
Use_class('queue_driver_redis', 'classes/queue/')
Extendsyf_queue_driver

Public properties

A site sets them in its config with $PROJECT_CONF['queue_driver_redis']['NAME'] = ...;

PropertyDefaultDescription
$_connection null

Public methods 9

add

public function add($queue, $what)
    public function add($queue, $what)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->lpush($queue, $what);
    }

all

public function all($queue)
    public function all($queue)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->lrange($queue, 0, -1);
    }

conf

public function conf($params = [])
    public function conf($params = [])
    {
        ! $this->_connection && $this->connect();
        $this->_connection->conf($params);
        return $this;
    }

connect

public function connect($options = [])
    public function connect($options = [])
    {
        if ( ! $this->_connection) {
            if ( ! $options) {
                $options = [
                    'REDIS_HOST' => $this->_get_conf('REDIS_QUEUE_HOST'),
                    'REDIS_PORT' => $this->_get_conf('REDIS_QUEUE_PORT'),
                    'REDIS_PREFIX' => $this->_get_conf('REDIS_QUEUE_PREFIX'),
                ];
            }
            $this->_connection = redis()->factory($options);
            $this->_connection->connect();
        }
        if ( ! $this->_connection->is_connection()) {
            $this->reconnect();
        }
        return $this->_connection;
    }

del

public function del($queue)
    public function del($queue)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->lrem($queue, 1);
    }

get

public function get($queue)
    public function get($queue)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->rpop($queue);
    }

is_ready

public function is_ready()
    public function is_ready()
    {
        ! $this->_connection && $this->connect();
        return (bool) $this->_connection;
    }

reconnect

public function reconnect()
    public function reconnect()
    {
        $this->_connection && $this->_connection->reconnect();
    }

Methods starting with _ hooks and helpers; not routable as page actions

_get_conf

public function _get_conf($name, $default = null, array $params = [])
  • $params array
    public function _get_conf($name, $default = null, array $params = [])
    {
        if (isset($params[$name])) {
            return $params[$name];
        }
        $from_env = getenv($name);
        if ($from_env !== false) {
            return $from_env;
        }
        global $CONF;
        if (isset($CONF[$name])) {
            $from_conf = $CONF[$name];
            return $from_conf;
        }
        if (defined($name) && ($val = constant($name)) != $name) {
            return $val;
        }
        return $default;
    }

Inherited methods

from yf_queue_driver: __call()