当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::pconnect方法代码示例

本文整理汇总了PHP中Redis::pconnect方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::pconnect方法的具体用法?PHP Redis::pconnect怎么用?PHP Redis::pconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::pconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: open

 /**
  * Establishes a DB connection.
  * It does nothing if a DB connection has already been established.
  * @return \Redis
  * @throws Exception if connection fails
  */
 public function open()
 {
     if ($this->_socket !== null) {
         return;
     }
     $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database;
     \Yii::trace('Opening redis DB connection: ' . $connection, __METHOD__);
     $this->_socket = new \Redis();
     if ($this->unixSocket) {
         if ($this->persist) {
             $this->_socket->pconnect($this->unixSocket, $this->port, $this->dataTimeout);
         } else {
             $this->_socket->connect($this->unixSocket, $this->port, $this->dataTimeout);
         }
     } else {
         if ($this->persist) {
             $this->_socket->pconnect($this->hostname, $this->port, $this->dataTimeout);
         } else {
             $this->_socket->connect($this->hostname, $this->port, $this->dataTimeout);
         }
     }
     if (isset($this->password)) {
         if ($this->_socket->auth($this->password) === false) {
             throw new Exception('Redis authentication failed!');
         }
     }
     $this->_socket->select($this->database);
     return $this->_socket;
 }
开发者ID:insolita,项目名称:yii2-redisman,代码行数:35,代码来源:PhpredisConnection.php

示例2: _connect

 /**
  * Connects to a Redis server
  *
  * @return bool True if Redis server was connected
  */
 protected function _connect()
 {
     try {
         $hash = "{$this->settings['server']}:{$this->settings['port']}:{$this->settings['database']}";
         if (!empty(self::$instances[$hash])) {
             $return = $this->_Redis = self::$instances[$hash];
         } else {
             $this->_Redis = new Redis();
             self::$instances[$hash] = $this->_Redis;
             if (!empty($this->settings['unix_socket'])) {
                 $return = $this->_Redis->connect($this->settings['unix_socket']);
             } elseif (empty($this->settings['persistent'])) {
                 $return = $this->_Redis->connect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
             } else {
                 $persistentId = $this->settings['port'] . $this->settings['timeout'] . $this->settings['database'];
                 $return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout'], $persistentId);
             }
         }
     } catch (RedisException $e) {
         $return = false;
     }
     if (!$return) {
         return false;
     }
     if ($this->settings['password'] && !$this->_Redis->auth($this->settings['password'])) {
         return false;
     }
     return $this->_Redis->select($this->settings['database']);
 }
开发者ID:solutudo,项目名称:cakephp,代码行数:34,代码来源:RedisEngine.php

