PHP Doku:: Store an item - memcached.set.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteMemcachedThe Memcached classMemcached::set

Ein Service von Reinhard Neidl - Webprogrammierung.

The Memcached class

<<Memcached::replaceByKey

Memcached::setByKey>>

Memcached::set

(PECL memcached >= 0.1.0)

Memcached::setStore an item

Beschreibung

public bool Memcached::set ( string $key , mixed $value [, int $expiration ] )

Memcached::set() stores the value on a memcache server under the specified key. The expiration parameter can be used to control when the value is considered expired.

The value can be any valid PHP type except for resources, because those cannot be represented in a serialized form. If the Memcached::OPT_COMPRESSION option is turned on, the serialized value will also be compressed before storage.

Parameter-Liste

key

Der Schlüssel, unter dem der Wert abgelegt werden soll.

value

Der zu speichernde Wert.

expiration

Die Verfallszeit, Vorgabewert ist 0. Siehe Verfallszeiten für weiterführende Informationen.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben. Benutzen Sie wenn nötig Memcached::getResultCode().

Beispiele

Beispiel #1 Memcached::set() example

<?php
$m 
= new Memcached();
$m->addServer('localhost'11211);

$m->set('int'99);
$m->set('string''a simple string');
$m->set('array', array(1112));
/* expire 'object' key in 5 minutes */
$m->set('object', new stdclasstime() + 300);


var_dump($m->get('int'));
var_dump($m->get('string'));
var_dump($m->get('array'));
var_dump($m->get('object'));
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

int(99)
string(15) "a simple string"
array(2) {
  [0]=>
  int(11)
  [1]=>
  int(12)
}
object(stdClass)#1 (0) {
}

Siehe auch


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
miha at hribar dot info
16.07.2009 17:26
The method correctly returns false if you set the value to false. This means that in order to have proper fault checking mechanism in place you need to check the result code.

<?php
$Memcached
= new Memcached();
$Memcached->addServer('localhost', 11211);
$Memcached->set('key', false);
var_dump($Memcached->get('key'));      // boolean false
var_dump($Memcached->getResultCode()); // int 0 which is  Memcached::RES_SUCCESS 
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)