CMemdUtil.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of CMemdUtil
  5. * CMemd工具类[CMem线上版]
  6. * @deprecated since version 2017.08.08
  7. * @author jgao,gwang
  8. */
  9. class CMemdUtil extends CMemBase
  10. {
  11. //put your code here
  12. public $mem = 0;
  13. public $keyDic = null;
  14. public function conn($host, $port, $pwd = "")
  15. {
  16. $this->mem = new Memcached();
  17. $this->mem->addServer($host, $port);
  18. $this->keyDic = new \stdClass();
  19. }
  20. public function get($key)
  21. {
  22. $cas_token = "";
  23. $result = $this->mem->get($key, null, $cas_token);
  24. if (!$result || $result == "" || $result == null) {
  25. return null;
  26. }
  27. $this->keyDic->$key = $cas_token;
  28. return JsonUtil::decode($result);
  29. }
  30. public function set($key, $value, $ts = 0)
  31. {
  32. if ($value == null || $value == "") {
  33. return false;
  34. }
  35. return $this->mem->set($key, JsonUtil::encode($value), $ts);
  36. }
  37. public function add($key, $value, $ts = 0)
  38. {
  39. if ($value == null || $value == "") {
  40. return false;
  41. }
  42. return $this->mem->add($key, JsonUtil::encode($value), $ts);
  43. }
  44. public function replace($key, $value, $ts = 0)
  45. {
  46. if ($value == null || $value == "") {
  47. return false;
  48. }
  49. return $this->mem->replace($this->mem, $key, JsonUtil::encode($value), $ts);
  50. }
  51. public function delete($key)
  52. {
  53. return $this->mem->delete($key);
  54. }
  55. public function increment($key)
  56. {
  57. return $this->mem->increment($key);
  58. }
  59. public function getMulti($keys)
  60. {
  61. $resultMulti = $this->mem->getMulti($keys);
  62. $retArray = array();
  63. foreach ($resultMulti as $result) {
  64. if (!$result || $result == "" || $result == null) {
  65. $retArray[] = null;
  66. } else {
  67. $retArray[] = JsonUtil::decode($result);
  68. }
  69. }
  70. return $retArray;
  71. }
  72. public function cas($key, $value, $ts)
  73. {
  74. if (!property_exists($this->keyDic, $key)) {
  75. return false;
  76. }
  77. if ($value == null || $value == "") {
  78. return false;
  79. }
  80. $cas_token = $this->keyDic->$key;
  81. return $this->mem->cas($cas_token, $key, JsonUtil::encode($value), $ts);
  82. }
  83. public function close()
  84. {
  85. return $this->mem->quit();
  86. }
  87. // --> 实现抽象类的 功能
  88. public function copy($surKey, $desKey)
  89. {
  90. return $this->set($desKey, $this->get($surKey));
  91. }
  92. /**
  93. *
  94. * @deprecated since version 20160413113950 经过自己考察json_encode对数据的影响并不存在
  95. * @param type $key
  96. */
  97. public function getWithoutJson($key)
  98. {
  99. }
  100. /**
  101. *
  102. * @deprecated since version 20160413113950 经过自己考察json_encode对数据的影响并不存在
  103. * @param type $key
  104. * @param type $value
  105. * @param type $ts
  106. */
  107. public function setWithoutJson($key, $value, $ts = 0)
  108. {
  109. }
  110. public function setMutlti($dict, $expireTs = 0)
  111. {
  112. }
  113. }