• Abp Vnext 替换Redis的实现为csredis


    Host项目安装csredis的nuget包和data protect包并

    移除 Microsoft.Extensions.Caching.StackExchangeRedis Microsoft.AspNetCore.DataProtection.StackExchangeRedis 

    添加

    Cacheing.CSRedis

    AspNetCore.DataProtection.CSRedis

    然后在xxModule.cs修改

    添加using

    using CSRedis;

    using Microsoft.Extensions.Caching.Distributed;

    在ConfigureService()中找到这段儿代码

    context.Services.AddStackExchangeRedisCache(options =>
    {
        options.Configuration = configuration["Redis:Configuration"];
    };

    if (!hostingEnvironment.IsDevelopment())
    {
      var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
      context.Services.AddDataProtection()
          .PersistKeysToStackExchangeRedis(redis, "XXX-DataProtection-Keys");
    }

    替换为

    var connection = new CSRedisClient(configuration["Redis:Configuration"]);
                context.Services.AddSingleton<IDistributedCache>(new Microsoft.Extensions.Caching.Redis.CSRedisCache(connection));
    RedisHelper.Initialization(connection);//如果需要使用csredis提供的redis原生功能则需要加此行来初始化csredis的单例
    if (!hostingEnvironment.IsDevelopment()) { context.Services .AddDataProtection() .PersistKeysToCSRedis(connection, "XXX-Protection-Keys"); }

    PS:连接串如果有密码或者更改databaseId的话需要按照csredis的规则来,也就是原始的redis连接串格

    "Redis": {

        "Configuration": "127.0.0.1:6379,password=123,defaultDatabase=13,prefix=my_"

    },

    如果是哨兵集群则需要在把上文中new CSRedisClient(configuration["Redis:Configuration"])改为new CSRedisClient(configuration["Redis:Configuration"], new []{ "192.169.1.10:26379", "192.169.1.11:26379", "192.169.1.12:26379"}),后边那三个是哨兵节点ip端口,也可以自己放入配置文件读取

     

  • 相关阅读:
    Asp.net Mvc 身份验证、异常处理、权限验证(拦截器)实现代码
    在执行Action之间检验是否登录
    链接服务器使用方法
    easyui-treegrid节点选择
    SQLServer 存储过程详解
    转载:SQL Server编程基本语法
    【转】SQL Server编程游标
    机器学习14—SVD学习笔记
    机器学习13—PCA学习笔记
    FP Tree算法原理总结(转载)
  • 原文地址:https://www.cnblogs.com/turingguo/p/AbpVnext_CSRedis.html
Copyright © 2020-2023  润新知