locked
sample .net core microservices using Azure Redis cache RRS feed

  • Question

  • User1532000778 posted

    Hi,

    I need to create a simple asp.net core microservice's API program to demonstrate the use of Azure Redis cache. Basically i want two API's, one storing info on Azure redis and another fetching from it. 

    Can anyone please help me with a sample use case code? I've serached all over the internet and only found the .net core console application. Please point me in the right direction if you have any url. I've very little experience with .net. 

    Thanks.

    Friday, November 15, 2019 7:48 PM

Answers

  • User61956409 posted

    Hi Zubain,

    Welcome to ASP.NET forums.

    Can anyone please help me with a sample use case code? I've serached all over the internet and only found the .net core console application. Please point me in the right direction if you have any url. I've very little experience with .net. 

    You can install the StackExchange.Redis NuGet package in your application.

    https://www.nuget.org/packages/StackExchange.Redis/

    Then refer to the following sample code to get and set data into the cache.

    var lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
    {
        string cacheConnection = "{your_connectionstring_here}";
        return ConnectionMultiplexer.Connect(cacheConnection);
    });
    
    IDatabase cache = lazyConnection.Value.GetDatabase();
    
    cache.StringSet("Message", "Hello! The cache is working from ASP.NET Core!").ToString();
    
    var res = cache.StringGet("Message").ToString();

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 18, 2019 3:03 AM

All replies

  • User61956409 posted

    Hi Zubain,

    Welcome to ASP.NET forums.

    Can anyone please help me with a sample use case code? I've serached all over the internet and only found the .net core console application. Please point me in the right direction if you have any url. I've very little experience with .net. 

    You can install the StackExchange.Redis NuGet package in your application.

    https://www.nuget.org/packages/StackExchange.Redis/

    Then refer to the following sample code to get and set data into the cache.

    var lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
    {
        string cacheConnection = "{your_connectionstring_here}";
        return ConnectionMultiplexer.Connect(cacheConnection);
    });
    
    IDatabase cache = lazyConnection.Value.GetDatabase();
    
    cache.StringSet("Message", "Hello! The cache is working from ASP.NET Core!").ToString();
    
    var res = cache.StringGet("Message").ToString();

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 18, 2019 3:03 AM
  • User1532000778 posted

    Thanks Fei. This helps. 

    Tuesday, November 19, 2019 8:37 AM