示例3: factory

    /**
     * Returns the singleton instance of Redis. If no instance has
     * been created, a new instance will be created.
     *       
     *     $redis = Koredis::factory();
     *
     * @return Kohana_Koredis
     **/
    public static function factory()
    {
        if (!Kohana_Koredis::$redis) {
            // Make sure Redis installed
            if (!class_exists('Redis', FALSE)) {
                throw new Kohana_Exception('class Redis can not be found. make sure 
					you have installed phpredis extension');
            }
            Kohana_Koredis::$redis = new Redis();
            // No config file found
            if (!Kohana::$config->load('koredis')) {
                Kohana_Koredis::$redis->pconnect('127.0.0.1', 6379, 1);
            } else {
                // Load config
                $config = Kohana::$config->load('koredis');
                $host = isset($config['host']) && $config['host'] ? $config['host'] : '127.0.0.1';
                $port = isset($config['port']) && $config['port'] ? $config['port'] : 6379;
                $timeout = isset($config['timeout']) && $config['timeout'] ? $config['timeout'] : 1;
                $pconnect = isset($config['pconnect']) && $config['pconnect'] ? $config['pconnect'] : false;
                // Persistent connection
                if ($pconnect === TRUE) {
                    Kohana_Koredis::$redis->pconnect($host, $port, $timeout);
                } else {
                    Kohana_Koredis::$redis->connect($host, $port, $timeout);
                }
            }
        }
        return Kohana_Koredis::$redis;
    }
开发者ID:rucky2013,项目名称:kohana-php-admin,代码行数:37,代码来源:Koredis.php

示例4: getConnection

 /**
  * Return redis connection object
  *
  * @return  mixed  Redis connection object on success, void or boolean on failure
  *
  * @since   3.4
  *
  * @throws  RuntimeException
  */
 protected function getConnection()
 {
     if (static::isSupported() == false) {
         return false;
     }
     $config = JFactory::getConfig();
     $app = JFactory::getApplication();
     $caching = (bool) $config->get('caching');
     if ($caching == false) {
         return false;
     }
     $this->_persistent = $config->get('redis_persist', true);
     $server = array('host' => $config->get('redis_server_host', 'localhost'), 'port' => $config->get('redis_server_port', 6379), 'auth' => $config->get('redis_server_auth', null), 'db' => (int) $config->get('redis_server_db', null));
     static::$_redis = new Redis();
     if ($this->_persistent) {
         try {
             $connection = static::$_redis->pconnect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (Exception $e) {
         }
     } else {
         try {
             $connection = static::$_redis->connect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (Exception $e) {
         }
     }
     if ($connection == false) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis connection failed');
         }
         return;
     }
     if ($auth == false) {
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis authentication failed');
         }
         return;
     }
     $select = static::$_redis->select($server['db']);
     if ($select == false) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis failed to select database');
         }
         return;
     }
     try {
         static::$_redis->ping();
     } catch (RedisException $e) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis ping failed');
         }
         return;
     }
     return static::$_redis;
 }
开发者ID:klas,项目名称:joomla-cms,代码行数:68,代码来源:redis.php

示例5: autoInit

 /**
  * If you want to use your own instance of Redis then pass it to UaiCachePhpredis::$redis before calling UserAgentInfoPeer for the first time.
  */
 public static function autoInit()
 {
     if (self::$redis instanceof Redis) {
         return;
     }
     self::$redis = new Redis();
     self::$redis->pconnect('127.0.0.1');
     self::$redis->setOption(Redis::OPT_SERIALIZER, UserAgentInfoConfig::CACHE_USE_IGBINARY ? Redis::SERIALIZER_IGBINARY : Redis::SERIALIZER_PHP);
 }
开发者ID:razzbee,项目名称:UserAgentInfo,代码行数:12,代码来源:UaiCachePhpredis.class.php

示例6: addServer

 /**
  * {@inheritDoc}
  *
  * @link https://github.com/phpredis/phpredis#pconnect-popen
  */
 public function addServer($host, $port)
 {
     try {
         $this->_connection->pconnect($host, $port);
     } catch (\RedisException $e) {
         // TODO: since memcache/memcached adapters do not throw exceptions because
         // their connection are established lazily, this exception must unfortunately need to be swallowed
     }
 }
开发者ID:behance,项目名称:nbd.php-cache,代码行数:14,代码来源:RedisAdapter.php

示例7: __construct

 /**
  * @param $config
  * @throws TXException
  */
 private function __construct($config)
 {
     $this->handler = new Redis();
     if (isset($config['keep-alive']) && $config['keep-alive']) {
         $fd = $this->handler->pconnect($config['host'], $config['port'], TXConst::minute);
     } else {
         $fd = $this->handler->connect($config['host'], $config['port']);
     }
     if (!$fd) {
         throw new TXException(4005, array($config['host'], $config['port']));
     }
 }
开发者ID:billge1205,项目名称:biny,代码行数:16,代码来源:TXRedis.php

示例8: _connect

 protected function _connect()
 {
     $this->_redis = new \Redis();
     if ($this->_config['persistent']) {
         $this->_redis->pconnect($this->_config['host'], isset($this->_config['port']) ? $this->_config['port'] : null, isset($this->_config['timeout']) ? $this->_config['timeout'] : null);
     } else {
         $this->_redis->connect($this->_config['host'], isset($this->_config['port']) ? $this->_config['port'] : null, isset($this->_config['timeout']) ? $this->_config['timeout'] : null);
     }
     $this->_redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
     if ($this->_config['database'] > 0) {
         $this->_redis->select($this->_config['database']);
     }
 }
