private StronglyTypedDictionary <T> Map(RedisValue[] values, params Expression <Func <T, object> >[] properties) { // ensure same amount of Redis result values is present as requested using expression if (values.Length != properties.Length) { throw new ArgumentException("Object properties not matching"); } var dictionary = new StronglyTypedDictionary <T>(Serializer); for (int i = 0; i < properties.Length; i++) { if (values[i].HasValue && properties[i].IsPropertySerializable()) { dictionary.Add(properties[i], Serializer.Deserialize <dynamic>(values[i])); } else { dictionary.Add(properties[i], values[i]); } } return(dictionary); }
private HashEntry[] TransformDictionaryIntoHashEntries(StronglyTypedDictionary <T> updates) { // ensure that value is not null, otherway exception is throw, use emtpy string instead return(updates.Where(c => c.Value != null).Select(s => new HashEntry(s.Key, s.Value.ToString())).ToArray()); }
public async Task HashSetAsync(string key, StronglyTypedDictionary <T> updates) { await GetDatabase(ConfigurationOptions.Database).HashSetAsync(ConfigurationOptions.KeyNamespace + key, TransformDictionaryIntoHashEntries(updates), ConfigurationOptions.PrefferedWriteFlags); }