切换 redis 连接

@param      $redis_name
@param null $select
962610
public static function userRedis($redis_name='', $select = null) {
        if(!$redis_name){
            $redis_name=CacheInterface::class;
        }
        CoContext::getContext()->set(CoContext::REDIS_NAME, $redis_name);
        if ($select) {
            CoContext::getContext()->set(CoContext::REDIS_SELECT, $select);
        }
    }
1302062
function loadScript(redis, script_name, script, callback) {
  redis.multi()
    .script('load', script)
    .exec(function (err, sha1) {
      if (err) {
        return callback(err);
      }
      shas[script_name] = sha1 && sha1.length && sha1[0];
      callback(null, sha1);
    });
}
114956
public static function getConfig($name)
    {
        if (self::$config_list === null) {
            self::init();
        }

        $name = strval($name);

        if (! isset(self::$config_list[$name])) {
            throw new \InvalidArgumentException("找不到连接名为'{$name}'的Redis配置！请检查配置项'database.redis'");
        }

        return self::$config_list[$name];
    }
353955
public static function redis() {
        $redisCache = self::getCache();
        if ($redisCache instanceof RedisCache) {
            $redisCache->open();
            return $redisCache->redis;
        }
        return null;
    }
1282516
public function selectPdo($select, $param = null)
    {
        if ($this->usePaginator === true) {
            return $this->initPaginator(array($select, $param));
        }
        $this->result = $this->tableGateway->selectPdo($select, $param);

        return $this->result;
    }
1302369
public function fetchAssoc(Select $select, AdapterInterface $specialAdapter = null)
    {
        $this->_logger->debug(sprintf('Executing query: %s', $select->assemble()));

        $result = ! is_null($specialAdapter) ? $specialAdapter->fetchAssoc($select) :
            $this->getDefaultConnection()->fetchAssoc($select);

        $this->_logger->debug(sprintf('Query result: %s', trim(print_r($result, true))));

        return $result;
    }
817664
public function updateSelectQuery($select)
    {
        $p = null;
        if (!empty($this->owner->relations)) {
            $p = $this->owner->table_alias ?: $this->owner->table;
        }

        if ($this->relation) {
            $select->field($this->actual_field ?: $this->short_name, $this->relation->short_name, $this->short_name);
        } elseif (!(is_null($this->actual_field)) && $this->actual_field != $this->short_name) {
            $select->field($this->actual_field, $p, $this->short_name);

            return $this;
        } else {
            $select->field($this->short_name, $p);
        }

        return $this;
    }
73797
public function plainSelect($name, $list = array(), $selected = null, $options = array())
    {
        return parent::select($name, $list, $selected, $options);
    }
1051868
public function selectOne(Select $select, ResultSet\ResultSetInterface $resultSet = null)
    {
        $select->limit(1);
        //var_dump($select->getSqlString()); die();
        return $this->select($select, $resultSet)->current();
    }
