/ 中存储网

Ubuntu 10.10下Memcache类delete失败的原因的方法及命令

2015-11-29 12:17:43 来源:中存储网

Ubuntu 10.10 Desktop下安装了Memcached,后来写了一个php文件来测试Memcache:

<?php 
$mem = new Memcache; 
$mem->connect('127.0.0.1',11211); 
$mem->delete('key'); 
?>

结果在delete的时候老是报错:

coinsight@insight-ubuntu:~$ php clear.php 
PHP Notice:  MemcachePool::delete(): Server 127.0.0.1 (tcp 11211, udp 0)  
failed with: CLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]
(0) in /home/coinsight/clear.php on line 4
coinsight@insight-ubuntu:~$

查找了半天原因发现在delete后面加个参数就可以了,并且这个参数必须是0,其它的值同样报错:

<?php 
$mem = new Memcache; 
$mem->connect('127.0.0.1',11211); 
$mem->delete('key',0); 
?>

后来百度+GG找,原因如下:

nibblebot at gmail dot com 09-Jul-2010 03:58  
the Memcache::delete(key) function is broken on several combinations of memcached+pecl-memcache combinations.  
 
pecl-memcache 2.2.5 + memcached 1.4.2 - Memcache::delete(key) WORKS 
 
pecl-memcache 2.2.5 + memcached 1.4.3 - Memcache::delete(key) DOES NOT WORK 
 
pecl-memcache 2.2.5 + memcached 1.4.4 - Memcache::delete(key) WORKS 
 
pecl-memcache 2.2.5 + memcached 1.4.5 - Memcache::delete(key) WORKS 
 
pecl-memcache 3.0.4 + memcached 1.4.2 - Memcache::delete(key) WORKS 
 
pecl-memcache 3.0.4 + memcached 1.4.3 - Memcache::delete(key) DOES NOT WORK 
 
pecl-memcache 3.0.4 + memcached 1.4.4 - Memcache::delete(key) DOES NOT WORK 
 
pecl-memcache 3.0.4 + memcached 1.4.5 - Memcache::delete(key) DOES NOT WORK

解决方案:(1)手动安装对应的版本 (2)在delete函数里面多加一个参数0。