php的两个memcached扩展:memcache和memcached(二)

现在在php中memcached用的很多,以前一直使用的是php的memcache扩展,最近开始改用了php的memcached扩展(注意这里memcache和memcached扩展的名字就相差了一个d)。或许在google或者百度搜索php的memcached扩展的时候,很多结果是memcache.dll或者memcache.so,很少的结果是memcached.so,windows下面甚至没有memcached.dll扩展。
memcache扩展的下载地址为:http://pecl.php.net/package/memcache
memcached扩展的下载地址为:http://pecl.php.net/package/memcached
以上两个都是源码包。
这两个扩展都是用c写的,具体的来看看memcache扩展和memcached扩展在使用上到底有哪些差别。

加载memcache扩展之后,可以在php中直接使用Memcache类,Memcache类有以下一些方法:

Memcache {
    bool add ( string $key , mixed $var [, int $flag [, int $expire ]] )
 
    bool addServer ( string $host [, int $port = 11211 [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback [, int $timeoutms ]]]]]]]] )
 
    bool close ( void )
 
    bool connect ( string $host [, int $port [, int $timeout ]] )
 
    int decrement ( string $key [, int $value = 1 ] )
 
    bool delete ( string $key [, int $timeout ] )
 
    bool flush ( void )
 
    string get ( string $key [, int &$flags ] )
 
    array getExtendedStats ([ string $type [, int $slabid [, int $limit = 100 ]]] )
 
    int getServerStatus ( string $host [, int $port = 11211 ] )
 
    array getStats ([ string $type [, int $slabid [, int $limit = 100 ]]] )
 
    string getVersion ( void )
 
    int increment ( string $key [, int $value = 1 ] )
 
    bool pconnect ( string $host [, int $port [, int $timeout ]] )
 
    bool replace ( string $key , mixed $var [, int $flag [, int $expire ]] )
 
    bool set ( string $key , mixed $var [, int $flag [, int $expire ]] )
 
    bool setCompressThreshold ( int $threshold [, float $min_savings ] )
 
    bool setServerParams ( string $host [, int $port = 11211 [, int $timeout [, int $retry_interval = false [, bool $status [, callback $failure_callback ]]]]] )
}
add — 增加一个条目到缓存服务器
addServer — 向连接池中添加一个memcache服务器
close — 关闭memcache连接
connect — 打开一个memcached服务端连接
decrement — 减小元素的值
delete — 从服务端删除一个元素
flush — 清洗(删除)已经存储的所有的元素
get — 从服务端检回一个元素
getExtendedStats — 缓存服务器池中所有服务器统计信息
getServerStatus — 用于获取一个服务器的在线/离线状态
getStats — 获取服务器统计信息
getVersion — 返回服务器版本信息
increment — 增加一个元素的值
pconnect — 打开一个到服务器的持久化连接
replace — 替换已经存在的元素的值
set — Store data at the server
setCompressThreshold — 开启大值自动压缩
setServerParams — 运行时修改服务器参数和状态

加载memcached扩展之后,可以在php中直接使用Memcached类,Memcached类有以下一些方法:

Memcached {
    __construct ([ string $persistent_id ] )
 
    public bool add ( string $key , mixed $value [, int $expiration ] )
 
    public bool addByKey ( string $server_key , string $key , mixed $value [, int $expiration ] )
 
    public bool addServer ( string $host , int $port [, int $weight = 0 ] )
 
    public bool addServers ( array $servers )
 
    public bool append ( string $key , string $value )
 
    public bool appendByKey ( string $server_key , string $key , string $value )
 
    public bool cas ( float $cas_token , string $key , mixed $value [, int $expiration ] )
 
    public bool casByKey ( float $cas_token , string $server_key , string $key , mixed $value [, int $expiration ] )
 
    public int decrement ( string $key [, int $offset = 1 ] )
 
    public bool delete ( string $key [, int $time = 0 ] )
 
    public bool deleteByKey ( string $server_key , string $key [, int $time = 0 ] )
 
    public array fetch ( void )
 
    public array fetchAll ( void )
 
    public bool flush ([ int $delay = 0 ] )
 
    public mixed get ( string $key [, callback $cache_cb [, float &$cas_token ]] )
 
    public mixed getByKey ( string $server_key , string $key [, callback $cache_cb [, float &$cas_token ]] )
 
    public bool getDelayed ( array $keys [, bool $with_cas [, callback $value_cb ]] )
 
    public bool getDelayedByKey ( string $server_key , array $keys [, bool $with_cas [, callback $value_cb ]] )
 
    public mixed getMulti ( array $keys [, array &$cas_tokens [, int $flags ]] )
 
    public array getMultiByKey ( string $server_key , array $keys [, string &$cas_tokens [, int $flags ]] )
 
    public mixed getOption ( int $option )
 
    public int getResultCode ( void )
 
    public string getResultMessage ( void )
 
    public array getServerByKey ( string $server_key )
 
    public array getServerList ( void )
 
    public array getStats ( void )
 
    public array getVersion ( void )
 
    public int increment ( string $key [, int $offset = 1 ] )
 
    public bool prepend ( string $key , string $value )
 
    public bool prependByKey ( string $server_key , string $key , string $value )
 
    public bool replace ( string $key , mixed $value [, int $expiration ] )
 
    public bool replaceByKey ( string $server_key , string $key , mixed $value [, int $expiration ] )
 
    public bool set ( string $key , mixed $value [, int $expiration ] )
 
    public bool setByKey ( string $server_key , string $key , mixed $value [, int $expiration ] )
 
    public bool setMulti ( array $items [, int $expiration ] )
 
    public bool setMultiByKey ( string $server_key , array $items [, int $expiration ] )
 
    public bool setOption ( int $option , mixed $value )

add — 向一个新的key下面增加一个元素
addByKey — 在指定服务器上的一个新的key下增加一个元素
addServer — 向服务器池中增加一个服务器
addServers — 向服务器池中增加多台服务器
append — 向已存在元素后追加数据
appendByKey — 向指定服务器上已存在元素后追加数据
cas — 比较并交换值
casByKey — 在指定服务器上比较并交换值
__construct — 创建一个Memcached实例
decrement — 减小数值元素的值
delete — 删除一个元素
deleteByKey — 从指定的服务器删除一个元素
fetch — 抓取下一个结果
fetchAll — 抓取所有剩余的结果
flush — 作废缓存中的所有元素
get — 检索一个元素
getByKey — 从特定的服务器检索元素
getDelayed — 请求多个元素
getDelayedByKey — 从指定的服务器上请求多个元素
getMulti — 检索多个元素
getMultiByKey — 从特定服务器检索多个元素
getOption — 获取Memcached的选项值
getResultCode — 返回最后一次操作的结果代码
getResultMessage — 返回最后一次操作的结果描述消息
getServerByKey — 获取一个key所映射的服务器信息
getServerList — 获取服务器池中的服务器列表
getStats — 获取服务器池的统计信息
getVersion — 获取服务器池中所有服务器的版本信息
increment — 增加数值元素的值
prepend — 向一个已存在的元素前面追加数据
prependByKey — Prepend data to an existing item on a specific server
replace — 替换已存在key下的元素
replaceByKey — Replace the item under an existing key on a specific server
set — 存储一个元素
setByKey — Store an item on a specific server
setMulti — 存储多个元素
setMultiByKey — Store multiple items on a specific server
setOption — 设置一个memcached选项


  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值