Skip to content

Commit

Permalink
Allow calling DeleteAll<T> when there are no ids for T
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Sep 21, 2012
1 parent 8262897 commit 1aaca5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/ServiceStack.Redis/Generic/RedisTypedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,21 @@ public void DeleteByIds(IEnumerable ids)
if (ids == null) return;

var urnKeys = ids.ConvertAll(t => client.UrnKey<T>(t));
this.RemoveEntry(urnKeys.ToArray());
client.RemoveTypeIds<T>(ids.ConvertAll(x => x.ToString()).ToArray());
if (urnKeys.Count > 0)
{
this.RemoveEntry(urnKeys.ToArray());
client.RemoveTypeIds<T>(ids.ConvertAll(x => x.ToString()).ToArray());
}
}

public void DeleteAll()
{
var urnKeys = client.GetAllItemsFromSet(this.TypeIdsSetKey);
this.RemoveEntry(urnKeys.ToArray());
this.RemoveEntry(this.TypeIdsSetKey);
if (urnKeys.Count > 0)
{
this.RemoveEntry(urnKeys.ToArray());
this.RemoveEntry(this.TypeIdsSetKey);
}
}

#endregion
Expand Down
11 changes: 7 additions & 4 deletions src/ServiceStack.Redis/RedisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public void Delete<T>(T entity)

public void DeleteByIds<T>(ICollection ids) where T : class, new()
{
if (ids == null) return;
if (ids == null || ids.Count == 0) return;

var urnKeys = ids.ConvertAll(UrnKey<T>);
this.RemoveEntry(urnKeys.ToArray());
Expand All @@ -658,9 +658,12 @@ public void Delete<T>(T entity)
{
var typeIdsSetKey = this.GetTypeIdsSetKey<T>();
var ids = this.GetAllItemsFromSet(typeIdsSetKey);
var urnKeys = ids.ConvertAll(UrnKey<T>);
this.RemoveEntry(urnKeys.ToArray());
this.Remove(typeIdsSetKey);
if (ids.Count > 0)
{
var urnKeys = ids.ConvertAll(UrnKey<T>);
this.RemoveEntry(urnKeys.ToArray());
this.Remove(typeIdsSetKey);
}
}

/// <summary>
Expand Down

0 comments on commit 1aaca5d

Please sign in to comment.