Created
February 15, 2013 13:50
-
-
Save kmpzr/4960488 to your computer and use it in GitHub Desktop.
Redis Client (Predis). Keys that Expires.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Redis { | |
| private static $handler = NULL; | |
| private static function getHandler() | |
| { | |
| if (self::$handler) | |
| return self::$handler; | |
| self::$handler = new Predis\Client(); | |
| return self::$handler; | |
| } | |
| public static function __callStatic($name, $args) | |
| { | |
| $callback = array(self::getHandler(), $name); | |
| return call_user_func_array($callback, $args); | |
| } | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $minutes_to_expire = 5; | |
| $key = "namespace:key"; | |
| if (!Redis::get($key)) { | |
| Redis::set($key, "value"); | |
| } | |
| Redis::expire($key, ($minutes_to_expire * 60)); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment