public function __construct($config) { // 读取配置文件 $this->config = $config; // 检测配置文件 if ($this->checkConfigure()) { return Console::error(get_class($this) . ' [ ', $k, ' ] configure must'); } // 连接缓存 $this->connect(); }
/** * 连接 * @return [type] [description] */ public function connect() { // 判断是否存在redis if (!class_exists('swoole_table')) { return Console::error("Class swoole_table not exists"); } $this->cache_object = new \swoole_table($this->config['dbsize']); $this->cache_object->column('time', \swoole_table::TYPE_INT, 4); //1,2,4,8 $this->cache_object->column('data', \swoole_table::TYPE_STRING, 65535); $this->cache_object->create(); }
/** * 连接 * @return [type] [description] */ public function connect() { // 判断是否存在redis if (!class_exists('Redis')) { return Console::error("Class Redis not exists"); } $this->cache_object = new \Redis(); if ($this->cache_object->connect($this->config['host'], $this->config['port'])) { if (isset($this->config['auth']) && !empty($this->config['auth'])) { $this->cache_object->auth($this->config['auth']); } } else { return Console::error("Redis Connect fail"); } }
/** * 连接 * @return [type] [description] */ public function connect() { // 判断是否存在redis if (!class_exists('MongoClient')) { return Console::error("Class MongoClient not exists"); } // 实例化mongoclient try { $this->cache_object = new \MongoClient($this->config['server'], array('connect' => true)); // 获取db和collection $db = $this->config['db']; $collection = $this->config['collection']; $this->mongo = $this->cache_object->{$db}->{$collection}; } catch (MongoConnectionException $e) { return Console::error("Mongo Connect fail", $e->getMessage()); } }