198315
function(options){
  var _this = this;

  this.handlers = {};

  if(!options){
    options = {};
  }

  if(!options.redis){
    options.redis = {};
  }

  this.options = {
    id: options.id || shortId.generate(),
    autoConfig: options.autoConfig ||  false,
    dataExpiry: options.dataExpiry || 30,
    redis: {
      port: options.redis.port || 6379,
      host: options.redis.host || '127.0.0.1',
      redis: options.redis.options || {}
    }
  };

  //Create redis clients
  this.redisSub = redis.createClient(this.options.redis.port, this.options.redis.host, this.options.redis.options);
  this.redis = redis.createClient(this.options.redis.port, this.options.redis.host, this.options.redis.options);
  this.redisInstant = redis.createClient(this.options.redis.port, this.options.redis.host, this.options.redis.options);

  //Attempt auto config
  if(this.options.autoConfig){
    var config = '';
    this.redis.config("GET", "notify-keyspace-events", function(err, data){
      if(data){
        config = data[1];
      }
      if(config.indexOf('E') == -1){
        config += 'E'
      }
      if(config.indexOf('x') == -1){
        config += 'x'
      }
      _this.redis.config("SET", "notify-keyspace-events", config)
    });
  }

  //Listen to key expiry notifications and handle events
  var expiryListener = new RedisEvent(this.redisSub, 'expired', /redular:(.+):(.+):(.+)/);
  expiryListener.defineHandler(function(key){
    var clientId = key[1];
    var eventName = key[2];
    var eventId = key[3];

    _this.redis.get('redular-data:' + clientId + ':' + eventName + ':' + eventId, function(err, data){
      if(data){
        data = JSON.parse(data);
      }
      if(clientId == _this.options.id || clientId == 'global'){
        _this.handleEvent(eventName, data);
      }
    });
  });

  //Listen to instant events and handle them
  this.redisInstant.subscribe('redular:instant');
  this.redisInstant.on('message', function(channel, message){
    try{
      var parsedMessage = JSON.parse(message);
    } catch (e){
      throw e;
    }
    if(parsedMessage.client == _this.options.id || parsedMessage.client == 'global') {
      _this.handleEvent(parsedMessage.event, parsedMessage.data);
    }
  });

}
774743
public function select($select = 'ROWID,*')
    {
        //Argument 1 must be a string or array
        Argument::i()->test(1, 'string', 'array');
        
        return \Eden\Sql\Select::i($select);
    }
115831
private function selectDatabase($database)
    {
        if (!is_integer($database) || $database < 0) {
            throw new RedisConnectionException(
                "Can't select database '{$database}'. Should be a natural number."
            );
        }
        $this->connection->select($database);
    }
347056
protected function _order(Zend_Db_Table_Select $select, $order)
    {
        if (!is_array($order)) {
            $order = array($order);
        }

        foreach ($order as $val) {
            $select->order($val);
        }

        return $select;
    }
1213919
private function connection__redis() {
		$this->connection = new \Redis();
		# @note: This emits warning on failure instead of throwing
		# exception, hence the @ sign.
		if (!@$this->connection->connect(
			$this->redishost, $this->redisport,
			$this->redistimeout
		))
			// @codeCoverageIgnoreStart
			return $this->connection_open_fail();
			// @codeCoverageIgnoreEnd
		if ($this->redispassword || $this->redisdatabase) {
			try {
				if ($this->redispassword)
					$this->connection->auth($this->redispassword);
				if ($this->redisdatabase)
					$this->connection->select($this->redisdatabase);
			} catch(\RedisException $e) {
				return $this->connection_open_fail($e->getMessage());
			}
		}
		try {
			$this->connection->ping();
		} catch(\RedisException $e) {
			return $this->connection_open_fail($e->getMessage());
		}
		return $this->connection_open_ok();
	}
182412
public function setRedis(\Redis $redis)
    {
        $redis->setOption(Redis::OPT_SERIALIZER, $this->getSerializerValue());
        $this->_redis = $redis;
    }
701147
public function multiselect(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [])
    {
        return $this->select($name, $options, $selected, $_attributes, true);
    }
973372
function initRedis(config, callback) {

  var self = this;

  protos.util.checkLocalPort(config.port, function(err) {

    if (err) {
      app.log("RedisTransport [%s:%s] %s", config.host, config.port, err.code);
    } else {

      // Set redis client
      self.client = redis.createClient(config.port, config.host, self.options);

      // Handle error event
      self.client.on('error', function(err) {
        callback.call(self, err);
      });

      // Authenticate if password provided
      if (typeof config.password == 'string') {
        self.client.auth(config.password, function(err, res) {
          if (err) {
            app.log("RedisTransport: [%s:%s] %s", config.host, config.port, err.code);
          } else if (typeof config.db == 'number' && config.db !== 0) {
            self.client.select(config.db, function(err, res) {
              if (err) callback.call(self, err);
              else callback.call(self, null);
            });
          } else {
            callback.call(self, null);
          }
        });
      } else if (typeof config.db == 'number' && config.db !== 0) {
        self.client.select(config.db, function(err, res) {
          callback.call(self, err);
        });
      } else {
        callback.call(self, null);
      }

    }
  });

}