public bool resetServerList ( void )
取消所有addServer()或addServers()的操作,置空服务端的Memcached中的服务器列表,客户端需要重新调用addServer()或addServers()才可对Memcached进行操作。public bool set ( string $key , mixed $value [, int $expiration ] )
将服务器Memcached中key为$key的数据的值更新为$value,如没有找到数据则新增。
如果设置$expiration则可以定义数据的存活时间,相关说明同add().与add、replace的区别于联系:
replace仅能更改已存在于Memcached中的数据,不能新增数据。
add仅能新增数据,不能更改已存在的数据;
set=add+replace,如果数据已存在则修改(replace),如果不存在则新增(add)。public bool setByKey ( string $server_key , string $key , mixed $value [, int $expiration ] )
同set,但仅在$server_key对应的服务器上进行操作。public bool setMulti ( array $items [, int $expiration ] )
同时执行多个set操作,设置多个key的value. $items为对应数据,结构为key=>value. $expiration的解释同add().public bool setMultiByKey ( string $server_key , array $\items [, int \$expiration ] )
同setMulti ,但仅在\$server_key对应的服务器上进行操作。public bool setOption ( int $option , mixed $value )
设置Memcached的属性,相关数据的说明参见:PHP常量说明, 其中OPT_开头的均为可设置的属性。public bool setOptions ( array $options )
批量设置属性,数组中的每个元素均为属性key=>属性value. 属性说明同setOption.public void setSaslAuthData ( string $username , string $password )
使用此方法需要确保PHP的SASL插件已安装到服务器。
安装方法:sudo apt-get install php5-sasl
安装后需要重新启动Apache:
sudo service apache2 restart
如果遇到报错:
Call to undefined method Memcached::setSaslAuthData()
则说说明服务器上安装的php扩展甚至libmemcached、memcached没有集成sasl或启动该模块的,需要重新下载源码,编译和安装,当然操作前需要先卸载现有的php扩展、libmemcached,甚至memcached.
/* memcached installed by 'apt-get intall memcached' does not support sasl, remove first and install from source*/ sudo apt-get remove memcached // remove libmemcached sudo apt-get remove libmemcached*(eg. libmemcached-dev libmemcached10) // remove php extension sudo apt-get remove php5-memcached //clean up sudo apt-get autoremove // install tools to install php extension from code sudo apt-get install php5-dev //install dependant of memcached sudo apt-get install libsasl2-dev sudo apt-get install libevent-dev // install memcached from code sudo wget http://memcached.org/latest -O memcached.tar.gz sudo tar -zxvf memcached.tar.gz cd memcached-*(eg. memcached-1.4.29) sudo ./configure --enable-sasl sudo make sudo make install // install libmemcached sudo wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz sudo tar -zxvf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 sudo make sudo make install //install php extension-memcached sudo pecl download memcached cd memcached-*(eg. memcached-2.2.0) phpize sudo ./configure --enable-memcached-sasl make make install sudo php5enmod memcached sudo service apache2 restart
public bool touch ( string $key , int $expiration )
更改服务器上Memcached中key是$key的数据的存活时间为 expiration. expiration的解释同add()public bool touchByKey ( string $server_key , string $key , int $expiration )
同touch,但仅在$server_key对应的服务器上进行操作。
PHP的51个Memcached方法(42-51)
最新推荐文章于 2022-11-09 13:16:07 发布