Tanmay
Tanmay

Reputation: 351

Stackexchange.Redis support for XX|NX|CH?

Does stackexchange.redis support the NX and other related switches from ZADD? I had a look in the documentation, unit tests and code but couldn't find any reference to it. Would be great if someone could shed some light on how to implement this if its not supported

Upvotes: 1

Views: 1496

Answers (1)

thepirat000
thepirat000

Reputation: 13124

As far as I know this is not implemented on the latest stable version of SE.Redis.

But you can still use ScriptEvaluate to execute arbitrary redis commands, for example:

var ctx = ConnectionMultiplexer.Connect("...");
var db = ctx.GetDatabase();
db.ScriptEvaluate("return redis.call('zadd', KEYS[1], unpack(ARGV))", 
    new RedisKey[] { "key" }, 
    new RedisValue[] { "NX", 12.34, "member" });

Also you can use CachingFramework.Redis library that is built on top of SE.Redis, since the SortedSet commands already handles the NX/XX switches, for example:

var context = new CachingFramework.Redis.Context();
var sset = context.Collections.GetRedisSortedSet<string>("key");
sset.Add(12.34, "member", When.NotExists);

Upvotes: 1

Related Questions