Ejemplo n.º 1
0
 public function _getRedis($options)
 {
     if (!isset($options["host"]) || !isset($options["port"]) || !isset($options["persistent"])) {
         throw new Exception("Unexpected inconsistency in options");
     }
     if (isset($options['prefix'])) {
         self::$_prefix = $options['prefix'];
     }
     $redis = new \Redis();
     if ($options["persistent"]) {
         $success = $redis->pconnect($options['host'], intval($options['port']));
     } else {
         $success = $redis->connect($options['host'], intval($options['port']));
     }
     if (!$success) {
         throw new Exception("Could not connect to the Redisd server " . $options["host"] . ":" . $options["port"]);
     }
     if (isset($options["auth"])) {
         $success = $redis->auth($options["auth"]);
         if (!$success) {
             throw new Exception("Failed to authenticate with the Redisd server");
         }
     }
     if (isset($options["index"])) {
         $redis->select(intval($options["index"]));
     } else {
         $redis->select(self::$_db);
     }
     return $redis;
 }
Ejemplo n.º 2
0
 /**
  * Init Redis to usse in socket.io.
  *
  * @param DI     $di     Dependency Injection.
  * @param Config $config Config object.
  *
  * @return void
  */
 protected function _initRedis($di, $config)
 {
     $di->set('redis', function () use($config) {
         $redis = new \Redis();
         $redis->connect($config->db->redis->host, $config->db->redis->port);
         return $redis;
     }, true);
 }