Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created February 7, 2013 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msarchet/4728459 to your computer and use it in GitHub Desktop.
Save msarchet/4728459 to your computer and use it in GitHub Desktop.
Cleanly update an item in a ServiceStack.Redis.IRedisList<T>
/*
Sometimes you need to just udpate something and assure that it happens
*/
public static class GenericReplaceLock
{
public static void Replace<T>(this IRedisClient Client, string key, T old, T newer)
{
using (var redis = Client.As<T>())
using (var transaction = redis.CreateTransaction())
{
transaction.QueueCommand(r => r.Lists[key].Remove(old));
transaction.QueueCommand(r => r.Lists[key].Add(newer));
transaction.Commit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment