From Yii2 Memcached to Amazon Elasticache

Hello all,

I’m currently using Memcached for caching purposes and Yii2 supports this well.

I however want to switch to using AWS Elasticache, which is similar to Memcached in use (as long as you select the Memcached version, not Redis).

The reason is that it allows for easier scalability, without me having to manage Memcached in the individual Amazon instances.

However, if I point from the Yii2 config file to one of the ElasticSearch nodes, the server throws the error that it needs Memcached extension installed.

The whole point is to move away from that.

Does anybody know how to properly configure Yii2 so that it uses ElasticSearch instead and doesn’t need Memcached installed locally?

Thanks for your thoughts,

Alex

Hi Alex,

In your post you mention both Elasticache and ElasticSearch… I assume you just mean Elasticache…

My understanding of Elasticache is that it does not REPLACE Memcached, but works with it.

Elasticache is listed as a Memcached protocol compatible caching service.

What this means is that you still need Memcached installed, but you configure it to point to another

cache node instead of using the local machine as the cache node which is the default.

I have not used Elasticache, and it has been a while since I read over the docs, but here are a couple of

references you can look over for more information. Hopfully you have already seen them… ;)

http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html

http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.ConnectToCacheNode.Memcached.html

If you are still having problems, post with the Yii config you are using and the error message you are getting.

Also, please let us know when you get it working, and what you did. That way others can benefit from the knowledge.

-John

Hi Alex,

Were you ever able to get this working? I am working on this same issue at the moment and any advice that you could share would be much appreciated.

Best Regards,

Brad

Thanks for your help, yes indeed I understand now that Memcached has to be run locally as well.

I got it to work by following the Yii documentation, it was as simple as putting this in the components.php file (but can be in your Yii config file as well:

‘cache’ => [

    'class' => 'yii\caching\MemCache',


    'useMemcached' => true,


    'servers' => [


            [


                'host' => '[insert your AWS ElastiCache endpoint here, see your AWS Console for this]', //the location of the AWS ElastiCache node/cluster


                'port' => 11211,


                'weight' => 100


            ]


    ]


],

Thanks,

Alex