StackExchange Redis ChannelPrefix Not Scoping Keys

2019-07-25 15:46发布

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条回答
虎瘦雄心在
2楼-- · 2019-07-25 16:33

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().

查看更多
登录 后发表回答