Skip to content

Commit

Permalink
Implemented ExecuteGet (multi-get) with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jzablocki committed Apr 16, 2012
1 parent a15cbab commit d5af820
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Enyim.Caching.Tests/MemcachedClientGetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public void When_Generic_Getting_Existing_Item_Value_Is_Not_Null_And_Result_Is_S
Assert.That(getResult.Value, Is.EqualTo(value), "Actual value was not expected value: " + getResult.Value);
}

[Test]
public void When_Getting_Multiple_Keys_Result_Is_Successful()
{
var keys = GetUniqueKeys().Distinct();
foreach (var key in keys)
{
Store(key: key, value: "Value for" + key);
}

var dict = _Client.ExecuteGet(keys);
Assert.That(dict.Keys.Count, Is.EqualTo(keys.Count()), "Keys count did not match results count");

foreach (var key in dict.Keys)
{
Assert.That(dict[key].Success, Is.True, "Get failed for key: " + key);
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions Enyim.Caching.Tests/MemcachedClientTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ protected string GetUniqueKey(string prefix = null)
"unit_test_" + DateTime.Now.Ticks;
}

protected IEnumerable<string> GetUniqueKeys(string prefix = null, int max = 5)
{

var keys = new List<string>(max);
for (int i = 0; i < max; i++)
{
keys.Add(GetUniqueKey(prefix));
}

return keys;
}

protected string GetRandomString()
{
var rand = new Random((int)DateTime.Now.Ticks).Next();
Expand Down
1 change: 1 addition & 0 deletions Enyim.Caching/Memcached/IMemcachedResultsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IMemcachedResultsClient
{
IGetOperationResult ExecuteGet(string key);
IGetOperationResult<T> ExecuteGet<T>(string key);
IDictionary<string, IGetOperationResult> ExecuteGet(IEnumerable<string> keys);

IGetOperationResult ExecuteTryGet(string key, out object value);

Expand Down
17 changes: 17 additions & 0 deletions Enyim.Caching/MemcachedClient.Results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ public IGetOperationResult<T> ExecuteGet<T>(string key)
return result;
}

/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
/// <param name="keys">The list of identifiers for the items to retrieve.</param>
/// <returns>a Dictionary holding all items indexed by their key.</returns>
public IDictionary<string, IGetOperationResult> ExecuteGet(IEnumerable<string> keys)
{
return PerformMultiGet<IGetOperationResult>(keys, (mget, kvp) =>
{
var result = GetOperationResultFactory.Create();
result.Value = this.transcoder.Deserialize(kvp.Value);
result.Cas = mget.Cas[kvp.Key];
result.Success = true;
return result;
});
}

#endregion

#region [ Mutate ]
Expand Down

0 comments on commit d5af820

Please sign in to comment.