Exemple #1
0
        /// <summary>
        /// Fetch value synchronously from Redis and deserialize as MsgPack object <typeparam name="type">T</typeparam>.
        /// </summary>
        /// <typeparam name="T">A message pack serializable object.</typeparam>
        /// <param name="keyType">Key type to lookup.</param>
        /// <param name="keyIdentifier">Key identifier too lookup. If unused, set to ""</param>
        /// <param name="flags">Flags to pass to Redis.</param>
        /// <returns>Instance of MsgPack object of type <typeparam name="type">T</typeparam>.</returns>
        public T GetValue <T>(RedisDBKeyTypes keyType, string keyIdentifier, RedisCommandFlags flags = RedisCommandFlags.None)
            where T : MessagePackSerializableObject, new()
        {
            var keyString = BuildKeyString(keyType, keyIdentifier);
            var data      = _db.StringGet(keyString, (CommandFlags)flags);

            return(!data.HasValue ? null : DeserializeMsgPack <T>(keyString, data));
        }
Exemple #2
0
        /// <summary>
        /// Fetch value synchronously from Redis and return raw string value.
        /// </summary>
        /// <param name="keyType">Key type to lookup.</param>
        /// <param name="keyIdentifier">Key identifier too lookup. If unused, set to ""</param>
        /// <param name="flags">Flags to pass to Redis.</param>
        /// <returns>String value stored in Redis.</returns>
        public string GetRawValue(RedisDBKeyTypes keyType, string keyIdentifier, RedisCommandFlags flags = RedisCommandFlags.None)
        {
            var keyString = BuildKeyString(keyType, keyIdentifier);
            var data      = _db.StringGet(keyString, (CommandFlags)flags);

            LogDebug("Getting raw Redis data", keyString, data.ToString());

            return(data);
        }
Exemple #3
0
 /// <summary>
 /// Asynchronously set keyType to hold the string value. If keyType already holds a value, it is overwritten, regardless of its type.
 /// </summary>
 /// <param name="keyType">RedisDBKey value to convert to string and lookup.</param>
 /// <param name="obj">MsgPack object to serialize.</param>
 /// <param name="expiry">(optional) TimeSpan date to expire value at.</param>
 /// <param name="when">Allows you to specify criteria for setting object. Update only if not-exist, etc.</param>
 /// <param name="commandFlags">Flags to pass to Redis.</param>
 /// <returns>True or false depending on if value was successfully set.</returns>
 public async Task <bool> SetValueAsync(
     RedisDBKeyTypes keyType,
     MessagePackSerializableObject obj,
     TimeSpan?expiry = null,
     SetWhen when    = SetWhen.Always,
     RedisCommandFlags commandFlags = RedisCommandFlags.None)
 {
     return(await SetValueAsync(keyType, "", obj, expiry, when, commandFlags));
 }
Exemple #4
0
        /// <summary>
        /// Asynchronously set keyType to hold the string value. If keyType already holds a value, it is overwritten, regardless of its type.
        /// </summary>
        /// <param name="keyType">Redis keyType to set.</param>
        /// <param name="keyIdentifier">suffix added to keyType for unique keys. If unused, set to ""</param>
        /// <param name="data">String to insert for data.</param>
        /// <param name="expiry">(optional) TimeSpan date to expire value at.</param>
        /// <param name="when">Allows you to specify criteria for setting object. Update only if not-exist, etc.</param>
        /// <param name="commandFlags">Flags to pass to Redis.</param>
        /// <returns>True or false depending on if value was successfully set.</returns>
        public Task <bool> SetRawValueAsync(
            RedisDBKeyTypes keyType,
            string keyIdentifier,
            string data,
            TimeSpan?expiry = null,
            SetWhen when    = SetWhen.Always,
            RedisCommandFlags commandFlags = RedisCommandFlags.None)
        {
            string keyString = keyType + "_" + keyIdentifier;

#if DEBUG
            LogDebug("[Redis Async Set Raw]: {0}" + expiry, keyString, data.ToString());
#endif
            return(_db.StringSetAsync(keyString, data, expiry, (When)when, (CommandFlags)commandFlags));
        }
