PHP 8.5.0 Alpha 2 available for testing

Memcache::replace

memcache_replace

(PECL memcache >= 0.2.0)

Memcache::replace -- memcache_replaceRemplaza el valor de un elemento existente

Descripción

Memcache::replace(
    string $key,
    mixed $var,
    int $flag = ?,
    int $expire = ?
): bool
memcache_replace(
    Memcache $memcache,
    string $key,
    mixed $var,
    int $flag = ?,
    int $expire = ?
): bool

Memcache::replace() se utiliza para reemplazar el valor de un elemento identificado por la clave key. En el caso de que el elemento identificado por la clave key no exista, la función Memcache::replace() devolverá false. Por lo demás, la función Memcache::replace() funciona de la misma manera que la función Memcache::set().

Parámetros

key

La clave que se asociará con el elemento.

var

La variable a almacenar. Los strings y los integers se almacenan como tales, los demás tipos se almacenan de manera serializada.

flag

Utilice MEMCACHE_COMPRESSED para almacenar el elemento comprimido (utiliza zlib).

expire

Tiempo de expiración para el elemento. Si es igual a 0, el elemento no expirará nunca. También puede utilizarse un timestamp Unix o un número de segundos a partir de la fecha actual, pero en este último caso, el número de segundos no debe exceder 2592000 (30 días).

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo con Memcache::replace()

<?php

$memcache_obj
= memcache_connect('memcache_host', 11211);

/* API procedimental */
memcache_replace($memcache_obj, "test_key", "some variable", false, 30);

/* API orientada a objetos */
$memcache_obj->replace("test_key", "some variable", false, 30);

?>

Ver también

add a note

User Contributed Notes 1 note

up
10
adam.pippin [AT] ohmedia.ca
14 years ago
This page mentions that replace should be used rather than set, but gives no reason. Best information I could find was a comment by 'argyleblanket' on the set page. (http://www.php.net/manual/en/memcache.set.php#84032)

"Using set more than once for the same key seems to have unexpected results - it does not behave as a "replace," but instead seems to "set" more than one value for the same key. "get" may return any of the values.

This was tested on a multiple-server setup - behaviour may be different if you only have one server. "
To Top