TestStore.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Link : http://www.phpcorner.net
  4. * User : qingbing<780042175@qq.com>
  5. * Date : 2018-12-05
  6. * Version : 1.0
  7. */
  8. namespace TestClass;
  9. use Abstracts\Store;
  10. class TestStore extends Store
  11. {
  12. private $_storeData = [];
  13. /**
  14. * 属性赋值后执行函数
  15. */
  16. public function init()
  17. {
  18. // TODO: Implement init() method.
  19. }
  20. /**
  21. * 获取最终的 id
  22. * @param mixed $key
  23. * @return string
  24. */
  25. protected function buildKey($key)
  26. {
  27. return md5(is_string($key) ? $key : json_encode($key));
  28. }
  29. /**
  30. * 获取 id 的信息
  31. * @param mixed $id
  32. * @return mixed
  33. */
  34. protected function getValue($id)
  35. {
  36. return isset($this->_storeData[$id]) ? $this->_storeData[$id] : null;
  37. }
  38. /**
  39. * 保存 id 的信息
  40. * @param string $id
  41. * @param string $value
  42. * @param int $ttl
  43. * @return bool
  44. */
  45. protected function setValue($id, $value, $ttl)
  46. {
  47. // 测试示例,不考虑 ttl 的情况
  48. $this->_storeData[$id] = $value;
  49. return true;
  50. }
  51. /**
  52. * 删除 id 的信息
  53. * @param string $id
  54. * @return bool
  55. */
  56. protected function deleteValue($id)
  57. {
  58. unset($this->_storeData[$id]);
  59. return true;
  60. }
  61. /**
  62. * 清理所有值
  63. * @return bool
  64. */
  65. protected function clearValues()
  66. {
  67. $this->_storeData = [];
  68. return true;
  69. }
  70. }