thepirat000 / CachingFramework.Redis

Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Other
287 stars 52 forks source link

Tag Prefix Feature #78

Closed Marty-Jones closed 2 years ago

Marty-Jones commented 2 years ago

I would like to request the ability to specify a custom tax prefix instead of the hardcoded value ":$tag$:{0}".

There are situations where we have application data that is prefixed and we would like the tags associated with that data to be prefixed as well. Basically allow the user to specify the tag prefix "{0}:{1}" so 0 would be what the override value is or default to ":$tag$".

thepirat000 commented 2 years ago

Just to be sure I'm understanding correctly, could you add a code sample on how are you expecting to configure this prefix value?

Do you need different tag prefixes on the same redis cluster? That could be a problem for example for methods like GetAllTags or IsStringKeyInTag.

Maybe something like this:

// Override prefix on start-up:
RedisContext.DefaultSerializer.TagPrefix = "{tag}:";
// Or maybe just a global setting:
RedisContext.TagPrefix = "{tag}:";

So the tag keys becomes, for example, {tag}:blue or {tag}:red

Wondering if this should be on the serializer or not

Marty-Jones commented 2 years ago

My use case is that I want to group tags for a given application. So my current configuration is that I prefix all my "keys" within the cluster with the application prefix. This allows me to remove all items for a given application by searching for keys that begin with that specific prefix.

My initial thought would be to allow the prefix to be set when you create a RedisContext (either a constructor argument or a setter to allow you to set an override TagPrefix). This would allow you to have different prefixes for each RedisContext that you would instantiate. In my case I would only need one RedisContext per application.

I can setup a Pull request if that would help.

thepirat000 commented 2 years ago

Yes, you can create a pull request.

But I think it will be better to have the configuration as part of the serializer. maybe adding the possibility to configure a Prefix and a Postfix for the tag keys

thepirat000 commented 2 years ago

Here is a pull request that adds the TagPrefix and TagPostfix to the serializer:

https://github.com/thepirat000/CachingFramework.Redis/pull/79

Marty-Jones commented 2 years ago

That works for me. This will accomplish what I need to do!

thepirat000 commented 2 years ago

This was added to version 14.1.0, please upgrade your references and re-test

Marty-Jones commented 2 years ago

Thank you for the quick turn around! I will test this first thing in the morning.

Marty-Jones commented 2 years ago

I have verified that the change is working as expected.

Thank you for making this change!