php8.5
Home/ Manual/ memcached / memcached/ Memcached::prepend

Memcached::prepend

PHP function Edit on GitHub ✎

(PECL memcached >= 0.1.0)

Prepend data to an existing item

Description

Memcached::prepend(string $key, string $value): bool|null

Memcached::prepend() prepends the given value string to the value of an existing item. The reason that value is forced to be a string is that prepending mixed types is not well-defined.

Note

If the Memcached::OPT_COMPRESSION is enabled, the operation will fail and a warning will be issued, because prepending compressed data to a value that is potentially already compressed is not possible.

Parameters

key

The key of the item to prepend the data to.

value

The string to prepend.

Return Values

Success Returns null when compression is on.

Errors/Exceptions

Returns null and raises an E_WARNING when compression is enabled.

Examples

Memcached::prepend() example

php
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->setOption(Memcached::OPT_COMPRESSION, false);

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

The above example will output:

output
string(6) "defabc"

See Also

  • Memcached::prependByKey
  • Memcached::append

Source: reference/memcached/memcached/prepend.xml · from the official PHP manual (php/doc-en)