Redis Cache Implementation for Azure Functions

using System.Net;
using StackExchange.Redis;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
  // Connecting to Redis
  var connString = System.Configuration.ConfigurationManager.ConnectionStrings["RedisConnectionString"].ConnectionString;
  var cache = ConnectionMultiplexer.Connect(connString).GetDatabase();
   
  // Redis usage
  var currentData = (int)cache.StringGet("ExecutionCount");
  currentData++;
  cache.StringSet("ExecutionCount", currentData);
 
  return req.CreateResponse(HttpStatusCode.OK, "Execution count: " + currentData);
}

Add Comment