|
@@ -1,4 +1,5 @@ |
|
|
using ServiceStack.Redis; |
|
|
using ServiceStack.Redis; |
|
|
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
|
namespace Communication |
|
|
namespace Communication |
|
|
{ |
|
|
{ |
|
@@ -10,19 +11,28 @@ namespace Communication |
|
|
private RedisHelper() { } |
|
|
private RedisHelper() { } |
|
|
RedisClient client; |
|
|
RedisClient client; |
|
|
|
|
|
|
|
|
public void Connect() |
|
|
|
|
|
|
|
|
public async Task<bool> ConnectAsync() |
|
|
{ |
|
|
{ |
|
|
if (client == null) |
|
|
|
|
|
{ |
|
|
|
|
|
client = new RedisClient("124.222.238.75", 16000, "123456", 1); |
|
|
|
|
|
Thread.Sleep(1000); |
|
|
|
|
|
//while (!client.HasConnected) |
|
|
|
|
|
//{ |
|
|
|
|
|
// client = new RedisClient("124.222.238.75", 16000, "123456"); |
|
|
|
|
|
// Thread.Sleep(1000); |
|
|
|
|
|
//} |
|
|
|
|
|
} |
|
|
|
|
|
if (client.HasConnected) BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("Redis 连接成功"); |
|
|
|
|
|
|
|
|
return await Task.Factory.StartNew(new Func<bool>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
if (client == null) |
|
|
|
|
|
{ |
|
|
|
|
|
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("开始连接 Redis"); |
|
|
|
|
|
client = new RedisClient("124.222.238.75", 16000, "123456", 1); |
|
|
|
|
|
client.ConnectTimeout = 5000; |
|
|
|
|
|
Stopwatch sw = new Stopwatch(); |
|
|
|
|
|
sw.Start(); |
|
|
|
|
|
while (!client.IsSocketConnected()) |
|
|
|
|
|
{ |
|
|
|
|
|
if (sw.ElapsedMilliseconds >= client.ConnectTimeout) break; |
|
|
|
|
|
Thread.Sleep(1000); |
|
|
|
|
|
} |
|
|
|
|
|
string status = client.IsSocketConnected() ? "成功" : "失败"; |
|
|
|
|
|
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog($"Redis 连接{status}"); |
|
|
|
|
|
} |
|
|
|
|
|
return client.IsSocketConnected(); |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary> |
|
|
/// <summary> |
|
|