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


PHP Redis::connect方法代码示例

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


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

示例1: getAdapter

 /**
  * {@inheritdoc}
  */
 public function getAdapter(array $config)
 {
     $client = new \Redis();
     $dsn = $this->getDsn();
     if (empty($dsn)) {
         if (false === $client->connect($config['host'], $config['port'])) {
             throw new ConnectException(sprintf('Could not connect to Redis database on "%s:%s".', $config['host'], $config['port']));
         }
     } else {
         if (false === $client->connect($dsn->getFirstHost(), $dsn->getFirstPort())) {
             throw new ConnectException(sprintf('Could not connect to Redis database on "%s:%s".', $dsn->getFirstHost(), $dsn->getFirstPort()));
         }
         if (!empty($dsn->getPassword())) {
             if (false === $client->auth($dsn->getPassword())) {
                 throw new ConnectException('Could not connect authenticate connection to Redis database.');
             }
         }
         if ($dsn->getDatabase() !== null) {
             if (false === $client->select($dsn->getDatabase())) {
                 throw new ConnectException(sprintf('Could not select Redis database with index "%s".', $dsn->getDatabase()));
             }
         }
     }
     $pool = new RedisCachePool($client);
     if (null !== $config['pool_namespace']) {
         $pool = new NamespacedCachePool($pool, $config['pool_namespace']);
     }
     return $pool;
 }
开发者ID:php-cache,项目名称:adapter-bundle,代码行数:32,代码来源:RedisFactory.php

示例2: 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

示例3: __construct

 /**
  * Constructor.
  *
  * @param string $uniqId to be used to separate objects in addition to their key identifiers, for instance in a
  * multi-user scenario.
  *
  * @return \iveeCrest\RedisWrapper
  */
 public function __construct($uniqId)
 {
     $this->redis = new \Redis();
     $this->redis->connect(Config::getCacheHost(), Config::getCachePort());
     $this->redis->setOption(\Redis::OPT_PREFIX, Config::getCachePrefix());
     $this->uniqId = $uniqId;
 }
开发者ID:plugh3,项目名称:eve-trade1-perl,代码行数:15,代码来源:RedisWrapper.php

示例4: __construct

 public function __construct()
 {
     $this->redis = new \Redis();
     if (!$this->redis->connect('127.0.0.1', 10000, 3)) {
         exit('redis connect failed');
     }
 }
开发者ID:sinopex,项目名称:self-learning-project,代码行数:7,代码来源:Suggest.php

示例5: _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

示例6: _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

示例7: connectToServer

 /**
  * @param ProvidesConnectionData $connectionData
  *
  * @throws CannotConnectToServer
  */
 private function connectToServer(ProvidesConnectionData $connectionData)
 {
     $connected = $this->redis->connect($connectionData->getHost(), $connectionData->getPort(), $connectionData->getTimeout(), null, $connectionData->getRetryInterval());
     if (!$connected) {
         throw (new CannotConnectToServer())->withConnectionData($connectionData);
     }
 }
开发者ID:hollodotme,项目名称:readis,代码行数:12,代码来源:ServerManager.php

示例8: __construct

 public function __construct($redis = FALSE, $opts = array())
 {
     if (is_array($redis)) {
         $opts = $redis;
         $redis = FALSE;
     }
     // Apply default arguments
     $opts = array_merge(array('host' => 'localhost', 'port' => 6379), $opts);
     if (!$redis) {
         // Default to phpredis
         if (extension_loaded('redis')) {
             if (!isset($opts['socket']) && !isset($opts['host'])) {
                 throw new \Exception('Host should be provided when not providing a redis instance');
             }
             if (!isset($opts['socket']) && !isset($opts['port'])) {
                 throw new \Exception('Port should be provided when not providing a redis instance');
             }
             $redis = new \Redis();
             if (isset($opts['socket'])) {
                 $redis->connect($opts['socket']);
             } else {
                 $redis->connect($opts['host'], $opts['port']);
             }
         } else {
             $redis = new \TinyRedisClient($opts['host'] . ':' . $opts['port']);
         }
     }
     if (!is_callable(array($redis, 'publish'))) {
         throw new \Exception('The Redis client provided is invalid. The client needs to implement the publish method. Try using the default client.');
     }
     $this->redis = $redis;
     $this->key = (isset($opts['key']) ? $opts['key'] : 'socket.io') . '#/#';
     $this->_rooms = array();
     $this->_flags = array();
 }
