Dmitry Kotov
Dmitry Kotov

Reputation: 375

ServiceStack.Redis relationship between RedisSentinelWorker and RedisPubSubServer

Description:

I'm curious what is the relationship between RedisSentinelWorker and RedisPubSubServer.

From what I've observed the library holds at most 1 active sentinel connection even if there are more sentinel hosts available. That sentinel connection is wrapped in RedisSentinelWorker, which wraps RedisPubSubServer under the hood.

What bothers me is that RedisSentinelWorker and RedisPubSubServer might actually represent connections to two different sentinels.

Here is why this is happening:

var sentinel = new RedisSentinel(new[] {"localhost:26380", "localhost:26381", "localhost:26382"});
var manager = sentinel.Start();

By the time we reach ServiceStack.Redis.RedisSentinelWorker.BeginListeningForConfigurationChanges the listening is supposed to start on sentinel localhost:26380. But when you reach ServiceStack.Redis.RedisPubSubServer.RunLoop - an actual sentinel that we use to establish pub/sub connection to is actually localhost:26381.

This is happening because of the round robin mechanism underneath the ClientsManager object we pass to RedisPubSubServer. Before the pub/sub connection is established we actually call ClientsManager twice.

  1. Inside of ServiceStack.Redis.RedisPubSubServer.Init to get server time. It returned localhost:26380.
  2. Inside of ServiceStack.Redis.RedisPubSubServer.RunLoop to actually establish the subscription. It now returns localhost:26381.

So my question is: is how this works now intentional or this is a bug?

Upvotes: 1

Views: 87

Answers (1)

mythz
mythz

Reputation: 143399

RedisPubSubServer provides a managed Pub/Sub Server for processing Redis Pub/Sub messages.

RedisSentinelWorker uses RedisPubSubServer to listen for sentinel messages, it was looking at connecting to any of the available active Sentinel Hosts for Sentinel message events but I can see how it would be more intuitive to only look at the sentinel host the worker is currently configured with so I've changed the behavior in this commit which will be available in the next v5.11 release.

Upvotes: 1

Related Questions