src/05_Cache/Cache.Redis/RedisCacheProvider.cs

(完整代码) 1KB

using System;
using System.Threading.Tasks;
using Mkh.Cache.Abstractions;

namespace Mkh.Cache.Redis;

public class RedisCacheProvider : ICacheProvider
{
    private readonly RedisHelper _helper;

    public RedisCacheProvider(RedisHelper helper)
    {
        _helper = helper;
    }

    public Task<string> Get(string key)
    {
        return _helper.StringGetAsync<string>(key);
    }

    public Task<T> Get<T>(string key)
    {
        return _helper.StringGetAsync<T>(key);
    }

    public Task<bool> Set<T>(string key, T value)
    {
        return _helper.StringSetAsync(key, value);
    }

    public Task<bool> Set<T>(string key, T value, int expires)
    {
        return _helper.StringSetAsync(key, value, new TimeSpan(0, 0, expires, 0));
    }

    public Task<bool> Set<T>(string key, T value, DateTime expires)
    {
        return _helper.StringSetAsync(key, value, expires - DateTime.Now);
    }

    public Task<bool> Set<T>(string key, T value, TimeSpan expires)
    {
        return _helper.StringSetAsync(key, value, expires);
    }

    public Task<bool> Remove(string key)
    {
        return _helper.KeyDeleteAsync(key);
    }

    public Task<bool> Exists(string key)
    {
        return _helper.KeyExistsAsync(key);
    }

    public Task RemoveByPrefix(string prefix)
    {
        return _helper.DeleteByPrefix(prefix);
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。