略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Memcached::append

2024-05-02

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_COMPRESSIONfalse);

$m->set('foo''abc');
$m->append('foo''def');
var_dump($m->get('foo'));
?>

以上例程会输出:

string(6) "abcdef"

参见

add a noteadd a note

User Contributed Notes 1 note

up
1
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

官方地址:https://www.php.net/manual/en/memcached.append.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3