/// <summary> /// Caches all the meta categories and values. /// </summary> private void CacheMetaContext() { //metaCategory->(meta value->score) var metaCategoryScores = base.GetMetaValuesWithScores(); foreach (var categoryPair in metaCategoryScores) { var categoryId = categoryPair.Key; var categoryKey = $"{Prefix}:_m:{categoryId}"; foreach (var val in categoryPair.Value) { var fullKey = $"{categoryKey}:{val.Key}"; var cntHash = new HashEntry("count", val.Value.Count); var scoreHash = new HashEntry("score", val.Value.Value); _cacher.SetHash(fullKey, cntHash); _cacher.SetHash(fullKey, scoreHash); } } //metaCategory->(metaValue->element set) var metaCategoryValueSets = base.GetEntityMetaValues(); foreach (var categoryPair in metaCategoryValueSets) { uint categoryId = categoryPair.Key; var categoryKey = $"{Prefix}:_mv:{categoryId}"; var categoryValues = categoryPair.Value; foreach (var metaVal in categoryValues) { var isSorted = SetIsSorted(categoryId, metaVal.Key); var fullKey = $"{categoryKey}:{metaVal.Key}"; var set = metaVal.Value; if (isSorted) { //Generate scores from x _cacher.SortedSetAddAll(fullKey, set.Select(x => { double score = 0; try { score = (double)double.Parse(x); } catch (Exception ex) { Trace.WriteLine($"Malformed data (double): {ex.Message}"); } var entry = new SortedSetEntry((RedisValue)x, score); return(entry); })); } else { _cacher.SetAddAll(fullKey, set.Select(x => (RedisValue)x)); } } } }
public void SetUserInfo(string key, string hashField, UserInfo value) { key = $"{_stringKeyPrefix}{key}"; _redisCacher.SetHash <UserInfo>(key, hashField, value); }