开发者ID:anton-github,项目名称:socket.io-php-emitter,代码行数:35,代码来源:Emitter.php

示例9: __construct

 /**
  * @param \Redis $redis
  */
 public function __construct()
 {
     $this->redis = new \Redis();
     $this->redis->connect('127.0.0.1', '6379');
     $this->emitter = new Emitter($this->redis);
     $this->user = new Emitter($this->redis);
 }
开发者ID:Symfomany,项目名称:papsymfony,代码行数:10,代码来源:Notification.php

示例10: class_init

 public static function class_init()
 {
     /** @var Settings $settings */
     $settings = resource(Settings::class);
     self::$redis = new \Redis();
     self::$redis->connect($settings->get("redis", "hostname"), $settings->get("redis", "connect_port"));
 }
开发者ID:pldin601,项目名称:HomeMusic,代码行数:7,代码来源:RedisBackend.php

示例11: init

 public function init()
 {
     $this->_redis = new \Redis();
     if (!$this->_redis->connect($this->host, $this->port)) {
         throw new InvalidConfigException("The redis host '{$this->host}' error.");
     }
 }
开发者ID:kerisy,项目名称:framework,代码行数:7,代码来源:RedisStorage.php

示例12: __construct

 /** 
  * Constructor
  *
  * This is the constructor. The options passed can be the
  * ip of the server, or an array of servers and their port.
  *
  * Example:
  * <code>
  *
  *     $options = array(
  *         'hostname' => '127.0.0.1',
  *         'port'     => 6666
  *     ); 
  *
  *     $cache   = Frapi_Cache_Adapter_Redis($options);
  * </code>
  *
  * @param array $options an array of options
  * @return void
  */
 public function __construct(array $options)
 {
     $this->redis = new Redis();
     $defaults = array('hostname' => '127.0.0.1', 'port' => 6379);
     $options += $defaults;
     $this->redis->connect($options['hostname'], $options['port']);
 }
开发者ID:jeremykendall,项目名称:frapi,代码行数:27,代码来源:Redis.php

示例13: __construct

 public function __construct($prefix = '')
 {
     parent::__construct($prefix);
     if (is_null(self::$cache)) {
         // TODO allow configuring a RedisArray, see https://github.com/nicolasff/phpredis/blob/master/arrays.markdown#redis-arrays
         self::$cache = new \Redis();
         $config = \OC::$server->getSystemConfig()->getValue('redis', array());
         if (isset($config['host'])) {
             $host = $config['host'];
         } else {
             $host = '127.0.0.1';
         }
         if (isset($config['port'])) {
             $port = $config['port'];
         } else {
             $port = 6379;
         }
         if (isset($config['timeout'])) {
             $timeout = $config['timeout'];
         } else {
             $timeout = 0.0;
             // unlimited
         }
         self::$cache->connect($host, $port, $timeout);
     }
 }
开发者ID:adolfo2103,项目名称:hcloudfilem,代码行数:26,代码来源:redis.php

示例14: setUp

 public function setUp()
 {
     $this->redis = new Redis();
     $this->redis->connect('127.0.0.1', 6379);
     // uncomment the following if you want to use authentication
     // $this->assertTrue($this->redis->auth('foobared'));
 }
开发者ID:virtulis,项目名称:phpredis,代码行数:7,代码来源:TestRedis.php

示例15: __construct

 /**
  * @param string $host redis server host
  * @param int $port redis server port
  * @param int $database redis server database num
  * @param string $channel redis queue key
  * @param string $prefix 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');
     }
 }
开发者ID:huyanping,项目名称:simple-fork-php,代码行数:32,代码来源:RedisQueue.php


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