开发者ID:bjlzt,项目名称:EasyRedis,代码行数:13,代码来源:Manager.php

示例9: _connect

 /**
  * Connects to a Redis server
  *
  * @return boolean True if Redis server was connected
  */
 protected function _connect()
 {
     $return = false;
     try {
         $this->_Redis = new Redis();
         if (empty($this->settings['persistent'])) {
             $return = $this->_Redis->connect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
         } else {
             $return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
         }
     } catch (RedisException $e) {
         return false;
     }
     return $return;
 }
开发者ID:julkar9,项目名称:gss,代码行数:20,代码来源:RedisEngine.php

示例10: setupRedisConnection

 private function setupRedisConnection($config)
 {
     $this->redis = new \Redis();
     if (isset($config['host'])) {
         $host = $config['host'];
     } else {
         $host = 'localhost';
     }
     if (isset($config['port'])) {
         $port = $config['port'];
         $this->redis->pconnect($host, $port);
     } else {
         $this->redis->pconnect($host);
     }
 }
开发者ID:drealecs,项目名称:thread-worker,代码行数:15,代码来源:RedisQueue.php

示例11: __construct

 public function __construct($config)
 {
     if (!is_array($config) || array_key_exists('port', $config) && (!is_numeric($config['port']) || intval($config['port']) <= 0 || intval($config['port']) > 65535) || array_key_exists('index', $config) && (!is_numeric($config['index']) || intval($config['index']) < 0 || intval($config['index']) > 15) || array_key_exists('timeout', $config) && (!is_numeric($config['timeout']) || intval($config['timeout']) < 0)) {
         throw new \InvalidArgumentException();
     }
     $ip = array_key_exists('ip', $config) ? $config['ip'] : self::DEFAULT_IP;
     $retry = false;
     $oriConfig = $ip;
     if (is_array($ip)) {
         if (count($ip) > 1) {
             $retry = true;
         }
         $tmpIdx = array_rand($ip);
         $ip = $ip[$tmpIdx];
         unset($oriConfig[$tmpIdx]);
     }
     $port = array_key_exists('port', $config) ? intval($config['port']) : self::DEFAULT_PORT;
     $index = array_key_exists('index', $config) ? intval($config['index']) : self::DEFAULT_INDEX;
     $keepalive = array_key_exists('keepalive', $config) ? (bool) $config['keepalive'] : self::DEFAULT_KEEPALIVE;
     $timeout = array_key_exists('timeout', $config) ? doubleval($config['timeout']) / 1000 : self::DEFAULT_TIMEOUT;
     $instance = new \Redis();
     $connectSucceeded = false;
     if ($keepalive) {
         $connectSucceeded = $instance->pconnect($ip, $port, $timeout);
     } else {
         $connectSucceeded = $instance->connect($ip, $port, $timeout);
     }
     if (!$connectSucceeded || !$instance->select($index)) {
         if ($retry) {
             $tmpIdx = array_rand($oriConfig);
             $ip = $oriConfig[$tmpIdx];
             if ($keepalive) {
                 $connectSucceeded = $instance->pconnect($ip, $port, $timeout);
             } else {
                 $connectSucceeded = $instance->connect($ip, $port, $timeout);
             }
             if (!$connectSucceeded || !$instance->select($index)) {
                 self::logConnectionError($config);
                 throw new \RedisException();
             }
         } else {
             self::logConnectionError($config);
             throw new \RedisException();
         }
     }
     $this->redis = $instance;
     return;
 }
开发者ID:Whispersong,项目名称:phputils,代码行数:48,代码来源:redis.php

