Memcached::append()
(PECL memcached >= 0.1.0)
向已存在元素后追加数据
说明
public Memcached::append(string $key,string $value): bool
Memcached::append()向已经存在的元素后追加$value参数对应的字符串值。$value被强制转换成字符串类型主要是因为对于mix类型的追加没有很好的定义。
Note:如果
Memcached::OPT_COMPRESSION
常量开启,这个操作会失败,并引发一个警告,因为向压缩数据后追加数据可能会导致解压不了。
参数
- $key
用于存储值的键名。
- $value
将要追加的值。
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。如果key不存在,Memcached::getResultCode()将返回Memcached::RES_NOTSTORED
。
范例
Example #1 Memcached::append()示例
<?php $m = new Memcached(); $m->addServer('localhost', 11211); $m->setOption(Memcached::OPT_COMPRESSION, false); $m->set('foo', 'abc'); $m->append('foo', 'def'); var_dump($m->get('foo')); ?>
以上例程会输出:
string(6) "abcdef"
参见
- Memcached::appendByKey() 向指定服务器上已存在元素后追加数据
- Memcached::prepend() 向一个已存在的元素前面追加数据
This method emits this php warning if OPT_COMPRESSION is not explicitly set to false (tested with libmemcached 1.0.18 & pecl-memcached 2.1.0): PHP Warning: Memcached::append(): cannot append/prepend with compression turned on