Caching with ElastiCache for Redis and AWS Ubuntu Server

Applications need to access data quickly, and as your applications grow to more users, they’ve to scale without overloading your distributed and backend systems. Caching can help with an in-memory cache; you can achieve sub-millisecond response times, manage spikes in demand and cost-effectively scale your application infrastructure. Memcached and Redis is a popular open-source in-memory data store developers use as high-performance caches to speed up applications. When you store your workloads in memory instead of on your local disk, Redis or Memcached can retrieve your data simultaneously in the key-value store.

With the cluster mode enabled, our Redis cluster gains enhanced managed memory and high availability. You can start your Redis cluster small and easily scale your Redis data as your application grows. We can also increase our read capacity by setting up replicas in different availability zones.

In this tutorial, I'll show you how to configure a Redis cluster with ElastiCache and Ubuntu Server.

Prerequisites


Getting Started

  • In the AWS Console, search for Amazon ElastiCache, and click on it. It provides a high-performance, scalable, and cost-effective caching solution. At the same time, it helps remove the complexity associated with deploying and managing a distributed cache environment.

  • Next, in the dashboard, click on Get Started. It’ll bring out the ElastiCache dashboard.
  • Click on Create Cluster; you’ve two options: a Redis cluster or a Memcached cluster. In this tutorial, we’ll be using the Redis Cluster.

  • Next, in your cluster, set Cluster mode to Enabled, and enter the Name and Description of your cluster.

  • Configure your Engine version, Parameter groups, Node type, and Replicas per shard. Most of the values are already defined by default. You can increase the number of shards and the replicas per shard.

  • Configure your subnet group, network type, and VPC for your Redis Cluster.

  • Add a subnet group tag if you want to, and configure your slots and keyspaces for your Redis cluster. Your keyspaces are your internal dictionary and storage that your Redis cluster manages, in which all your keys are stored.

  • Click on Next to encrypt your data at rest or in transit. Enabling encryption at rest encrypts your data on the disk, and encryption in transit encrypts your data between the service and the client.

  • Next, configure your security groups, enable automatic backups, and set up your maintenance window if you want to.

  • Next, review your settings and click on Create. In your dashboard, you can see that your Redis cluster is creating in progress.

  • Next, we’ll launch an EC2 instance to access the ElastiCache Redis instance we created. Enter the Name and Description of your instance to set it up.

  • You can use an existing key pair or create a new key pair.

  • Next, launch your EC2 instance.  In your instance dashboard, you can see your EC2 instance with your launch log.

  • Click on Connect EC2 instance to SSH into your EC2 instance.

  • In your terminal on your local machine, ssh into your instance, and enable root permissions.

Successfully, we’re able to access the EC2 instance.

  • Before we install Redis on our EC2 instance, let's update the Ubuntu package manager using the sudo apt update command.

  • Install Redis on your Ubuntu server.

  • Get the Configuration Endpoint from your Redis cluster instance description.

Before you connect to your Redis instance, make sure your Redis port is opened on your EC2 instance security group. Add a custom port in your inbound rules for port 6379.

  • Next, Connect to your Redis instance cluster. Before connecting to your Redis instance using the Redis command, ensure you’ve exposed port 6379 on your Redis instance cluster. In your terminal, enter the redis-cli -c -h workflow-redis.j51gu9.clustercfg.use2.cache.amazonaws.com -p 6379 command.

  • Now you’re connected to your Redis instance, play around with some Redis commands and settings. For example, you can set a tag, name, or value and eventually get the same value back on your CLI.

  • Set other tags and values.

  • Set and get different secrets.

  • List out your keys using keys *

  • Once you’re done with your Redis instance on server you can delete your Redis cluster, and EC2 instance if you’re not using them anymore.

Conclusion

AWS ElastiCache boosts the performance of your databases by retrieving data from high throughput and low latency in-memory data stores. ElastiCache gives you a sub-millisecond response time and has no upfront costs. ElastiCache for Redis supports Amazon VPC endpoints and requests, helping you isolate and secure your data. CTO.ai Open-source workflows for AWS Redis and ElastiCache feature auto-discovery help developers save time by simplifying how an application connects to a cluster, and It’s easy to scale your ElastiCache cluster to handle more data and operations.