Memcached::getMulti

(PECL memcached >= 0.1.0)

Memcached::getMultiRetrieve multiple items

Beschreibung

public Memcached::getMulti(array $keys, int $flags = ?): mixed

Memcached::getMulti() is similar to Memcached::get(), but instead of a single key item, it retrieves multiple items the keys of which are specified in the keys array.

Hinweis:

Before v3.0 a second argument &cas_tokens was in use. It was filled with the CAS token values for the found items. The &cas_tokens parameter was removed in v3.0 of the extension. It was replaced with a new flag Memcached::GET_EXTENDED that needs is to be used as the value for flags.

The flags parameter can be used to specify additional options for Memcached::getMulti(). Memcached::GET_PRESERVE_ORDER ensures that the keys are returned in the same order as they were requested in. Memcached::GET_EXTENDED ensures that the CAS tokens will be fetched too.

Parameter-Liste

keys

Array of keys to retrieve.

flags

The flags for the get operation.

Rückgabewerte

Returns the array of found itemsBei einem Fehler wird false zurückgegeben.. Benutzen Sie wenn nötig Memcached::getResultCode().

Changelog

Version Beschreibung
PECL memcached 3.0.0 The &cas_tokens parameter was removed. The Memcached::GET_EXTENDED was added and when passed as a flag it ensures the CAS tokens to be fetched.

Beispiele

Beispiel #1 Memcached::getMulti() example for Memcached v3

<?php
// Valid for v3 of the extension

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

$items = array(
    
'key1' => 'value1',
    
'key2' => 'value2',
    
'key3' => 'value3'
);
$m->setMulti($items);
$result $m->getMulti(array('key1''key3''badkey'));
var_dump($result);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(2) {
  ["key1"]=>
  string(6) "value1"
  ["key3"]=>
  string(6) "value3"
}

Beispiel #2 Memcached::getMulti() example for Memcached v1 and v2

<?php
// Valid for v1 and v2 of the extension

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

$items = array(
    
'key1' => 'value1',
    
'key2' => 'value2',
    
'key3' => 'value3'
);
$m->setMulti($items);
$result $m->getMulti(array('key1''key3''badkey'), $cas);
var_dump($result$cas);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

array(2) {
  ["key1"]=>
  string(6) "value1"
  ["key3"]=>
  string(6) "value3"
}
array(2) {
  ["key1"]=>
  float(2360)
  ["key3"]=>
  float(2362)
}

Beispiel #3 Memcached::GET_PRESERVE_ORDER example for Memcached v3

<?php
// Valid for v3 of the extension

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

$data = array(
    
'foo' => 'foo-data',
    
'bar' => 'bar-data',
    
'baz' => 'baz-data',
    
'lol' => 'lol-data',
    
'kek' => 'kek-data',
);

$m->setMulti($data3600);

$keys array_keys($data);
$keys[] = 'zoo';
$got $m->getMulti($keysMemcached::GET_PRESERVE_ORDER);

foreach (
$got as $k => $v) {
    echo 
"$k $v\n";
}
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

foo foo-data
bar bar-data
baz baz-data
lol lol-data
kek kek-data
zoo 

Beispiel #4 Memcached::GET_PRESERVE_ORDER example for Memcached v1 and v2

<?php
// Valid for v1 and v2 of the extension

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

$data = array(
    
'foo' => 'foo-data',
    
'bar' => 'bar-data',
    
'baz' => 'baz-data',
    
'lol' => 'lol-data',
    
'kek' => 'kek-data',
);

$m->setMulti($data3600);

$null null;
$keys array_keys($data);
$keys[] = 'zoo';
$got $m->getMulti($keys$nullMemcached::GET_PRESERVE_ORDER);

foreach (
$got as $k => $v) {
    echo 
"$k $v\n";
}
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

foo foo-data
bar bar-data
baz baz-data
lol lol-data
kek kek-data
zoo 

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.

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

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-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

SoundCloud to MP3

SoundCloud (https://soundcloudto.com/) to MP3 converters have gained popularity as convenient tools for downloading and converting audio from Soun ...

Geschrieben von soundcloudto am 19.07.2024 04:10:40
Forum: User pages
Suche Netzwerktechnik Großhändler

I'm currently seeking reliable wholesalers specializing in network technology. Please provide details on your range of products, pricing, and any ...

Geschrieben von dussan77 am 12.07.2024 16:54:48
Forum: Ankündigungen
Getting Database Connection Failed Error in PHP Project

Hi everyone, I’m currently working on an AI and ML-based web application using PHP, and I've hit a roadblock. I’m encountering a “Database ...

Geschrieben von Gast am 27.06.2024 11:31:32
Forum: Off-Topic Diskussionen
How to overcome Safari's iframe cookie block?

Hello I think your cookies are set with SameSite=None; Secure to allow cross-site usage. To implement a custom proxy on the server side to handle ...

Geschrieben von Gast am 27.06.2024 11:04:46
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS