添加项目文件。
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace IM.Commons
|
||||
{
|
||||
public interface IRedisService
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T">缓存对象类型</typeparam>
|
||||
/// <param name="key">缓存索引值</param>
|
||||
/// <param name="value">要缓存的对象</param>
|
||||
/// <param name="expiration">过期时间</param>
|
||||
/// <returns></returns>
|
||||
Task SetAsync<T>(string key, T value, TimeSpan? expiration = null);
|
||||
/// <summary>
|
||||
/// 获取缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key">缓存索引</param>
|
||||
/// <returns></returns>
|
||||
Task<T?> GetAsync<T>(string key);
|
||||
/// <summary>
|
||||
/// 删除缓存
|
||||
/// </summary>
|
||||
/// <param name="key">缓存索引</param>
|
||||
/// <returns></returns>
|
||||
Task RemoveAsync(string key);
|
||||
}
|
||||
|
||||
public static class RedisServiceExtension
|
||||
{
|
||||
public static IServiceCollection AddRedisCache(this IServiceCollection services)
|
||||
{
|
||||
return services.AddScoped<IRedisService, RedisCacheService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user