سؤال

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);
هل كانت مفيدة؟

المحلول

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();
}

نصائح أخرى

Here is my approach:

var expireTime = ...
var batchOp = redisCache.CreateBatch();
foreach (...) {
    batchOp.StringSetAsync(key, value, expireTime);
}
batchOp.Execute();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top