using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.RedisCache
{
///
/// 监测记录缓存辅助类
///
public class MonitorRecordCacheHelper
{
//Redis客户端辅助类对象
private readonly RedisClientHelper _redisClient = new RedisClientHelper();
private static string CreateRedisKey(long monitorPointId)
{
return $"linux_test:{monitorPointId}";
}
//最后一条记录
private const string _lastRecord = "last-record";
#region 最后一条记录
///
/// 设置最后一条记录
///
public void SetLastRecord(Model.MonitorRecord model)
{
if (model == null)
return;
var redisKey = CreateRedisKey(model.MonitorPointID);
_redisClient.HashSetJosn(redisKey, _lastRecord, model);
}
///
/// 设置最后一条记录
///
public void SetLastRecord(IEnumerable list)
{
if (list == null || list.Count() < 1)
return;
foreach (var item in list)
{
SetLastRecord(item);
}
}
///
/// 获取最后一条记录
///
public Model.MonitorRecord GetLastRecord(long monitorPointId)
{
var redisKey = CreateRedisKey(monitorPointId);
return _redisClient.HashGetJson(redisKey, _lastRecord);
}
///
/// 获取最后一条记录
///
public List GetLastRecord(IEnumerable monitorPointIds)
{
if (monitorPointIds == null || monitorPointIds.Count() < 1)
return default;
return monitorPointIds.Select(x => GetLastRecord(x)).Where(x => x != null).ToList();
}
#endregion
}
}