You can use Redis Labs Memcached Cloud to cache application data. Memcached Cloud is a fully-managed service offering a variety of options for running Memcached.
Redis Labs offers a free tier that provides 30mb of cache storage.
To use Redis Labs Memcached Cloud:
- Sign up for a Redis Labs account.
- Create a Memcached Bucket using Memcached Cloud. For the lowest latency, create the Memcache bucket in the same region as your app.
- Edit the bucket and set a username and password.
- Note the bucket's
Installing a Memcached client library
Because Redis Labs uses SASL authentication, you need to use a Memcached client that supports the binary protocol and SASL authentication.
Install the MemJS package in your local environment
npm install --save memjs
Connecting to Redis Labs Memcache
Configure environment variables in your
app.flexible.yaml with the Memcached server
endpoint, username, and password for your Redis Labs Memcached bucket:
# The following env variables may contain sensitive information that grants # anyone access to your memcached service. Do not add this file to your source # control. env_variables: MEMCACHE_URL: your-memcache-url # If you are using a Memcached server with SASL authentiation enabled, # fill in these values with your username and password. MEMCACHE_USERNAME: your-memcache-username MEMCACHE_PASSWORD: your-memcache-password
Use the environment variables in your application code to configure a Memcached client:
// Environment variables are defined in app.yaml. let MEMCACHE_URL = process.env.MEMCACHE_URL; const mc = memjs.Client.create(MEMCACHE_URL);
Testing Memcached locally
If you are testing your app locally, you can still connect to your the Redis Labs Memcached bucket. However, you might want to run a local instance of Memcached to avoid interacting with production data.
To run a local Memcached instance, install a Memcached daemon in your OS:
Use the memcached package.
For Debian and Ubuntu derivatives:
apt-get install memcached
For Red Hat, CentOS, and Fedora, use
yum install memcached
For Linux Arch:
pacman -S memcached
Run it as a daemon (or check systemd for an automatic startup):
Mac OS X
brew install memcached
Run it as a daemon: