What's the preferred way of using multiple databases with Sentinel?

Hello,

Is scenario supported? We have a multiple environments where we’d like to share the group of machines. I know we could come up with some type of naming convention so the keys don’t collide, but I’d prefer a separate database.

After digging a bit into the source code I also can’t infer if Sentinel returns a pooled manager or not. e.g.

          var sentinelHosts = container.Resolve<IAppSettings>()
            .GetString("Redis:Sentinel:Hosts").Split(',');
            var sentinel = new RedisSentinel(sentinelHosts, "master");
            var redisManager = sentinel.Start();
            container.Register(redisManager);

because I have a hunch that changing the database will be a the responsibility of the client manager.

Update1: Reading the source code, I found this in the RedisSentinelWorker…doesn’t look good for the home team

    public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string masterName)
    {
        this.redisSentinel = redisSentinel;
        this.redisManager = redisSentinel.RedisManager;
        this.masterName = masterName;

        //Sentinel Servers doesn't support DB, reset to 0
        var sentinelEndpoint = host.ToRedisEndpoint(defaultPort:RedisNativeClient.DefaultPortSentinel);

        this.sentinelClient = new RedisClient(sentinelEndpoint) { Db = 0 };
        this.sentinelPubSubClient = new RedisClient(sentinelEndpoint) { Db = 0 };
        this.sentinelSubscription = this.sentinelPubSubClient.CreateSubscription();
        this.sentinelSubscription.OnMessage = SentinelMessageReceived;

        if (Log.IsDebugEnabled)
            Log.Debug("Set up Redis Sentinel on {0}".Fmt(host));
    }

Thank you,
Stephen

You can specify to use a different Database with Sentinel by specifying a HostFilter, e.g:

var sentinel = new RedisSentinel(sentinelHosts, masterName) {
    HostFilter = host => "{0}?db=1".Fmt(host)
}

The connection string you give the Sentinel Hosts is only for the Sentinel Servers. This is how you can change the connection string for individual RedisClient instances.

The code you’re looking at is for connecting to Sentinel servers which doesn’t have a concept for Different databases neither does RedisCluster for that matter, Salvatore regrets having implement multiple databases in the first place as it added unnecessary complexity to the Redis code-base where it would’ve made more sense for everyone to use a different redis-server process to partition data. On that note Sentinel supports monitoring multiple master/slave groups you just have to give it a different masterName in redis.conf and sentinel.conf so it knows which master/slaves belongs to which masterName group - which would be the preferred approach given he recommends against using different databases.

So then it’s feasible to have a apphost/process use one of the databases , say number 3, and both Cache and Session will work and be none the wiser. Perfect!