CMemUtil.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. //
  3. //namespace loyalsoft;
  4. //
  5. ///*
  6. // * 操作内存数据库 Memcache工具类
  7. // * version:
  8. // * 2016.4.12 (gwang)改造出一个基类
  9. // * 2016.4.12 以前的记录无
  10. // */
  11. //
  12. ///**
  13. // * Description of MemCacheUtil
  14. // * CMem工具类[APHP三大操作单元之一]
  15. // * @deprecated since version 2017.08.08
  16. // * @author jgao,gwang
  17. // */
  18. //class CMemUtil extends CMemBase
  19. //{
  20. //
  21. // //put your code here
  22. // public $mem = 0;
  23. // public $keyDic = null;
  24. //
  25. // public function conn($host, $port, $pwd = "")
  26. // {
  27. // $this->keyDic = new \stdClass();
  28. // $this->mem = new Memcache();
  29. // return $this->mem->connect($host, $port);
  30. // }
  31. //
  32. // /**
  33. // *
  34. // * @param string $key
  35. // * @return any
  36. // */
  37. // public function get($key)
  38. // {
  39. // $cas_token = "";
  40. // if ($GLOBALS['mem_version'] == "3.0") {
  41. // $result = memcache_get($this->mem, $key, null, $cas_token);
  42. // } else {
  43. // $result = memcache_get($this->mem, $key);
  44. // }
  45. // if (!$result || $result == "" || $result == null) {
  46. // return null;
  47. // }
  48. // if ($GLOBALS['mem_version'] == "3.0") {
  49. // $this->keyDic->$key = $cas_token;
  50. // }
  51. // return JsonUtil::decode($result);
  52. // }
  53. //
  54. // public function set($key, $value, $ts = 0)
  55. // {
  56. // if ($value == null || $value == "") {
  57. // return false;
  58. // }
  59. // return memcache_set($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts);
  60. // }
  61. //
  62. // /**
  63. // * 取没有进行json编码的数据
  64. // * @param type $key
  65. // * @return string
  66. // */
  67. // public function getWithoutJson($key)
  68. // {
  69. // $cas_token = "";
  70. // if ($GLOBALS['mem_version'] == "3.0") {
  71. // $result = memcache_get($this->mem, $key, null, $cas_token);
  72. // } else {
  73. // $result = memcache_get($this->mem, $key);
  74. // }
  75. // if (!$result || $result == "" || $result == null) {
  76. // return null;
  77. // }
  78. // if ($GLOBALS['mem_version'] == "3.0") {
  79. // $this->keyDic->$key = $cas_token;
  80. // }
  81. // return $result;
  82. // }
  83. //
  84. // /**
  85. // * 设置值,内部不加 json_encode
  86. // * @param string $key
  87. // * @param string $value
  88. // * @param int $ts expirets Ps.当ts的值大于一个月的时候将被视为时间戳
  89. // * @return boolean
  90. // */
  91. // public function setWithoutJson($key, $value, $ts = 0)
  92. // {
  93. // if ($value == null || $value == "") {
  94. // return false;
  95. // }
  96. // return memcache_set($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts);
  97. // }
  98. //
  99. // public function add($key, $value, $ts = 0)
  100. // {
  101. // if ($value == null || $value == "") {
  102. // return false;
  103. // }
  104. // return memcache_add($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts);
  105. // }
  106. //
  107. // public function replace($key, $value, $ts = 0)
  108. // {
  109. // if ($value == null || $value == "") {
  110. // return false;
  111. // }
  112. // return memcache_replace($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts);
  113. // }
  114. //
  115. // public function delete($key)
  116. // {
  117. // return memcache_delete($this->mem, $key);
  118. // }
  119. //
  120. // public function increment($key)
  121. // {
  122. // return memcache_increment($this->mem, $key);
  123. // }
  124. //
  125. // public function getMulti($keys)
  126. // {
  127. // $retArray = array();
  128. // foreach ($keys as $key) {
  129. // $result = $this->get($key);
  130. // if ($result == null) {
  131. // $retArray[] = null;
  132. // } else {
  133. // $retArray[] = $result;
  134. // }
  135. // }
  136. // return $retArray;
  137. // }
  138. //
  139. // public function setMutlti($dict, $expireTs = 0)
  140. // {
  141. // ;
  142. // }
  143. //
  144. // public function cas($key, $value, $ts)
  145. // {
  146. // if ($GLOBALS['mem_version'] == "3.0") {
  147. // if ($value == null || $value == "") {
  148. // return false;
  149. // }
  150. // if (!property_exists($this->keyDic, $key)) {
  151. // return memcache_set($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts);
  152. // }
  153. // $cas_token = $this->keyDic->$key;
  154. // return memcache_cas($this->mem, $key, JsonUtil::encode($value), MEMCACHE_COMPRESSED, $ts, $cas_token);
  155. // } else {
  156. // return $this->set($key, $value, $ts);
  157. // }
  158. // }
  159. //
  160. // public function copy($surKey, $desKey)
  161. // {
  162. // return $this->set($desKey, $this->get($surKey));
  163. // }
  164. //
  165. // public function close()
  166. // {
  167. // return memcache_close($this->mem);
  168. // }
  169. //
  170. //}