redis-om-dotnet
redis-om-dotnet copied to clipboard
Add a prefix check
Hey guys, i think it would be required to add a prefix check as per https://github.com/RediSearch/RediSearch/issues/3079 this would prevent wrong object to be returned
Hey @zulander1 - so what's happening here? Do you have duplicated prefixes across models? You can already define custom prefixe(s) on your model, and by default, your prefix will be a fully-qualified class name - so that would be pretty hard to have duplicated
@slorello89 If you have a prefix: item and another one with item-a, when you search for it like this item.where(x=>x.name='testa') you will see that the data from item-a will be included
Yeah, so that's how prefixes are meant to work in Redis, we have configurable prefixes in Redis OM for just this reason. And Redis OM goes out of it's way to create complex prefixes by default (includes the fully-qualified class name) so that confusion like this can be avoided - not quite sure what the solution would be here.
@slorello89 So, this is the issue the index with the prefix Customer: results in 4 items, when it should be just one, so if I add a :, there is another issue, it create a double quote ::

Perhaps, we can do a check like this: if(!prefix.endWiths(":")) prefix=prefix +":" ?
provider.Connection.CreateIndex(typeof(CustomerOne));
provider.Connection.CreateIndex(typeof(CustomerTwo));
provider.Connection.CreateIndex(typeof(CustomerThree));
provider.Connection.CreateIndex(typeof(CustomerFour));
var bob = new CustomerOne
{
Age = 35,
Email = "[email protected]",
FirstName = "Bob",
LastName = "Smith"
};
var linda = new CustomerTwo
{
Age = 35,
Email = "[email protected]",
FirstName = "Bob",
LastName = "Smith"
};
var james = new CustomerThree
{
Age = 35,
Email = "[email protected]",
FirstName = "Bob",
LastName = "Smith"
};
var jack = new CustomerFour
{
Age = 35,
Email = "[email protected]",
FirstName = "Bob",
LastName = "Smith"
};
var customerOne = provider.RedisCollection<CustomerOne>();
var customerTwo = provider.RedisCollection<CustomerTwo>();
var customerThree = provider.RedisCollection<CustomerThree>();
var customerFour = provider.RedisCollection<CustomerFour>();
await customerOne.InsertAsync(bob);
await customerTwo.InsertAsync(linda);
await customerThree.InsertAsync(james);
await customerFour.InsertAsync(jack);
var test1 = customerOne.Where(x => x.Age == 35);
var test2 = customerTwo.Where(x => x.Age == 35);
var test3 = customerThree.Where(x => x.Age == 35);
var test4 = customerFour.Where(x => x.Age == 35);
Console.WriteLine("Result 1: " + test1.Count());
Console.WriteLine("Result 2: " + test2.Count());
Console.WriteLine("Result 3: " + test3.Count());
Console.WriteLine("Result 4: " + test4.Count());
_ = Console.ReadLine();
[Document(Prefixes = new[] { "Customer" })]
public class CustomerOne
{
[Indexed(Sortable = true)] public string FirstName { get; set; }
[Indexed(Sortable = true)] public string LastName { get; set; }
[Indexed(Sortable = true)] public string Email { get; set; }
[Indexed(Sortable = true)] public int Age { get; set; }
}
[Document(Prefixes = new[] { "Customer-Two" })]
public class CustomerTwo
{
[Indexed(Sortable = true)] public string FirstName { get; set; }
[Indexed(Sortable = true)] public string LastName { get; set; }
[Indexed(Sortable = true)] public string Email { get; set; }
[Indexed(Sortable = true)] public int Age { get; set; }
}
[Document(Prefixes = new[] { "CustomerThree" })]
public class CustomerThree
{
[Indexed(Sortable = true)] public string FirstName { get; set; }
[Indexed(Sortable = true)] public string LastName { get; set; }
[Indexed(Sortable = true)] public string Email { get; set; }
[Indexed(Sortable = true)] public int Age { get; set; }
}
[Document(Prefixes = new[] { "CustomerFour" })]
public class CustomerFour
{
[Indexed(Sortable = true)] public string FirstName { get; set; }
[Indexed(Sortable = true)] public string LastName { get; set; }
[Indexed(Sortable = true)] public string Email { get; set; }
[Indexed(Sortable = true)] public int Age { get; set; }
}
@slorello89 any thoughts on this ?
@zulander1 - I investigated this a bit more - if you append a : to the end of your prefix - it does have a bit of a wonky key name but as far as I can tell - it works as expected - so I don't think this is strictly speaking necessary except for fixing a cosmetic issue?
I think adding a check as suggested would be a breaking change as it would change the way keys are stored, so anyone who is already using it would need to clean out and rebuild their entire model - not ideal.
Going to close this one out.