I wanted to go through the process of Redis running in AWS ElastiCache, since we have already covered Docker, Azure and plain vanilla Redis on Linux Server. Redis in AWS is under the umbrella of ElastiCache, where they offer Redis and Memcached.
There are different type of nodes offered by AWS ElastiCache:
- Standard
- Memory Optimized
I wont be going through the AWS offering, since AWS ElastiCache does a good job in explaining the differences between the Nodes.
First you will need to login to your AWS console, once logged in.
- Click on the Database Section of ElastiCache
- Select the Redis option on the Dashboard Menu
- Click on Create
- Select the node that you wish to use. Here I am just selecting small, but feel free to choose which one serves you the best.
- Select Redis and fill in the Name of the cluster and click Create.
- The process takes couple of minutes and will complete
- Once complete you will have a AWS domain name to connect to your Redis
AWS does not have the option to see ElastiCache Redis running within its Console like Azure, but one can connect to the endpoint the same way you connect to any Redis instance. As we saw there is a default hostname that is given by AWS to connect to, there is no secret/key pair provided like Azure. The access to the ElastiCache Redis instance is configured through AWS Security Groups, just like connecting to your RDS, EC2 instance.
There are two important items to note when running AWS ElastiCache with Redis:
- One cannot set password on the Redis instance. Any EC2 instance in the same security group will have access to your Redis instance.
- Connection to the ElastiCache instance is only within the region/VPC
When using StackExchange.Redis you can connect to the Redis instance, the information to connect to AWS ElastiCache is located in the AWS Console under your Redis instance running, one can use the sample code below to connect. (Note: AWS uses Security Group to connect)
1 2 3 4 5 6 7 8 9 10 11 12 |
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() => { return ConnectionMultiplexer.Connect("whatever-redis.bd1zu2.0009.usw2.cache.amazonaws.com:6379"); }); public static ConnectionMultiplexer Connection { get { return lazyConnection.Value; } } |
For other Redis topics
- Intro to Redis for .NET Developers
- Redis for .NET Developer – Connecting with C#
- Redis for .NET Developer – String Datatype
- Redis for .NET Developer – String Datatype part 2
- Redis for .NET Developer – Hash Datatype
- Redis for .NET Developer – Redis running in Docker
- Redis for .NET Developer – Redis running in Azure
How can I write and read from asp.net mvc using redis?
Hi Melissa,
Did you look at the first part of the connecting with Redis?
http://taswar.zeytinsoft.com/redis-for-net-developer-connecting-with-c/
Are you looking for an example of using it with asp .net mvc? I can write a blog post on it if you like let me know.
Hi ,
I have done all the setup for redis in aws console .
and also i have written the code in C# for caching but how to connect to the AWS console redis using c# code.
my code work fine when installing redis server locally .
please help me out to resolve this.
or if you can help me out to connect to redis using aws lambda
Hello,
Do you know if there are issues with Encrypted AWS Redis ElastiCache Cluster while connecting with a .Net Application Framework
Regards
Dhriti
Depends on what you mean by your question. There should not be any issue if you are using parameter store or KMS to encrypt the connection string and then to use it to connect to Redis, unless you are speaking of encrypting data in redis, If you can be more specific I might be able to help 🙂