Ejemplo n.º 1
0
 public function __construct($settings)
 {
     parent::bootstrap();
     $t = microtime(true);
     $redis = new \Redis();
     try {
         $redis->connect($settings['host'], $settings['port']);
         if (isset($settings['password']) && !empty($settings['password'])) {
             if ($redis->auth($settings['password']) === false) {
                 throw new \Exception('Unable to authenticate with redis!');
             }
         }
         if (isset($settings['database']) && !empty($settings['database'])) {
             if ($redis->select($settings['database']) === false) {
                 throw new \Exception('Unable to Redis database select');
             }
         }
     } catch (\Exception $e) {
         throw new \Exception('Unable to connect to Redis server');
     }
     if (isset($settings['prefix'])) {
         $redis->setOption(\Redis::OPT_PREFIX, $settings['prefix'] . ':');
     }
     parent::$serviceInstance[get_class()] = $redis;
     $queryTime = round((microtime(true) - $t) * 1000, 2);
     self::logQuery(array('command' => 'CONNECTION to ' . $settings['host'] . ':' . $settings['port'], 'time' => $queryTime));
     self::$_totalTime[get_class()] += $queryTime;
     self::$_totalQueries[get_class()]++;
 }
Ejemplo n.º 2
0
 public function __construct($settings)
 {
     parent::bootstrap();
     $t = microtime(true);
     try {
         parent::$serviceInstance[get_class()] = new \Mongo($settings['host'] . ':' . $settings['port']);
     } catch (\Exception $e) {
         throw new \Exception('Unable to connect to Mongo server');
     }
     $queryTime = round((microtime(true) - $t) * 1000, 2);
     parent::logQuery(array('command' => 'CONNECTION to ' . $settings['host'] . ':' . $settings['port'], 'time' => $queryTime));
     parent::$_totalTime[get_class()] += $queryTime;
     parent::$_totalQueries[get_class()]++;
 }
Ejemplo n.º 3
0
 public function __construct($settings)
 {
     parent::bootstrap();
     $this->settings = $settings;
     parent::$serviceInstance[get_class()] = $this;
 }