-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding ability to add prefixes to indexes for Searches #245
Conversation
@houstonhaynes @VagyokC4 - what are your thoughts? |
I'm confused by what you mean by "prefix". I took the term to mean "the part of the key that the index applies to" Where it looks like you interpret it as "the part of the name that goes before "-idx" Did I get that right? What I was originally talking included both the key-part that the index uses to discover/add records. I'll give an example: Say I have two customers in a Redis instance. One customer has the ID of "A" and the other "B". The keys I generate for the records for each respectively would be "Customer:A:[some-random-GUID]" and "Customer:B:[some-random-GUID]" Then I would create three indices, named "CustomerA-idx" "CustomerB-idx" and "CustomerAdmin-idx". CustomerA-idx would look for all keys with the partial key match to "Customer:A:" So in effect - the CustomerA ACL would be set to access only "CustomerA-idx" and so would be tenant limited to Customer "A" records. By extrapolation the CustomerB ACL would limit those users to only see Customer "B" keyed records. And finally - admins would have a CustomerAdmin ACL would would be able to see all keys because they're using an index which matches to the "Customer:*" partial key pattern. To be more specific - here's a sample of what I would set for the ACL for each company "user":
And here's what I'd set for the admin role:
I hope this clarifies what I'm trying to achieve. This means that both IndexName and Prefix need to be settable at run-time. |
@houstonhaynes - So the idea here is that the index's name would be computable given a prefix and the model, the format would now be [Document(StorageType = StorageType.Json, Prefixes = new string[]{"Customer"})]
public class Customer
{
[RedisIdField] public string Id { get; set; }
[Indexed] public string FirstName { get; set; }
[Indexed] public string LastName { get; set; }
} you would then be able to do something like: // connect
var provider = new RedisConnectionProvider("redis://localhost:6379");
var connection = provider.Connection;
connection.Execute("FLUSHDB"); // don't run this in production
var customers = provider.RedisCollection<Customer>();
var customersA = provider.RedisCollection<Customer>(false, 1000, "Customer:A");
var customersB = provider.RedisCollection<Customer>(false, 1000, "Customer:B");
customers.CreateIndex();
customersA.CreateIndex();
customersB.CreateIndex();
customersA.Insert(new Customer { FirstName = "Customer", LastName = "A" });
customersB.Insert(new Customer { FirstName = "Customer", LastName = "B" });
Console.WriteLine("Customers in customers collection");
foreach (var customer in customers)
{
Console.WriteLine($"Customer: {customer.Id} FirstName: {customer.FirstName}, LastName: {customer.LastName}");
}
Console.WriteLine("Customers in customersA collection");
foreach (var customer in customersA)
{
Console.WriteLine($"Customer: {customer.Id} FirstName: {customer.FirstName}, LastName: {customer.LastName}");
}
Console.WriteLine("Customers in customersB collection");
foreach (var customer in customersB)
{
Console.WriteLine($"Customer: {customer.Id} FirstName: {customer.FirstName}, LastName: {customer.LastName}");
} the customersA collection will generate this index:
Whereas customersB will create:
Then as you insert objects into redis via the prefixed collections, it will produces keys like:
and
Because the Prefix for the class As for ACLs, you can of course limit which index is visible to which user, you can also limit keys via prefix I think? (about 85% sure of that lol) so you can manage this by prefix. But of course as long as you are using the right collection for the right customer, the ACLs are really just a backup. |
eecc7a5
to
7a044da
Compare
Hi everyone, do you know when this new feature will be released? I'm trying to migrate from using |
Thank you, this is a great improvement. Will there be a release of this feature soon? |
Adds overload to to RedisCollection to enable you to create your own prefixes dynamically, this is helpful for cases such as #242 where someone might want to have an index per tenant with it's own set of prefixes.
Basically now you initalize a RedisCollection with a prefix, that prefix then becomes what your Collection uses to:
{prefix}:{id}