using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.RedisCache { public class Smi_Expert_StoreVibrationRecord { private const string Flag = "smi-expert";//标志 //最后一条记录 private const string _lastRecord = "LastRecord"; //Redis客户端辅助类对象 private readonly RedisClientHelper _redisClient = new RedisClientHelper(); //创建RedisKey private static string CreateRedisKey(string objectId) { return $"{RedisKeyHelper.CreateKey(Flag)}:{objectId}"; } /// /// 设置最后一条记录 /// public void SetLastRecord(Model.Smi_Expert_VibrationRecord model) { if (model == null) return; var redisKey = CreateRedisKey(model.ObjectId); _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.Smi_Expert_VibrationRecord GetLastRecord(string ObjectId) { var redisKey = CreateRedisKey(ObjectId); return _redisClient.HashGetJson(redisKey,_lastRecord); } /// /// 获取最后一条记录 /// public List GetLastRecord(IEnumerable ObjectIds) { if (ObjectIds == null || ObjectIds.Count() < 1) return default; return ObjectIds.Select(x => GetLastRecord(x)).Where(x => x != null).ToList(); } /// /// 获取最后一条记录StartWith /// public List GetLastRecordStartWith(string objectId) { var key = CreateRedisKey(objectId); var allKeys = _redisClient.AllKeyStartWidth(key); if (allKeys == null || allKeys.Count < 1) return default; var vm_list = new List(); foreach (var redisKey in allKeys) { var vm = _redisClient.HashGetJson(redisKey, _lastRecord); if (vm != null) { vm_list.Add(vm); } } return vm_list; } } }