StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.88k stars 1.51k forks source link

Accept key prefix in connection string #2676

Open alrz opened 6 months ago

alrz commented 6 months ago

using WithKeyPrefix must be supported in each library that depends on SE.R. It would really help if we could pass the prefix in the connection string just like defaultDatabase.

NickCraver commented 6 months ago

@mgravell I remember there was a reason we never implemented this, including when Stack used it and channelPrefix was added...but I can't recall why now, any chance you remember?

I'm admittedly not sure how the behavior would with the existing methods kick in, e.g. would they concat an additional prefix? That's likely counter to what's wanted because "starts with" it usually the intuitive behavior. For example if the base was prefix1 then the key is prefix1:key, but if .WithKeyPrefix() is called on the now-default IDatabase say with prefix2 would the result be:

Things like this come into play if there's some global default. Each of the above options is arguable, but not intuitive, and the last could allow an "escape" is the intent is to encapsulate keys inside an external prefix. It may be just because of the above questions that we leave it to downstream libraries, because there are behavioral decisions in supporting it.

alrz commented 6 months ago

Note that the reason for this is that clients may only access to a specific key prefix so I think the one specified in connection string should be considered the global default (not overridable)

NickCraver commented 6 months ago

@alrz Understood - I assumed the same, but all the questions remain :) What specific thing are you using that doesn't support this today?

alrz commented 6 months ago

I've filed this for Orleans as well. This was kind of blocking due to the keyspace perm but didn't find it in either side.

mgravell commented 6 months ago

If I may reframe/restate, is this correct?

alrz commented 6 months ago

That's exactly correct, I believe.

NickCraver commented 6 months ago

If the intent is ACLs, then it seems like the intended behavior wouldn't be something like "globalKeyPrefix", which always comes first for all commands (would it apply to channels? Or no because there exists an option for that which could be set too?)