StackExchange / StackExchange/StackExchange.Redis

4 connections per multiplexer created when connecting to Azure Cache For Redis Server

Open
#2,685 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.2k
Forks
1.6k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Not sure if this is specifically a library issue or more of an azure redis server issue, but azure redis team suggested I file an issue here.

We noticed when we switched our apps from Microsoft.Caching.Redis (so essentially an old fork of SE.Redis) to SE.Redis that our connection count as reported by our azure redis instances increased by 33%. An important point here is that we're connecting to Azure Cache for Redis instances that have clustering enabled, but only one shard. My understanding is that this should mean each multiplexer our app creates should yield 3 connections: one discovery connection, one interactive connection, and one pubsub connection. But when I run the app below to connect to an ACR instance I actually see 4 connections from my machine when I run client list in the server console.

Configuration of the Azure Cache for Redis server is a P1 SKU with Clustering enabled and shard count of 1.

Here's the app (all code is just in this one file, and then it has a nuget dependency on Stackexchange.Redis

using StackExchange.Redis;

namespace RedisTest
{
    internal class Program
    {
        private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
        {
            return ConnectionMultiplexer.Connect("<connection string redacted>");
        });

        public static ConnectionMultiplexer Connection
        {
            get
            {
                return lazyConnection.Value;
            }
        }

        public async Task WriteToCache(string key, string value)
        {
            IDatabase cache = Connection.GetDatabase();
            await cache.StringSetAsync(key, value);
        }

        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            var prog = new Program();
            await prog.WriteToCache("testkey1", "val1");
            await Task.Delay(TimeSpan.FromMinutes(60));
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the one-file reproduction, especially ConnectionMultiplexer.Connect in the lazy connection and the WriteToCache entry point. Run it against a clustered, one-shard Azure Cache for Redis instance, then use the server's client list to compare the observed four connections with the expected three. Done means determining whether the extra connection is created by StackExchange.Redis or by the Azure Redis service, with a confirmed explanation or fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, redis
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.