I have channelPrefix declared in my connection string and I can tell by using ConfigurationOptions.Parse that it is correctly parsing out the channelPrefix from the string. I assumed that if I opened two instances of Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache where they each had the same connection string, except for different channelPrefix values, that Redis would maintain separate values for the keys of the two, but that is not what I am seeing. When I set a value to a key using one instance of RedisCache, I can retrieve the value from the other instance using the same key. Am I totally misunderstanding what channelPrefix does or is it possible that our Redis server is configured in a way that does not obey channelPrefix?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The concept of a "channel", and the RedisChannel
type in particular, relates to the pub/sub API, not the keyspace DB API. For what you want, you are after the .WithKeyPrefix()
extension method on the IDatabase
that you obtained with GetDatabase()
.