Skip to content

RedisDatabase StringSet or StringGet - No connection is active/available to service this operation #1424

@tomasfabian

Description

@tomasfabian

Hi,
I'm trying to get or set a string key from redis database after OnConnectionRestored, but the command sometimes failes:

    public void Connect()
    {
      var configuration = new ConfigurationOptions
      {
        AbortOnConnectFail = false,
        ConnectTimeout = 3000,
        SyncTimeout = 5000,
        KeepAlive = 180,
        EndPoints =
        {
          {
            url, Port
          }
        }
      };

      var connectionMultiplexer = ConnectionMultiplexer.Connect(configuration);
      connectionMultiplexer.GetDatabase();

      connectionMultiplexer.ConnectionRestored += OnConnectionRestored;

      var subscriber = connectionMultiplexer.GetSubscriber();
    }    

    private void OnConnectionRestored(object sender, ConnectionFailedEventArgs args)
    {
      var connectionMultiplexer = (ConnectionMultiplexer) sender;
      if (connectionMultiplexer.IsConnected)
      {
        var redisDatabase = connectionMultiplexer.GetDatabase();

        var setStringResult = redisDatabase.StringSet(new[]
        {
          new KeyValuePair<RedisKey, RedisValue>("key", "value")
        });
      }
    }

StackExchange.Redis.RedisConnectionException: 'No connection is active/available to service this operation: SET key, mc: 1/1/0, mgr: 10 of 10 available, clientName: FABIAN-PC, IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=1,Free=32766,Min=8,Max=32767), v: 2.1.30.38891'

FailureType = UnableToResolvePhysicalConnection

at StackExchange.Redis.ConnectionMultiplexer.ThrowFailed[T](TaskCompletionSource1 source, Exception unthrownException) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2575 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()_

Is it possible to observe somehow IDatabase IsConnected? Or is there a problem somewhere else?

Thank you, Tomas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions