Esempio n. 1
0
 public static function get_slave_redis($source_name)
 {
     if (!isset(self::$redis_nodes['slave'][$source_name])) {
         $dsns = config::get_logic('redis.' . $source_name . '.slaves', []);
         if ($dsns === []) {
             $dsns = array(config::get_logic('redis.' . $source_name . '.master'));
         }
         $all_attempts_failed = true;
         foreach ($dsns as $dsn) {
             $url_parts = parse_url($dsn);
             extract($url_parts, EXTR_SKIP);
             $redis_node = new redis_slave_node();
             if ($redis_node->connect($host, $port, 2)) {
                 self::$redis_nodes['slave'][$source_name] = $redis_node;
                 $all_attempts_failed = false;
                 break;
             } else {
                 logger::log_error("cannot connect to dsn: '{$dsn}', maybe failed?");
             }
         }
         if ($all_attempts_failed) {
             throw new server_except("cannot connect to all dsns of redis source: {$source_name}");
         }
     }
     return self::$redis_nodes['slave'][$source_name];
 }
Esempio n. 2
0
 public static function get_cache($cache_name)
 {
     static $caches = [];
     if (!array_key_exists($cache_name, $caches)) {
         $dsns = config::get_logic('cache.' . $cache_name);
         list($cache_type, ) = explode('://', current($dsns), 2);
         $cache_class = __NAMESPACE__ . '\\' . $cache_type . '_cache';
         $cache = new $cache_class($dsns);
         $caches[$cache_name] = $cache;
     }
     return $caches[$cache_name];
 }
Esempio n. 3
0
 public static function get_mover($target_name)
 {
     static $movers = [];
     if (!isset($movers[$target_name])) {
         $dsn = config::get_logic('mover.' . $target_name);
         list($mover_type, ) = explode('://', $dsn, 2);
         $mover_class = __NAMESPACE__ . '\\' . $mover_type . '_mover';
         if (!class_exists($mover_class, true)) {
             throw new developer_error("mover: '{$mover_class}' does not exist");
         }
         $mover = new $mover_class($dsn);
         $movers[$target_name] = $mover;
     }
     return $movers[$target_name];
 }
Esempio n. 4
0
File: rdb.php Progetto: xpd1437/swap
 protected static function get_source_name_from_table_name($table_name)
 {
     $source_name = config::get_logic('rdb.tables.' . $table_name, null);
     if ($source_name === null) {
         $source_name = config::get_logic('rdb.tables.*');
     }
     return $source_name;
 }