Skip to content

Commit

Permalink
Fixed SearchKeys method returning keys with KeyPrefix included (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosboeing authored and imperugo committed Nov 27, 2018
1 parent e67711c commit ea173a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ public IEnumerable<string> SearchKeys(string pattern)
while (nextCursor != 0);
}

return keys;
return !string.IsNullOrEmpty(keyprefix) ? keys.Select(k => k.Substring(keyprefix.Length)) : keys;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,28 @@ public void SearchKeys_With_Key_Prefix_Should_Return_All_Database_Keys()
Assert.True(keys.Count() == 2);
}

[Fact]
[Fact]
public void SearchKeys_With_Key_Prefix_Should_Return_Keys_Without_Prefix()
{
var client = new StackExchangeRedisCacheClient(Serializer, "localhost", "MyPrefix__");

var values = Range(0, 10)
.Select(i => new TestClass<string>($"mykey{i}", Guid.NewGuid().ToString()))
.ToArray();

values.ForEach(x => client.Add(x.Key, x.Value));

var result = client.SearchKeys("*mykey*").OrderBy(k => k).ToList();

Assert.True(result.Count == 10);

for (int i = 0; i < result.Count; i++)
{
Assert.Equal(result[i], values[i].Key);
}
}

[Fact]
public void Exist_With_Valid_Object_Should_Return_The_Correct_Instance()
{
var values = Range(0, 2)
Expand Down

0 comments on commit ea173a9

Please sign in to comment.