Search code examples
c#.netredisstackexchange.redisamazon-elasticache

StackExchange.Redis.RedisServerException: ERR unknown command 'unwatch' when calling ITransaction.ExecuteAsync()


I am using StackExchange.Redis library, connecting to AWS ElastiCache for Redis (Serverless).

Example code:

ITransaction transaction = db.CreateTransaction();
transaction.AddCondition(Condition.StringEqual("key:{id1:id2:id3}:stats:sum", "100"));
transaction.ListLeftPushAsync("key:{id1:id2:id3}:stats:samples", "20");
transaction.StringSetAsync("key:{id1:id2:id3}:stats:sum", "120");
transaction.StringSetAsync("key:{id1:id2:id3}:stats:updated_at", "1707808358");
await transaction.ExecuteAsync();

I am getting the following error:

StackExchange.Redis.RedisServerException: ERR unknown command 'unwatch', with args beginning with:

I can not seem to reproduce this issue locally, so perhaps it's related to the cluster mode or some other aspect of Serverless ElastiCache?


Solution

  • Apparently (news to me), serverless ElastiCache doesn't support watch or unwatch - source. That means you can't use constraints (but the transaction itself should work, without the constraints). If available, Lua (ScriptEvaluate) might be a better option, anyway (even if constraints were available) - as this is usually easier to get right, and doesn't interrupt the multiplexer (checking constraints requires waiting for the result, which means paying latency rather than pure pipelining, and since this is inside the transaction, all other operations must be held for that time).