Код: Выделить всё
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
Теперь CLASS_2 не является одноэлементным классом, и в приложении существует несколько его экземпляров. . CLASS_2 также подписывается на тот же канал, на который подписан CLASS_1. Но CLASS_2 также выполняет отмену подписки в какой-то момент во время работы программы.
Теперь проблема возникает, когда CLASS_2 выполняет отмену подписки, он также отменяет подписку активная подписка в CLASS_1, и я не хочу отказываться от подписки в CLASS_1.
Теперь я пытаюсь выяснить, не является ли использование ConnectionMultiplexer причиной проблемы ? Или любая информация будет полезна.
Заранее спасибо!

Подробнее здесь: https://stackoverflow.com/questions/723 ... ther-redis