Question

Unless I am missing something, I don't see a Multiple Set/Add overload that allows you to set multiple keys with an expiration.

var conn = new RedisConnection("server");

Dictionary<string,string> keyvals;

conn.Strings.Set(0,keyvals,expiration);

or even doing it with multiple operations

conn.Strings.Set(0,keyvals);
conn.Expire(keyvals.Keys,expiration);
Was it helpful?

Solution

No such redis operation exists - expire is not varadic. However, since the api is pipelined, just call the method multiple times. If you want to ensure absolute best performance, you can suspend eager socket flushing while you do this:

conn.SuspendFlush();
try {
    foreach(...)
        conn.Keys.Expire(...);
} finally {
    conn.ResumeFlush();
}

OTHER TIPS

Here is my approach:

var expireTime = ...
var batchOp = redisCache.CreateBatch();
foreach (...) {
    batchOp.StringSetAsync(key, value, expireTime);
}
batchOp.Execute();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top