adding redis read/writes
This commit is contained in:
@@ -1,11 +1,40 @@
|
||||
using System;
|
||||
using ctstone.Redis;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
namespace NOCQ
|
||||
{
|
||||
public class RedisDataase
|
||||
{
|
||||
public RedisDataase(){}
|
||||
|
||||
public static async Task SaveAlert(IAlert alert)
|
||||
{
|
||||
using (var redis = new RedisClientAsync(ConfigurationManager.AppSettings["DBQueueKey"],
|
||||
Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
|
||||
Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"])
|
||||
))
|
||||
{
|
||||
await redis.LPush(ConfigurationManager.AppSettings["DBQueueKey"], alert);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static async Task<Alert> GetNextAlert()
|
||||
{
|
||||
using (var redis = new RedisClientAsync(ConfigurationManager.AppSettings["DBQueueKey"],
|
||||
Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
|
||||
Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"])
|
||||
))
|
||||
{
|
||||
var ts = await redis.RPop(ConfigurationManager.AppSettings["DBQueueKey"]);
|
||||
|
||||
return JsonConvert.DeserializeObject<Alert>(ts);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace NOCQ
|
||||
{
|
||||
public class Alert : IAlert
|
||||
{
|
||||
|
||||
public DateTime TimeStamp {get; set;}
|
||||
public string Source {get;set;}
|
||||
public string System {get;set;}
|
||||
|
||||
@@ -55,6 +55,10 @@
|
||||
<HintPath>..\..\packages\AE.Net.Mail.1.7.9.1\lib\net45\AE.Net.Mail.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
<package id="AE.Net.Mail" version="1.7.9.1" targetFramework="net45" />
|
||||
<package id="csredis" version="1.4.7.1" targetFramework="net45" />
|
||||
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user