示例12: instance

 /**
  * redis 实例化
  * @param  $name	   连接那个redis
  * @param  $pconnect 是否进行长连接
  * @param  $ping     是否进行 ping 检测
  */
 public static function instance($name, $pconnect = false, $ping = false)
 {
     try {
         //检查是否可用
         if (self::ping($name, $ping)) {
             return self::$instanceObj[$name];
         }
     } catch (\RedisException $e) {
         self::$instanceObj[$name] = null;
     }
     //检查实例是否存在
     if (isset(self::$instanceObj[$name]) && self::$instanceObj[$name] instanceof \Redis) {
         return self::$instanceObj[$name];
     }
     $redisConf = self::getRedisConf($name);
     $host = $redisConf['host'];
     $port = $redisConf['port'];
     $redis = new \Redis();
     if ($pconnect) {
         $redis->pconnect($host, $port);
     } else {
         $redis->connect($host, $port);
     }
     if (isset($redisConf['dbIndex'])) {
         $redis->select(intval($redisConf['dbIndex']));
     }
     self::$instanceObj[$name] = $redis;
     return self::$instanceObj[$name];
 }
开发者ID:cygsxak,项目名称:my-message,代码行数:35,代码来源:RedisFactory.php

示例13: connect

 public function connect($config = array('host' => '127.0.0.1', 'port' => 6379), $is_master = true)
 {
     //default port
     if (!isset($config['port'])) {
         $config['port'] = 6379;
     }
     //设置master链接
     $redis = new Redis();
     if ($redis) {
         $ret = $redis->pconnect($config['host'], $config['port']);
         //选择库
         $redis->select(1);
         if ($is_master) {
             $this->_link_handle['master'] = $redis;
         } else {
             //多个slave链接
             $this->_link_handle['slave'][$this->_slave_sn] = $redis;
             ++$this->_slave_sn;
         }
         return $ret;
     } else {
         echo 'redis fail';
         return false;
     }
 }
开发者ID:lughong,项目名称:shop,代码行数:25,代码来源:RedisCluster_3.class.php

示例14: _connect

 /**
  * Connects to a Redis server
  *
  * @return bool True if Redis server was connected
  */
 protected function _connect()
 {
     try {
         $server = $this->_config['host'];
         if (empty($server) && !empty($this->_config['server'])) {
             $server = $this->_config['server'];
         }
         $this->_Redis = new \Redis();
         if (!empty($this->settings['unix_socket'])) {
             $return = $this->_Redis->connect($this->settings['unix_socket']);
         } elseif (empty($this->_config['persistent'])) {
             $return = $this->_Redis->connect($this->_config['server'], $this->_config['port'], $this->_config['timeout']);
         } else {
             $persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database'];
             $return = $this->_Redis->pconnect($this->_config['server'], $this->_config['port'], $this->_config['timeout'], $persistentId);
         }
     } catch (\RedisException $e) {
         return false;
     }
     if ($return && $this->_config['password']) {
         $return = $this->_Redis->auth($this->_config['password']);
     }
     if ($return) {
         $return = $this->_Redis->select($this->_config['database']);
     }
     return $return;
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:32,代码来源:RedisEngine.php

示例15: init

 /**
  * Retrieve Redis Cache Instance
  *
  * @return RedisCache|boolean
  */
 public function init()
 {
     $redis_cache = false;
     $config = $this->getServiceLocator()->get('Config');
     $config = $config['caches']['redis'];
     $namespace = $config['adapter']['options']['namespace'];
     $host = $config['adapter']['options']['server']['host'];
     $port = $config['adapter']['options']['server']['port'];
     $ttl = $config['adapter']['options']['ttl'];
     $redis = new \Redis();
     /**
      * This is not required, although it will allow to store anything that
      * can be serialized by PHP in Redis
      */
     try {
         $conn = $redis->pconnect($host, $port, $ttl);
         $redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
     } catch (\Exception $e) {
         $conn = false;
     }
     if ($conn) {
         $redis_cache = new RedisCache();
         $redis_cache->setNamespace($namespace);
         $redis_cache->setRedis($redis);
     }
     return $redis_cache;
 }
开发者ID:arstropica,项目名称:zf2-dashboard,代码行数:32,代码来源:DoctrineRedisCacheFactory.php


注:本文中的Redis::pconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。