Getting RedisTimeoutException on Azure Cache for Redis

320 Views Asked by At

I have a web API on Azure App Service using .Net 7 and Azure Cache for Redis. Recently, it has been throwing RedisTimeoutException errors. The following are some of the exceptions:

StackExchange.Redis.RedisTimeoutException: Timeout awaiting response (outbound=0KiB, inbound=0KiB, 5813ms elapsed, timeout is 5000ms), command=EXISTS, next: EXISTS xxxx, inst: 0, qu: 0, qs: 0, aw: False, bw: SpinningDown, rs: ReadAsync, ws: Idle, in: 0, last-in: 725, cur-in: 0, sync-ops: 112, async-ops: 6861, serverEndpoint: xxxx, conn-sec: 780.17, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: xxx(SE.Redis-v2.6.122.38350), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=4,Free=32763,Min=1,Max=32767), POOL: (Threads=5,QueuedItems=4,CompletedItems=270390,Timers=48), v: 2.6.122.38350

At first, I suspected that this was due to a noisy neighbor, as the cache was running on the Standard C0 tier. However, after scaling up to the C1 tier, the issue still persists. Before scaling, the Redis server load was always below 50%, but after scaling, it has consistently been hitting 100%.

1

There are 1 best solutions below

0
SaiVamshiKrishna On

The error message you provided, StackExchange.Redis.RedisTimeoutException: Timeout awaiting response, indicates that your application is timing out while waiting for a response from the Redis server

Created a console application in C# that interacts with a Redis cache and uses the EXISTS command to check if a key exists in the cache

using System;
using StackExchange.Redis;

class Program
{
    static void Main()
    {
        // Replace these with your Redis server details
        string redisConnectionString = "Your Redis ConnectionString"; // Redis server address

        // Create a Redis ConnectionMultiplexer
        ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(redisConnectionString);

        // Get a reference to the Redis database
        IDatabase db = redis.GetDatabase();

        // Key to check for existence
        string keyToCheck = "myKey";

        // Use the EXISTS command to check if the key exists
        bool keyExists = db.KeyExists(keyToCheck);

        if (keyExists)
        {
            Console.WriteLine($"Key '{keyToCheck}' exists in the Redis cache.");
        }
        else
        {
            Console.WriteLine($"Key '{keyToCheck}' does not exist in the Redis cache.");
        }

        // Close the Redis connection
        redis.Close();
    }
}

Result

Above Code check whether Value: myKey is present in cache or not enter image description here

You can also refer to this Link