Skip to main content

Posts

Showing posts with the label Redis

RedisTimeoutException - High ‘in’ value

While investigating a performance issue we noticed that the we had a lot of RedisTimeoutExceptions inside our logs: 2019-12-15 16:26:57.425 +01:00 [ERR] Connection id "0HLS1E3OEP520", Request id "0HLS1E3OEP520:0000001D": An unhandled exception was thrown by the application. StackExchange.Redis.RedisTimeoutException: Timeout performing PEXPIRE CookiesStorageAuthSessionStore-4a07a1bb-04e0-442d-9223-e1612967bf2b, inst: 2, queue: 8, qu: 0, qs: 8, qc: 0, wr: 0, wq: 0, in: 14411, ar: 0, clientName: SERVER1, serverEndpoint: Unspecified/redis:6379, keyHashSlot: 4822 (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts ) You would think that this indicates there is a performance issue in Redis but this turned out not to be the case. Let’s have a second look at the error message and especially the strange parameters: inst: 2, queue: 8, qu: 0, qs: 8, qc: 0, wr: ...

The type 'StackExchange.Redis.IDatabase' exists in both StackExchange.Redis and StackExchange.Redis.StrongName.

After switching from the old packages.config file to the PackageReference inside my csproj file, I got the following error message when trying to build: The type 'StackExchange.Redis.IDatabase' exists in both 'c:\packages\StackExchange.Redis.1.0.481\lib\net45\StackExchange.Redis.dll' and 'c:\packages\StackExchange.Redis.StrongName.1.0.481\lib\net45\StackExchange.Redis.StrongName.dll' However when I looked at the referenced packages I only saw a package reference to StackExchange.Redis… The problem was that the StackExchange.Redis nuget package was referenced both directly using a PackageReference and indirectly through a reference with the Microsoft.Web.RedisSessionStateProvider . After removing the direct reference to StackExchange.Redis, the build error disappeared.

ASP.NET Core SignalR–Add a Redis backplane

The moment that you start using SignalR, better sooner than late you should add a backplane to allow scaling out your backend services. At the moment of writing I’m aware of only 2 possible backplanes: The Azure SignalR service: in this case you are moving your full SignalR backend logic to Azure. Azure will manage the scale out for you. Redis backplane: in this case you are still running the SignalR backend yourself and only the data is replicated through Redis In their official documentation Microsoft refers to the Microsoft.AspNetCore.SignalR.StackExchangeRedis nuget package, but I’m using the (official?) Microsoft.AspNetCore.SignalR.Redis package. Here are the steps you need to take to use it: Add the Microsoft.AspNetCore.SignalR.Redis package to your ASP.NET Core project. In your startup class add the AddRedis line to your SignalR middleware configuration: Add the Redis connectionstring to your configuration. That’s all! Remark: Don’t for...

Microsoft Azure–Redis Cache Advisor

With the latest Azure update, Microsoft gave some love to the Redis Cache implementation. One of the things that got added is the Redis Cache Advisor . On your Azure Redis Cache instance, you’ll find a new Recommendations blade. This blade is empty in normal situations but if any special condition occurs, like high memory usage, high server load, etc… an alert is displayed on the Redis Cache blade and the Recommendations blade will be filled with extra information on how to fix this(most of the time buy a bigger box ). More information: https://azure.microsoft.com/en-us/documentation/articles/cache-configure/#redis-cache-advisor

Reconfigure Redis cache

It is possible to reconfigure your Redis cache from a Redis client without stopping or restarting the service by executing the CONFIG SET command: CONFIG SET maxmemory 2mb However be aware that this will not change the redis.conf file and that your change is gone with the next restart of Redis. To persist your configuration change, you can use the CONFIG REWRITE command: CONFIG REWRITE This will update all fields in your redis.conf file that don’t match the current configuration.

ASP.NET RedisSessionStateProvider - ERR unknown command 'EVAL'

After switching to the RedisSessionStateProvider   our ASP.NET application started to fail with the following error message: ERR unknown command 'EVAL' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: StackExchange.Redis.RedisServerException: ERR unknown command 'EVAL' On StackOverflow I found that it could be related to an older Redis version as the EVAL command was introduced in Redis 2.6. A quick check using the INFO command revealed that I was indeed using an older version: After upgrading to a more recent version, the error went away!

Trying the ASP.NET session state provider for Redis

After the news about the support for Redis on Windows Azure , Microsoft also announced a preview release of an ASP.NET session state provider for Redis . I am using the ServiceStack.Redis client for a long time, but I wanted to give it a shot and switched to the Microsoft.Web.RedisSessionStateProvider . However when I tried to use it, ASP.NET returned a yellow screen of death and showed the following error message: “Could not load file or assembly ‘StackExchange.Redis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46’ or one of its dependencies. The system cannot find the file specified.” The RedisSessionStateProvider is using the StackExchange.Redis client behind the scenes. As I installed it through NuGet, a newer version of the assembly was installed than expected. I fixed it by removing both NuGet Packages and first installing an older version of the StackExchange.Redis client.

ASP.NET Session State Providers

On my current project, I’m building an (ASP.NET MVC) web application. The plan is to deploy it to a web farm, so we had to replace the default in memory session state provider with a persistent one. We did our own performance tests comparing multiple possible solutions(SQL Session State, Redis, AppFabric Caching, …). The clear winner for us was  Redis . On SlideShare I found the following presentation confirming our own conclusions: Best performing asp.net session state providers from James Smith

Unofficial Redis for Windows

While looking for a good distributed cache solution in ASP.NET I felt in love with Redis , a fast and feature rich key-value store solution. Unfortunately there is no official support(yet) for Redis on Windows. However the Microsoft Open Tech group created an unofficial port that works great! From the Redis site: The easiest way to install Redis is through NuGet : Open Visual Studio Create an empty solution so that NuGet knows where to put the packages Go the Package Manager Console : Tools –> Library Package Manager –>Package Manager Console Type Install-Package Redis-64 Go to the Packages folder and browse to the Tools folder. Here you’ll find the Redis-server.exe . Double click on it to start it. Redis is ready to use and start’s listening on a specific port(6379 in my case) Let’s open up a client and try to put a value into Redis. Start Redis-cli.exe . It already connects to the same port by default. Add a value by executing...