/** * connect to redis server * * @param string $host * @param int $port * @return object */ public static function connect($index = 'user', $host = null, $port = null) { //----------------------------octopus update 2014-01-03---------------------------------- //根据业务,把redis拆分成两部分,user 和 card // if (!isset(self::$_dbIndex[$index])) { // throw new Exception('DB index not found.'); // } //$db = self::$_dbIndex[$index]; if (!extension_loaded('redis')) { throw new Exception('Redis extension not found.'); } $redisConfig = TZ_Loader::config('redis'); if (empty($redisConfig)) { throw new Exception('Reids Configuration error.'); } $redis = new Redis(); $host = null === $host ? $redisConfig[$index]['host'] : $host; $port = null === $port ? $redisConfig[$index]['port'] : $port; $connection = $redis->connect($host, $port); if (!$connection) { throw new Exception('Can\'t connect to Redis server.'); } //$redis->select($db); //-----------------------------------end --------------------------------------------------- return $redis; }
/** * get relation cache * * @param string $telephone * @param array $fields * @return string */ private function _getCacheByTelephone($telephone, $fields = array()) { $memcacheConfig = TZ_Loader::config('memcache'); $host = $memcacheConfig['user']['host']; $port = $memcacheConfig['user']['port']; $cache = new HM_Memcached($host, $port); $uid = $cache->get($this->_telephonePreKey . $telephone); return $uid ? $this->_getCacheByUid($uid, $fields) : false; }