1

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);
Chad Grant
  • 44,326
  • 9
  • 65
  • 80

2 Answers2

1

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();
}
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thanks ;) btw ... inconsistency I also noticed was that Set takes a long for expiry and Expire takes an int. – Chad Grant Dec 11 '13 at 23:13
  • It would also be nice to have the Multi-Get operation return a Dictionary so I can figure out which keys don't exist. – Chad Grant Dec 11 '13 at 23:16
  • @ChadGrant there is a multi-get `GetString` that takes a `string[]` of the keys and returns a `string[]` of the values - they are matched by index – Marc Gravell Dec 12 '13 at 06:58
0

Here is my approach:

var expireTime = ...
var batchOp = redisCache.CreateBatch();
foreach (...) {
    batchOp.StringSetAsync(key, value, expireTime);
}
batchOp.Execute();