Pregunta

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);
¿Fue útil?

Solución

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

Otros consejos

Here is my approach:

var expireTime = ...
var batchOp = redisCache.CreateBatch();
foreach (...) {
    batchOp.StringSetAsync(key, value, expireTime);
}
batchOp.Execute();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top