Jagadeesh
Jagadeesh

Reputation: 1790

StackExchange.Redis: No connection is available to service this operation. UnableToConnect on HOST:PORT/Interactive

I am trying to connect REDIS database (GCP-memorystore-Redis) from C#. While set values to Redis, I'm getting exception like:

No connection is available to service this operation. UnableToConnect on 10.0.0.2:6379/Interactive, Initializing, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 10s ago, last-write: 10s ago, unanswered-write: 115s ago, keep-alive: 180s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.519.65453; IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=1,Max=32767), Local-CPU: n/a

I am using StackExchange.Redis version:2.0.519

Code:

               IDatabase redisDB;
                try {
                    ConnectionMultiplexer redis = ConnectionMultiplexer.Connect($"{host}:{port},resolvedns=1,abortConnect=False,keepAlive=180,connectTimeout=10000");
                   
                    redisDB = redis.GetDatabase();
                    
                    if(redisDB==null)
                    {
                     **//Getting Error**
                      var messageId = redisDB.StreamAdd("event_stream", "foo_name", "bar_value");
                     //redisDB.StringSet("RedisKey", "RedisValue");
                    }
                  }

(or) I am also trying to set values by using below code as well. (getting same issue)

redisDB.StringSet("RedisKey", "RedisValue");

could you please help on this.

Upvotes: 1

Views: 4794

Answers (3)

Ruben Schild
Ruben Schild

Reputation: 1

I guess you're trying to connect to a local redis connection? Anyways, I don't think my suggestion is going to work but I felt like replying anyway. I had the same issue when I was trying to connect to my Azure Cache for Redis.

I solved it by simply putting sslprotocols=tls12 inside the connection string. Then it looked something like this: azure.cache.for.redis.conn.string:6380,password:foobar,ssl=true,sslprotocols=tls12,abortConnect=false.

I hope you've already fixed it, otherwise I hope this may be of good help :).

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1062780

It looks like this might be mostly a formatting/concatenation issue, in which case the simplest approach is: don't do that. There is a strongly typed object model that makes it very hard to get wrong:

var config = new ConfigurationOptions {
    EndPoints = {
        new DnsEndPoint(host, port),
        // new IPEndPoint(host, port), // <== or this if 'host' is an IPAddress
    },
    ResolveDns = true,
    AbortOnConnectFail = false,
    KeepAlive = 180,
    ConnectTimeout = 10000,
};
var muxer = ConnectionMultiplexer.Connect(config);

Internally, if you give it a string, the first thing it is going to do is parse the string to create exactly the above, so you might as well just go direct!

Upvotes: 2

It seems that your variable "host" in ConnectionMultiplexer connectionstring isn't correct. Look at your exception "UnableToConnect on IPAddress:6379/Interactive". So your variable "port" is correct and it has value 6379. Perhaps you have wrong conversion of your "host" variable to string. So you have in it type of variable (IPAddress) instead of real value.

Upvotes: 1

Related Questions