I would like to make a base clock using StackExchange.Redis. Where, if the key is changed during a transaction, it fails.
StackExchange.Redis reacted very well to the "Condition" api, which supports the concepts of "Equal" and "Existing".
This is really nice, but I would just like to do something like "No change." I could have missed something, but at this point it is not clear to me how to do this.
Is it possible to do something like:
var transaction = redis.CreateTransaction();
transaction.AddCondition(Condition.StringUnchanged("key"));
var val = transaction.StringGet("key");
transaction.StringSetAsync("key", val + 1);
transaction.Execute();
Or even a possible better version (which will do the same):
var transaction = redis.CreateTransaction();
var val = transaction.Watch("key");
transaction.StringSetAsync("key", val + 1);
transaction.Execute();
Currently, the only way to figure this out is to do something like:
var val = redis.StringGet("key");
var transaction = redis.CreateTransaction();
transaction.AddCondition(Condition.StringEqual("key", val));
transaction.StringSetAsync("key", val + 1);
transaction.Execute();
Which of the attempts to read the SE.Redis code I understand to translate something like (not sure how accurate it is):
val = GET key
WATCH key
MULTI
val = val + 1
SET key $val
checkVal = GET key
(then if checkVal != val:) UNWATCH
(otherwise:) EXEC
Redis, , . , - ?:
WATCH key
MULTI
val = GET key
val = val + 1
SET key $val
EXEC
, SE.Redis?