[英]Unable to connect AWS Redis cache in .net C# - RedisConnectionException: 'No connection is active/available to service this operation
[英]how to connection aws redis with c#
如何使用 c# 連接 aws redis?
我創建 aws redis 完成並創建 linux 主機以連接 redis 成功,
但是當我使用 c# 代碼進行連接時,我失敗了。
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;
}
}
錯誤信息
沒有連接處於活動狀態/可用於服務此操作:GET hello; UnableToConnect on test.qzgpeh.ng.0001.use2.cache.amazonaws.com:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, 未完成: 0, last-read: 5s ago, last-write: 5s前,保持活動狀態:60 秒,state:正在連接,管理器:10 個中的 10 個可用,最后一次心跳:從不,全局:5 秒前,v:2.1.58.34321,mc:1/1/0,管理器:10 個可用, 客戶端名稱: HAUSER, IOCP: (Busy=0,Free=1000,Min=12,Max=1000), WORKER: (Busy=0,Free=32767,Min=12,Max=32767), v: 2.1.58.34321
我該如何解決?
如果有人遇到類似問題,請發布。
我試圖從 Elastic Beanstalk.Net 應用程序訪問 Redis 數據並面臨類似問題。
就我而言,這是來自安全組的問題。 我按照以下步驟
Redis 安全組入站規則
.NET 內核示例代碼
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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.