Memcached::append
(PECL memcached >= 0.1.0)
Memcached::append — 向已存在元素后追加数据
说明
public Memcached::append(string
$key
, string $value
): bool
Memcached::append()向已经存在的元素后追加value
参数对应的字符串值。
value
被强制转换成字符串类型主要是因为对于mix类型的追加没有很好的定义。
注意:
如果
Memcached::OPT_COMPRESSION
常量开启,这个操作会失败,并引发一个警告,因为向压缩数据 后追加数据可能会导致解压不了。
参数
-
key
-
用于存储值的键名。
-
value
-
将要追加的值。
返回值
成功时返回 true
, 或者在失败时返回 false
。
如果key不存在,Memcached::getResultCode()将返回Memcached::RES_NOTSTORED
。
范例
示例 #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"

User Contributed Notes 1 note
mattsch at gmail dot com ¶
7 years ago
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