Memcache::replace

memcache_replace

(PECL memcache >= 0.2.0)

Memcache::replace -- memcache_replaceSubstitui o valor do item existente

Descrição

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() deve ser usado para substituir o valor de item existente por key. Caso o item com tal chave não exista, Memcache::replace() retorna false. Para o resto, Memcache::replace() se comporta similarmente a Memcache::set().

Parâmetros

key

A chave que será associada ao item.

var

A variável a ser armazenada. Strings e inteiros são armazenados diretamente, outros tipos são armazenados serializados.

flag

Use MEMCACHE_COMPRESSED para armazenar o item compactado (usa zlib).

expire

Tempo de expiração do item. Se for igual a zero, o item nunca irá expirar. Você também pode usar o timestamp Unix ou um número de segundos iniciando do horário atual, mas no último caso o número de segundos não pode exceder 2592000 (30 dias).

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Exemplos

Exemplo #1 Exemplo de Memcache::replace()

<?php

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

/* API procedural */
memcache_replace($memcache_obj, "chave_teste", "variável qualquer", false, 30);

/* API orientada a objeto */
$memcache_obj->replace("chave_teste", "variável qualquer", false, 30);

?>

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 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