using System.Collections.Generic; namespace DataTransferService.RedisHelp { public class DataHelper { #region 方法 -> 从Redis缓存中判断是否已存在数据 public static bool ContainData(string tableName, string KeyValue) { //从Redis的db0数据库中获取信息 T InfoModel = RedisHelp.Redis.HashGet(0, tableName, KeyValue); if (InfoModel != null) { return true; } return false; } #endregion #region 方法 -> 将数据记录Redis缓存中 /// /// 将数据记录Redis缓存中 /// /// 泛型对象 /// 保存到redis数据中的list数据集 /// 数据表名称 /// 数据键值 /// public static bool RecordToRedis(T ObjectModel, string tableName, string KeyName) { //获取item对象类型 var pros = typeof(T).GetProperties(); string KeyValue = string.Empty; //字段值 foreach (var item in pros) { if (item.Name == KeyName) { KeyValue = item.GetValue(ObjectModel, null).ToString(); break; } } //写入Redis的db0数据库 return RedisHelp.Redis.HashSet(0, tableName, KeyValue, ObjectModel); } /// /// 将数据记录Redis缓存中 /// /// 泛型对象 /// 保存到redis数据中的list数据集 /// 数据表名称 /// 数据键值 /// public static bool RecordToRedis(List listData, string tableName, string KeyName) { bool flag = false; foreach (T model in listData) { //获取item对象类型 var pros = typeof(T).GetProperties(); string KeyValue = string.Empty; //字段值 foreach (var item in pros) { if (item.Name == KeyName) { KeyValue = item.GetValue(model, null).ToString(); break; } } //写入Redis的db0数据库 flag = RedisHelp.Redis.HashSet(0, tableName, KeyValue, model); } return flag; } #endregion } }