Skip to content

Instantly share code, notes, and snippets.

@kmpzr
Created February 15, 2013 13:50
Show Gist options
  • Select an option

  • Save kmpzr/4960488 to your computer and use it in GitHub Desktop.

Select an option

Save kmpzr/4960488 to your computer and use it in GitHub Desktop.
Redis Client (Predis). Keys that Expires.
<?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);
}
}
?>
<?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