how to use c# to connection aws redis?
I create aws redis done and create linux host to conntection redis is successed,
but when I use c# code to connection, I get failed.
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("test.qzgpeh.ng.0001.use2.cache.amazonaws.com:6379,abortConnect=false");
});
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
Error Message
No connection is active/available to service this operation: GET hello; UnableToConnect on test.qzgpeh.ng.0001.use2.cache.amazonaws.com:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 5s ago, last-write: 5s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 5s ago, v: 2.1.58.34321, mc: 1/1/0, mgr: 10 of 10 available, clientName: HAUSER, IOCP: (Busy=0,Free=1000,Min=12,Max=1000), WORKER: (Busy=0,Free=32767,Min=12,Max=32767), v: 2.1.58.34321
how I can to fix it?
Posting if someone facing a similar issue.
I was trying to access Redis data from the Elastic Beanstalk.Net application and facing a similar issue.
In my case, it was an issue from a security group. I followed the below steps
Redis Security Group Inbound Rule
.NET Core Sample Code
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;
private readonly IDatabase cache;
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("******-redis-cache.yq8meb.0001.aps1.cache.amazonaws.com:6379,abortConnect=false");
});
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
this.cache = Connection.GetDatabase();
}
[BindProperty]
public string StartTime { get; set; }
public void OnGet()
{
StartTime = this.cache.StringGet("StartTime");
if (string.IsNullOrWhiteSpace(StartTime))
{
StartTime = DateTime.Now.ToString();
this.cache.StringSet("StartTime", StartTime);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.