A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/StackExchange/StackExchange.Redis/issues/2016 below:

RedisCommandException for "Command cannot be issued to a replica" is difficult to handle · Issue #2016 · StackExchange/StackExchange.Redis · GitHub

Hey all,

I work on a large service using Azure Redis Premium. Our normal pattern for using Redis is something like:

try{
db.StringGet()
}
catch (RedisException)
...
catch (TimeoutException)
...

This works pretty well, but we have some low level of failures that look like this:

RedisCommandException: Exception: 'Command cannot be issued to a slave: UNLINK '

(In newer versions of the SDK, it says "Command cannot be issued to a replica" instead.)

This is a reasonable error, but I am not intentionally targeting a replica. I assume Azure has failed over from under me, changing the recipient to a replica, while it was primary when the command was sent.

I would like to just treat this as a transient failure, log it, and move on with life as though it were a timeout. This is a little tricky though because the exception is RedisCommandException (which doesn't inherit from RedisException). I am hesitant to catch and handle RedisCommandException, because I understand that it usually means the command is bad, like maybe a bad LUA script.

Basically, I'd like some way to differentiate this exception so I can treat it as transient.

My suggestion is to make this case a RedisException or RedisServerException, but I'm open to other resolutions, including being told that I should be catching some different set of exceptions as transient.

Thanks,
Adam


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4