123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace loyalsoft;
- /**
- * Description of CMemdUtil
- * CMemd工具类[CMem线上版]
- * @deprecated since version 2017.08.08
- * @author jgao,gwang
- */
- class CMemdUtil extends CMemBase
- {
- //put your code here
- public $mem = 0;
- public $keyDic = null;
- public function conn($host, $port, $pwd = "")
- {
- $this->mem = new Memcached();
- $this->mem->addServer($host, $port);
- $this->keyDic = new \stdClass();
- }
- public function get($key)
- {
- $cas_token = "";
- $result = $this->mem->get($key, null, $cas_token);
- if (!$result || $result == "" || $result == null) {
- return null;
- }
- $this->keyDic->$key = $cas_token;
- return JsonUtil::decode($result);
- }
- public function set($key, $value, $ts = 0)
- {
- if ($value == null || $value == "") {
- return false;
- }
- return $this->mem->set($key, JsonUtil::encode($value), $ts);
- }
- public function add($key, $value, $ts = 0)
- {
- if ($value == null || $value == "") {
- return false;
- }
- return $this->mem->add($key, JsonUtil::encode($value), $ts);
- }
- public function replace($key, $value, $ts = 0)
- {
- if ($value == null || $value == "") {
- return false;
- }
- return $this->mem->replace($this->mem, $key, JsonUtil::encode($value), $ts);
- }
- public function delete($key)
- {
- return $this->mem->delete($key);
- }
- public function increment($key)
- {
- return $this->mem->increment($key);
- }
- public function getMulti($keys)
- {
- $resultMulti = $this->mem->getMulti($keys);
- $retArray = array();
- foreach ($resultMulti as $result) {
- if (!$result || $result == "" || $result == null) {
- $retArray[] = null;
- } else {
- $retArray[] = JsonUtil::decode($result);
- }
- }
- return $retArray;
- }
- public function cas($key, $value, $ts)
- {
- if (!property_exists($this->keyDic, $key)) {
- return false;
- }
- if ($value == null || $value == "") {
- return false;
- }
- $cas_token = $this->keyDic->$key;
- return $this->mem->cas($cas_token, $key, JsonUtil::encode($value), $ts);
- }
- public function close()
- {
- return $this->mem->quit();
- }
- // --> 实现抽象类的 功能
- public function copy($surKey, $desKey)
- {
- return $this->set($desKey, $this->get($surKey));
- }
- /**
- *
- * @deprecated since version 20160413113950 经过自己考察json_encode对数据的影响并不存在
- * @param type $key
- */
- public function getWithoutJson($key)
- {
- }
- /**
- *
- * @deprecated since version 20160413113950 经过自己考察json_encode对数据的影响并不存在
- * @param type $key
- * @param type $value
- * @param type $ts
- */
- public function setWithoutJson($key, $value, $ts = 0)
- {
- }
- public function setMutlti($dict, $expireTs = 0)
- {
- }
- }
|