public Dictionary <string, HashSet <string> > ConvertToDictionary(List <TModel> list) { Dictionary <string, HashSet <string> > dictionary = new Dictionary <string, HashSet <string> >(); object propertyValue = null; string propertyValueStr = ""; foreach (var property in redisIndexProperties) { foreach (var model in list) { propertyValue = property.GetValue(model, null); if (propertyValue == null) { continue; } propertyValueStr = propertyValue.ToString(); if (string.IsNullOrWhiteSpace(propertyValueStr)) { continue; } bool isExisted = false; string key = GetKey(property.Name, propertyValueStr); string value = RedisCommon.GetPrimaryKeysValuesStr <TModel>(model, primaryKeysProperties); if (string.IsNullOrEmpty(value)) { continue; } foreach (var item in dictionary) { if (item.Key == key) { item.Value.Add(value); isExisted = true; break; } } if (!isExisted) { dictionary.Add(key, new HashSet <string>(new List <string>() { value })); } propertyValue = null; propertyValueStr = null; } } return(dictionary); }
public void SaveData(List <TModel> list) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var model in list) { string field = RedisCommon.GetPrimaryKeysValuesStr <TModel>(model, primaryKeysProperties); if (!string.IsNullOrEmpty(field)) { dictionary.Add(field, JsonSerializer.SerializeToString <TModel>(model)); } } redisHelper.HSet(GetKey(), dictionary); }
public string GetField(TModel model) { return(RedisCommon.GetPrimaryKeysValuesStr <TModel>(model, primaryKeysProperties)); }