News
IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. ***
  Nov 21 2017 12:09PM     Amose
  0 Comments    473 Views  
Here is the simple steps to create amazon free account and sample code to store and get value using AWS Memcached.
Follow the below steps,
1. Create an account in Amazon (Free Tier)

2. Create an Memcached cluster in AWS Management Console

3. Create an EC2 Instance and Security Group

4. Create an Console Application to set and get key value in memcached

5. Hosting the Console Application into Amazon EC2 Instance

We will walk through the above steps one by one

1. Create an account in Amazon (Free Tier)
1. Navigate to the AWS Management Console



2. You will redirected to the following page



3. Click on "Create a new AWS Account"


Fill all the mandatory fields and click on continue
4. Once you click on Continue and you will need to fill all your contact information


And then click on "Create Account and Continue"
5. Once you click on "Create Account and Continue" and you will need to fill all your debit/credit card information to validate your card.

Note : Amazon will charge INR 2 on your card and this will be refunded once your card has been validated. Your bank may take 3-5 business days to show the refund. Mastercard/Visa customers may be redirected to your bank website to authorize the charge.

And then click on "Secure Submit"

After your successfull validation of credit/debit card and you can able to login AWS Management Console.


2. Create an Memcached cluster in AWS Management Console
1. Now you have already done with creating and AWS Account, You can click on this link to login to AWS Account



2. Once you have successfully logged in to your AWS Account and you will redirect to the following page



3. Now you need to create Memcached Cluster, Click on ElasticCache under Database

4. Then click on Memcached under ElasticCache Dashboard in the left pane. 5. Click on create and select Memcached as a Cluster engine. 6. Fill all Redis settings (Name the cluster, Description and Select Node type as "Cache.t2.micro" as shown in the following image.



Then click on Save.


And Finally click on "Create" at the bottom of the page. Once you have successfully created a memcache cluster and you will be able to see the cluster status as "Creating" as shown in the following image.


This will take few moments to change status to "Available". Now you have successfully created a Memcached cluster.


3. Create an EC2 Instance and Security Group

1. Now you have already done with creating and AWS Account and Memcached Cluster. Now you need to create EC2 Instance. Click on Services on top of the page and select EC2 under compute section.



2. Then click on "Instance" under Instances from the left pane. Now click on "Launch Instance" button on top of the page.

3. Now choose an Amazon Machine Image (AMI) as "Microsoft Windows Server 2016 Base" as shown in following image.


3. Select t2.micro (Free Tier Eligible) and click on Review and Launch.

4. Please review your instance launch details. You can go back to edit changes for each section. Click Launch to assign a key pair to your instance and complete the launch process.

When prompted, select "create a new key pair" and enter the key pair name in the below input field. The selected key pair will be added to the set of keys authorized for this instance. Now click on "Download Keypair" for future use (.pem file).

Once you have downloaded, you can click on "Launch Instance" to finish your EC2 instance creation.


This will take few moments to change status to "Creating" to "Running". Now you have successfully created a EC2 Instance. 5. Now click on Security Groups under Network & Security from the left pane and then click on "Create Security Group" . 6. When prompted,Enter Security Group Name, Description and select VPC. 7. Click on Inbound and create a rule for RDP to access Amozon Ec2 Instance using Remote Desktop. Select Source as "MY IP" as shown in the below image.



Click on Create at the bottom of the page.Now you are done with creating Security Group to authorize EC2 instance to access memcached.


3. Create an Console Application to set and get key value in memcached

1. Go to Visual Studio, create a console application and select Framework as 3.5 or higher version



2. Go to Nuget Packages and install "ElastiCacheCluster". Emyim will install automatically once ElastiCacheCluster has installed successfully.

3. Then, You need to include the following name space

using Enyim.Caching;

using Amazon.ElastiCacheCluster;

Sample Code
namespace ClusterConfigDemo
{
    class Program
    {
        protected static MemcachedClient memcacheClient = null;
        protected static ConnectionMultiplexer redisCon = null;

        static void Main(string[] args)
        {
            StoreAndGetValueUsingMemCached();
            //StoreAndGetValueUsingClusterRedis();
        }

        #region Memcached
        private static void initMemCached()
        {
            Console.WriteLine("Creating config...");
            ElastiCacheClusterConfig config = new ElastiCacheClusterConfig("mycachecluster3.hszzja.cfg.use2.cache.amazonaws.com", 11211);
            Console.WriteLine("Creating client...");
            memcacheClient = new MemcachedClient(config);
        }

        public static void StoreAndGetValueUsingMemCached()
        {
            if (memcacheClient == null)
            {
                initMemCached();
            }
            else
                Console.WriteLine("client has already created...");

            if (memcacheClient.Store(Enyim.Caching.Memcached.StoreMode.Set, "Demo""Hello World"))
            {
                Console.WriteLine("Stored to cache successfully");
            }
            else
            {
                Console.WriteLine("Did not store to cache successfully");
            }

            Object value;
            if (memcacheClient.TryGet("Demo"out value))
            {
                Console.WriteLine("Got the value: " + (value as string));
            }
            else
            {
                // Search Database if the get fails
                Console.WriteLine("Checking database because get failed");
            }

            memcacheClient.TryGet("Demo"out value);

            Console.Read();
        }
        #endregion

   
    }
}


3. Hosting the Console Application into Amazon EC2 Instance

1. Click on Services on top of the page and select EC2 under compute section.



2. You Could find a instance that is already running. Click on running instances as shown in following image.



3. Then click on "Connect" button on top of the page. When prompted, there you can see the username as "Administrator". To get Password, click on "Get Password" and upload your keypair (.pem file) which you have downloaded earlier and click on decrypt password.



4. Now you are done with creating username and password to make a remote desktop connection as shown in following image.



5. Go to "Run" type "mstsc" and enter.



Enter your Public DNS (IPV4) for running EC2 instance as computer name and Enter your username and password which you have created earlier then click on "Connect". Now, you are successfully logged in to the Amazon EC2 instance server.

6. Create a new folder and Paste your successfully build console application and run the application file.

7. Great, You are done with set and get value in AWS Elastic Cache using Memcached.
Hope this article will helps you to set and get value in AWS Elastic Cache using Memcached .Thanks.
BackToTop
Comments



 
Search
Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Nov 21 2017 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Nov 8 2017 10:26AM Posted By Pranav
Google URL Shortener in C#
Oct 26 2017 10:43AM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2017 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2017 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2017 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2017 10:20AM Posted By Micheal
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: