1

I'm trying to store multiple member-score values using Redis Booksleeve but the Booksleeve api doesn't seem to support this functionality.

conn.SortedSets.Add overload supports only single pairs of value - scores.

Do i miss something or this is on purpose or something that you forgot to implement?

Currently i'm updating my sorted set in a transaction loop like this:

foreach (ForumMessage message in messages)
{
    trans.SortedSets.Add(db, redisKey, message.id.ToString(), message.id);
}
trans.Execute();

Is the above the same as doing a ZADD with multiple member-score values from performance perspective?

PanKak
  • 133
  • 12

1 Answers1

1

It won't be quite as efficient:

  • it'll send the command and key multiple times
  • there is a good chance of emptying the output buffer repeatedly, which can cause packet fragmentation

But... it'll still be pretty fast.

There are hacky ways around the latter, including:

  • batching
  • suspend/resume flush (be very careful to use try/finally if you do this!)

However, you might want to know that StackExchange.Redis has a multi key/value SortedSetAdd method that does exactly what you want.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thanks I'try batching although the above code is included inside a transaction. Is batching necessary when I use transactions. – PanKak Mar 19 '14 at 19:29
  • @PanKak if you are using transactions, then indeed that is a form of batching - the second issue (packet fragmentation) should bot be an issue – Marc Gravell Mar 19 '14 at 19:31
  • Anyway I'm surprised with the new client, it looks quite promising. You just ruined my tognight's sleep actually :) I'll try it ASAP!!! – PanKak Mar 19 '14 at 19:33