SRedis::useConfig PHP Method

useConfig() static public method

切换配置文件
static public useConfig ( string $zone, $type = "host" ) : array
$zone string
return array
    static function useConfig($zone, $type = "host")
    {
        $key = $zone . ":" . $type;
        if (isset(self::$_instances[$key])) {
            self::$_rc = self::$_instances[$key];
            return self::$_rc;
        }
        $hosts = array();
        $options = array();
        $config = self::getConfig($zone, $type);
        if (empty($config)) {
            trigger_error("the redis hosts is not set in config file(" . self::$_config . ")");
            return false;
        }
        if (is_array($config)) {
            $hosts = $config;
        } else {
            $hosts[] = $config;
        }
        $config = self::getConfig($zone, "options");
        if (!empty($config)) {
            if (is_object($config)) {
                foreach ($config as $k => $v) {
                    $options[$k] = $v;
                }
            }
        }
        return self::$_rc = self::$_instances[$key] = new RedisArray($hosts, $options);
    }

Usage Example

Esempio n. 1
0
 public function pageEntry($inPath)
 {
     SRedis::useConfig("default");
     $r = SRedis::set($key = "key", $v = "value." . date("Y-m-d H:i:s"), 60);
     if ($r) {
         echo "set redis ok!<br />\n";
     } else {
         echo "set redis fail!<br />\n";
     }
     $v = SRedis::get($key);
     echo "get redis values:{$v} <br />\n";
 }