Exemple #5
0
        /// <summary>
        /// Asynchronously set keyType to hold the string value. If keyType already holds a value, it is overwritten, regardless of its type.
        /// </summary>
        /// <param name="keyType">Redis keyType to set.</param>
        /// <param name="keyIdentifier">suffix added to keyType for unique keys. If unused, set to ""</param>
        /// <param name="obj">MsgPack object to serialize.</param>
        /// <param name="expiry">(optional) TimeSpan date to expire value at.</param>
        /// <param name="when">Allows you to specify criteria for setting object. Update only if not-exist, etc.</param>
        /// <param name="commandFlags">Flags to pass to Redis.</param>
        /// <returns>True or false depending on if value was successfully set.</returns>
        public Task <bool> SetValueAsync(
            RedisDBKeyTypes keyType,
            string keyIdentifier,
            MessagePackSerializableObject obj,
            TimeSpan?expiry = null,
            SetWhen when    = SetWhen.Always,
            RedisCommandFlags commandFlags = RedisCommandFlags.None)
        {
            string keyString = keyType + "_" + keyIdentifier;

#if DEBUG
            LogDebug("[Redis Async Set]: {0}" + expiry, keyString, obj.Serialize().ToString());
#endif

            return(_db.StringSetAsync(keyString, obj.Serialize(), expiry, (When)when, (CommandFlags)commandFlags));
        }
Exemple #6
0
        /// <summary>
        /// Fetch value asynchronously from Redis and return raw string value.
        /// </summary>
        /// <param name="keyType">Key type to lookup.</param>
        /// <param name="keyIdentifier">Key identifier too lookup. If unused, set to ""</param>
        /// <param name="flags">Flags to pass to Redis.</param>
        /// <returns>String value stored in Redis.</returns>
        public async Task <string> GetRawValueAsync(RedisDBKeyTypes keyType, string keyIdentifier, RedisCommandFlags commandFlags = RedisCommandFlags.None)
        {
            var keyString = BuildKeyString(keyType, keyIdentifier);
            var data      = await _db.StringGetAsync(keyString, (CommandFlags)commandFlags);

            LogDebug("Getting raw Redis data", keyString, data.ToString());

            return(data);
        }
Exemple #7
0
 /// <summary>
 /// Fetch value asynchronously from Redis and deserialize as MsgPack object <typeparam name="type">T</typeparam>.
 /// </summary>
 /// <typeparam name="T">A message pack serializable object.</typeparam>
 /// <param name="rawKeyType">RedisDBKey value to convert to string and lookup.</param>
 /// <param name="flags">Flags to pass to Redis.</param>
 /// <returns>Instance of MsgPack object of type <typeparam name="type">T</typeparam>.</returns>
 public async Task <T> GetValueAsync <T>(RedisDBKeyTypes rawKeyType, RedisCommandFlags flags = RedisCommandFlags.None)
     where T : MessagePackSerializableObject, new()
 {
     return(await GetValueAsync <T>(rawKeyType, "", flags));
 }
Exemple #8
0
 /// <summary>
 /// Fetch value synchronously from Redis and deserialize as MsgPack object <typeparam name="type">T</typeparam>.
 /// </summary>
 /// <typeparam name="T">A message pack serializable object.</typeparam>
 /// <param name="rawKeyType">RedisDBKey value to convert to string and lookup.</param>
 /// <param name="flags">Flags to pass to Redis.</param>
 /// <returns>Instance of MsgPack object of type <typeparam name="type">T</typeparam>.</returns>
 public T GetValue <T>(RedisDBKeyTypes rawKeyType, RedisCommandFlags flags = RedisCommandFlags.None)
     where T : MessagePackSerializableObject, new()
 {
     return(GetValue <T>(rawKeyType, "", flags));
 }