Frage

After installing memcache on my EC2 Linux instance using this:

:~$ sudo apt-get install memcached php5-memcache

I can immediately do this:

$memcache = new Memcache;
$memcache->connect('localhost', 11211);

$array_result=$this->db->query("SELECT * where ...."); // some DB query
$memcache->set('my_items', $array_result, false, 60*60*24);    

and later can access this cached array like this:

$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$my_items=$memcache->get('my_items');
var_dump($my_items);

My question is what is the Elasticache syntax that correlates with memcache's connect(), set(), and get() commands? I'm totally confused by the Elasticache part of the AWS PHP SDK.

War es hilfreich?

Lösung

You need to create elasticache node (AWS Management Console), to which you can connect via memcache client, take a look at the Getting started guide.

If you want to control your cache nodes with your code then you should use Elasticache SDK.

$memcache->connect('myfirstcacheinstance.evdfes.0001.use1.cache.amazonaws.com', 11211);

You don't need memcache server on your EC2 Linux instance it's enough to have php5-memcache PECL extension.

Andere Tipps

Try this:

<?php

$server_endpoint = "xxx.xx.xfg.sae1.cache.amazonaws.com";
$server_port = 11211;

if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    //PHP 5.3 with php-pecl-memcache
    $client = new Memcache;
    $client->connect($server_endpoint, $server_port);
    //If you need debug see $client->getExtendedStats();
    $client->set('myKey', 'My Value PHP 5.3');
} else {
    //PHP 5.4 with php54-pecl-memcached:
    $client = new Memcached;
    $client->addServer($server_endpoint, $server_port);
    $client->set('myKey', 'My Value PHP 5.4');
}

echo 'Data in the cluster: [' . $client->get('myKey') . ']';

Make sure you have allowed the OUTPUT on port 11211

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top