/// <summary> /// Removes an item from the cache /// </summary> /// <param name="key">Cache key</param> /// <param name="partitionName"> /// Optional value for the name of a partition in the application cache. Partitions can be a good way to categorize or group /// certain types of items in the cache together. /// </param> public async Task RemoveAsync(string key, string partitionName = "") { if (string.IsNullOrEmpty(key)) { return; } // Remove it from the partition if (string.IsNullOrEmpty(partitionName)) // Remove the object from regular cache { await _redisDatabase.KeyDeleteAsync(key).ConfigureAwait(false); } else // Else remove the object from the redis hash set. { var partitionKey = ComposePartitionKey(partitionName); await _redisDatabase.HashDeleteAsync(partitionKey, key).ConfigureAwait(false); var timeoutPartitionKey = ComposeTimeoutPartitionKey(partitionName); await _redisDatabase.HashDeleteAsync(timeoutPartitionKey, key).ConfigureAwait(false); } }
/// <summary> /// 从 hash 中移除指定字段 /// </summary> /// <param name="redisKey"></param> /// <param name="hashField"></param> /// <returns></returns> public async Task <bool> HashDeleteAsync(string redisKey, string hashField) { redisKey = GetKeyForRedis(redisKey); return(await _database.HashDeleteAsync(redisKey, hashField)); }