0

We have used redis cache in web api project to add information on to the cache.

The same redis cache connection string we are using in Azure web Job to take the cached data stored in web api project.But we are not getting the cached data in Azure web Job as it is returning null data for that region.

 <add key="RedisCacheStorageHours" value="8" />

Please Help.

1 Answers1

0

As I have tested, when you fail to connect to the Redis Cache, it doesn't give any error prompt, and its vault is null.

Here is an article about Use Azure Cache for Redis with a .NET application. The detailed steps are as below:

1.Set connectionstring in app.config:

<appSettings>
    <add key="CacheConnection" value="<cache-name>.redis.cache.windows.net,abortConnect=false,ssl=true,password=<access-key>"/>
</appSettings>

2.Install StackExchange.Redis package.

3.Use the following code to retrieve cache data.

static void Main(string[] args)
{
    IDatabase cache = lazyConnection.Value.GetDatabase();
    string cacheCommand = "GET Message";
    Console.WriteLine("\nCache command  : " + cacheCommand + " or StringGet()");
    Console.WriteLine("Cache response : " + cache.StringGet("Message").ToString());
    lazyConnection.Value.Dispose();
 }

After testing fine on local, you could publish the console app as azure webjobs and it will take the cached data as you want.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30