.net core Redis客户端Shiny.Redis包库的使用


一、说明

Shiny.Redis是一个redis客户端,基于新生命团队newlife.redis的封装,支持.net core3,.net5,.net6

二、安装

nuget直接搜索Shiny.Redis安装

Shiny.Redis的注入有两种方式,一种是直接字符串注入,一种是通过读取配置文件注入

        /// 
        /// 添加redis服务
        /// 
        /// 
        /// 
        /// 
        public static void AddRedisCacheManager(this IServiceCollection services, string redisConfiguration = null)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            if (!string.IsNullOrEmpty(redisConfiguration))
            {
                services.AddSingleton(x => new RedisCacheManager(redisConfiguration));

            }
            else
            {
                services.AddSingleton();
            }

        }

通过字符串注入

 services.AddRedisCacheManager("server=127.0.0.1:6379;password=xxx;db=3");

通过配置文件

"ConnectionStrings": {
    "Redis": "server=127.0.0.1:6379;password=xxx;db=3"
  },

三、使用

 直接通过构造函数注入

直接使用封装好的方法就行