Store.php.for-memcache 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author walkor <worker-man@qq.com>
  6. *
  7. */
  8. class Store
  9. {
  10. protected static $instance = null;
  11. public static function connect()
  12. {
  13. if(!self::$instance)
  14. {
  15. self::$instance = new Memcache;
  16. self::$instance->addServer('127.0.0.1', 11211);
  17. }
  18. return self::$instance;
  19. }
  20. public static function set($key, $value, $ttl = 0)
  21. {
  22. if(self::connect())
  23. {
  24. return self::$instance->set($key, $value, $ttl);
  25. }
  26. return false;
  27. }
  28. public static function get($key)
  29. {
  30. if(self::connect())
  31. {
  32. return self::$instance->get($key);
  33. }
  34. return false;
  35. }
  36. public static function delete($key)
  37. {
  38. if(self::connect())
  39. {
  40. return self::$instance->delete($key);
  41. }
  42. return false;
  43. }
  44. public static function deleteAll(){}
  45. }