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"; }
/** * 切换配置文件 * @param string $zone * @return array */ static function useConfig($zone, $type = "host") { $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; } } } self::$_rc = new RedisArray($hosts, $options); }
public static function __callStatic($name, $args) { try { if (self::$_rc) { return call_user_func_array(array(self::$_rc, $name), $args); } } catch (RedisException $e) { self::$_instances = null; self::$_rc = null; trigger_error($e); } return false; }
<?php /** * sample to test * * http://localhost/samples/www/index.php/zone/default/entry/a/b/c * http://localhost/samples/www/index.php/zone-default-entry-a-b-c.html * */ require_once "global.php"; //SlightPHP::setDebug(true); SlightPHP::setAppDir(ROOT_APP); SlightPHP::setDefaultZone("index"); SlightPHP::setDefaultPage("main"); SlightPHP::setDefaultEntry("entry"); SlightPHP::setSplitFlag("-_."); //{{{ SDb::setConfigFile(ROOT_CONFIG . "/db.conf"); SRoute::setConfigFile(ROOT_CONFIG . "/route.conf"); SRedis::setConfigFile(ROOT_CONFIG . "/redis.conf"); //}}} if (($r = SlightPHP::run()) === false) { echo "404 error"; } elseif (is_object($r)) { var_dump($r); } else { echo $r; }