Exemplo n.º 1
0
 /// <summary>
 /// Returns an enumerator that iterates through the collection.
 /// </summary>
 /// <returns>
 /// An enumerator that can be used to iterate through the collection.
 /// </returns>
 public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator()
 {
     foreach (var hashKey in RedisDb.HashKeys(RedisKey))
     {
         var redisValue = RedisDb.HashGet(RedisKey, hashKey);
         yield return(new KeyValuePair <TKey, TValue>(KeySerializer.Deserialize <TKey>(hashKey), ValueSerializer.Deserialize <TValue>(redisValue)));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets or sets the <see cref="TValue"/> with the specified key.
 /// </summary>
 /// <value>
 /// The <see cref="TValue"/>.
 /// </value>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 public TValue this[TKey key]
 {
     get
     {
         var redisValue = RedisDb.HashGet(RedisKey, KeySerializer.Serialize(key));
         return(redisValue.IsNull ? default(TValue) : ValueSerializer.Deserialize <TValue>(redisValue));
     }
     set
     {
         Add(key, value);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <param name="key">The key whose value to get.</param>
        /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value" /> parameter. This parameter is passed uninitialized.</param>
        /// <returns>
        /// true if the object that implements <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the specified key; otherwise, false.
        /// </returns>
        public bool TryGetValue(TKey key, out TValue value)
        {
            var redisValue = RedisDb.HashGet(RedisKey, KeySerializer.Serialize(key));

            if (redisValue.IsNull)
            {
                value = default(TValue);
                return(false);
            }

            value = ValueSerializer.Deserialize <TValue>(redisValue);
            return(true);
        }