Memcache::set

(PECL memcache >= 0.2.0)

Memcache::setStore data at the server

Beschreibung

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

Memcache::set() stores an item var with key on the memcached server. Parameter expire is expiration time in seconds. If it's 0, the item never expires (but memcached server doesn't guarantee this item to be stored all the time, it could be deleted from the cache to make place for other items). You can use MEMCACHE_COMPRESSED constant as flag value if you want to use on-the-fly compression (uses zlib).

Hinweis:

Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache, because they cannot be adequately represented in serialized state.

Also you can use memcache_set() function.

Parameter-Liste

key

The key that will be associated with the item.

var

The variable to store. Strings and integers are stored as is, other types are stored serialized.

flag

Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).

expire

Expiration time of the item. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).

Rückgabewerte

Gibt bei Erfolg true zurück. Bei einem Fehler wird false zurückgegeben.

Beispiele

Beispiel #1 Memcache::set() example

<?php
/* procedural API */

/* connect to memcached server */
$memcache_obj memcache_connect('memcache_host'11211);

/*
set value of item with key 'var_key'
using 0 as flag value, compression is not used
expire time is 30 seconds
*/
memcache_set($memcache_obj'var_key''some variable'030);

echo 
memcache_get($memcache_obj'var_key');

?>

Beispiel #2 Memcache::set() example

<?php
/* OO API */

$memcache_obj = new Memcache;

/* connect to memcached server */
$memcache_obj->connect('memcache_host'11211);

/*
set value of item with key 'var_key', using on-the-fly compression
expire time is 50 seconds
*/
$memcache_obj->set('var_key''some really big variable'MEMCACHE_COMPRESSED50);

echo 
$memcache_obj->get('var_key');

?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

lfuzosin Billig. mochte Alfuzosin kaufen - Kaufen Sie Alfuzosin sicher online über N

Billig Alfuzosin. mochte Alfuzosin kaufen Sie benötigen zuverlässige, hochwertige Medikamente, möchten aber nicht das Haus verlassen, um sie zu ...

Geschrieben von drawer am 20.06.2026 06:59:50
Forum: Fragen/Vorschläge zum Forum
enormina Sin receta. costo de pastillas Tenormina - Tenormina comprar Europa. Badalo

Sin receta Tenormina. costo de pastillas Tenormina ¿Necesita medicamentos de calidad sin complicaciones? ¡Nuestra farmacia en línea está aquí ...

Geschrieben von travelder am 20.06.2026 06:59:49
Forum: Entwicklungsumgebungen
vermectin Fast delivery. Buy cheap Ivermectin - Ivermectin Overnight COD No Prescrip

Fast delivery Ivermectin. Buy cheap Ivermectin Do you need reliable, high-quality medications, but don't want to leave home to buy them? Then you ...

Geschrieben von drawer am 20.06.2026 06:59:11
Forum: Ankündigungen
emazepam Te koop. Bekijk Kopen Temazepam No Prescription - Koop Temazepam online zon

Te koop Temazepam. Bekijk Kopen Temazepam No Prescription Op zoek naar eersteklas medicijnen zonder dat u uw huis hoeft te verlaten? Zoek niet ver ...

Geschrieben von travelder am 20.06.2026 06:58:20
Forum: Projekthilfe