.net core 6 redis操作类

/// 
/// redis操作类
/// 
public class RedisTool
{
    /// 
    /// 构造
    /// 
    /// 
    public RedisTool(IConfiguration configuration)
    {
        string redis = configuration.GetValue("redis");

        CSRedisClient cSRedis = new CSRedis.CSRedisClient(redis);

        RedisHelper.Initialization(cSRedis);
    }

    /// 
    /// 得到值
    /// 
    /// 
    /// 
    public string GetRedisString(string str)
    {
        return RedisHelper.Get(str);
    }

    /// 
    /// 得到值
    /// 
    /// 
    /// 
    public bool SetRedisString(string key, string value)
    {
        return RedisHelper.Set(key, value);
    }

    /// 
    /// 设置列表
    /// 
    /// 
    /// 
    public string SetRedisList(string key, string value)
    {
        //列表前后插入
        RedisHelper.RPush(key, value).ToString();
        return RedisHelper.LPush(key, value).ToString();
    }

    /// 
    /// 设置哈希值
    /// 
    /// 表名
    /// 字段名
    /// 值
    /// 
    public bool SetRedisHSet(string key, string field, string value)
    {
        //相同时会更新
        return RedisHelper.HSet(key, field, value);
    }

    /// 
    /// 得到哈希值
    /// 
    /// 
    /// 
    /// 
    public string GetRedisHSet(string key, string field)
    {
        return RedisHelper.HGet(key, field);
    }

    /// 
    /// 给值增加指定的值
    /// 
    /// 
    /// 
    /// 
    public long SetRedisIncre(string key, long value)
    {
        return RedisHelper.IncrBy(key, value);
    }

    /// 
    /// 是否包含
    /// 
    /// 
    /// 
    /// 
    public bool RedisSIsMember(string key, string value)
    {
        //是否包含
        return RedisHelper.SIsMember(key, value);
    }
}

1、配置appsettings.json:

"redis": "127.0.0.1:6379,password=,defaultDatabase=1,poolsize=50,ssl=false,writeBuffer=10240"

2、用的大神国产包:CSRedisCore

你可能感兴趣的:(.netcore,redis)