欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

读取设置memcache的值(优先支持memcached扩展和cas协议)

程序员文章站 2022-05-18 16:42:02
...
addServer($INI['memcachehost'], $INI['memcacheport']);
				$res['value'] = $m1->get($key, null, $cas);
				$res['cas'] = $cas;
			}
			else
			{
				$m1 = self::getinstance();
				$m1->addServer($INI['memcachehost'], $INI['memcacheport']);
				$res['value'] = $m1->get($key);
			}
			return $res;
		}

		static public function set($key,$value,$cas)
		{
			$value = (string)$value;
			global $INI;
			if(class_exists('Memcached'))
			{
				$m1 = self::getinstance();
				$m1->addServer($INI['memcachehost'], $INI['memcacheport']);
				$res = $m1->cas($cas,$key,$value);
			}
			else
			{
				$m1 = self::getinstance();
				$m1->addServer($INI['memcachehost'], $INI['memcacheport']);
				$res = $m1->set($key,$value);
			}
			return $res;
		}
	}