I have a Redis Connection Multiplexer class which I inject into two of my classes in the constructors.
public class CLASS_1 {
IConnectionMultiplexer _redis;
public CLASS_1(IConnectionMultiplexer redis){
_redis = redis
subscribeToChannel()
}
public subscribeToChannel(){
ISubscriber redisSubscriber = null;
redisSubscriber = _redis.GetSubscriber();
redisSubscriber.Subscribe("REDIS_CHANNEL",(channel, message) => {
// alway listen to the messages and perform the task
}
}
~ CLASS_1(){
redisSubscriber.Unsubscribe("REDIS_CHANNEL")
}
}
public class CLASS_2 {
IConnectionMultiplexer _redis;
public CLASS_2(IConnectionMultiplexer redis){
_redis = redis
}
public async executeCommand(){
ISubscriber redisSubscriber = null;
redisSubscriber = _redis.GetSubscriber();
/// perform a task
await redisSubscriber.SubscribeAsync("REDIS_CHANNEL", callBack);
/// perform a task
if (redisSubscriber != null) {
redisSubscriber.UnsubscribeAll()
// even if I do redisSubscriber.Unsubscribe("REDIS_CHANNEL") it still affects the other subscriptions
}
}
}
CLASS_1 is a singleton class and I am subscribing to a Redis channel in CLASS_1. Which means it only subscribe to the channel once. This class is always listening to the channel messages and perform some tasks when any message is received. The only time CLASS_1 unsubscribe to the channel is in the destructor.
Now, CLASS_2 is not a singleton class and there are few instances of it around the app. CLASS_2 also subscribes to the same channel subscribed in CLASS_1. But CLASS_2 also does an Unsubscribe at some point while the program is running.
Now, the problem arises when the CLASS_2 does an unsubscribe, it also unsubscribe the active subscription in the CLASS_1 and I do not want to unsubscribe the subscription in CLASS_1.
Now I am trying to figure if using the ConnectionMultiplexer is causing the issue? Or any information would be helpful.
Thank you in Advance! :)