yf_pubsub_driver_redis class

Fileplugins/pubsub/classes/pubsub/yf_pubsub_driver_redis.class.php
Use_class('pubsub_driver_redis', 'classes/pubsub/')
Extendsyf_pubsub_driver

Public properties

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

PropertyDefaultDescription
$_connection null
$_connection_pub null
$_connection_sub null
$_is_connection null

Public methods 10

conf

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

connect

public function connect($options = [])
    public function connect($options = [])
    {
        if ( ! $this->_is_connection) {
            if ( ! $options) {
                $options = [
                    'REDIS_HOST' => $this->_get_conf('REDIS_PUBSUB_HOST'),
                    'REDIS_PORT' => $this->_get_conf('REDIS_PUBSUB_PORT'),
                    'REDIS_PREFIX' => $this->_get_conf('REDIS_PUBSUB_PREFIX'),
                ];
            }
            $this->_connection_pub = redis()->factory($options);
            $options['is_new'] = true;
            $this->_connection_sub = redis()->factory($options);
            $this->_is_connection = true;
        }
        if ( ! $this->_connection_pub->is_connection()) {
            $this->reconnect_pub();
        }
        if ( ! $this->_connection_sub->is_connection()) {
            $this->reconnect_sub();
        }
        return $this->_is_connection;
    }

is_ready

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

pub

public function pub($channel, $what)
    public function pub($channel, $what)
    {
        ! $this->_is_connection && $this->connect();
        return $this->_connection_pub->pub($channel, $what);
    }

pub_conf

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

reconnect_pub

public function reconnect_pub()
    public function reconnect_pub()
    {
        $this->_connection_pub->reconnect();
    }

reconnect_sub

public function reconnect_sub()
    public function reconnect_sub()
    {
        $this->_connection_sub->reconnect();
    }

sub

public function sub($channels, $callback)
    public function sub($channels, $callback)
    {
        ! $this->_is_connection && $this->connect();
        return $this->_connection_sub->sub($channels, $callback);
    }

sub_conf

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

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_pubsub_driver: __call()