首页 / REDIS / abp框架里使用Redis
abp框架里使用Redis
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了abp框架里使用Redis,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3505字,纯文字阅读大概需要6分钟。
内容图文
![abp框架里使用Redis](/upload/InfoBanner/zyjiaocheng/915/a03361ae3e18454e8251166843e8bc73.jpg)
首先引用 nuget Abp.RedisCache
在 appsettings.json加上Redis服务器配置
"RedisCache": { "ConnectionString": "xx.xx.xx.xx:5001,password=xxx", "DatabaseId": "-1" }
然后在项目的依赖文件 AbpModule里加上Redis相关配置
1 using Abp.AutoMapper; 2 using Abp.Modules; 3 using Abp.Reflection.Extensions; 4 using Abp.Runtime.Caching.Redis; 5 using System; 6 7 namespace BossHelper 8 { 9 [DependsOn( 10 typeof(BossHelperCoreModule), 11 typeof(AbpAutoMapperModule), 12 typeof(AbpRedisCacheModule) 13 )] 14 15 public class BossHelperApplicationModule : AbpModule 16 { 17 public override void PreInitialize() 18 { 19 int DatabaseId = -1; 20 int.TryParse(ConfigHelper.GetAppSetting("App", "RedisCache:DatabaseId"), out DatabaseId); 21 //配置使用Redis缓存 22 Configuration.Caching.UseRedis(options => 23 { 24 options.ConnectionString = ConfigHelper.GetAppSetting("App", "RedisCache:ConnectionString"); 25 options.DatabaseId = DatabaseId; 26 }); 27 28 //配置所有Cache的默认过期时间为2小时 29 Configuration.Caching.ConfigureAll(cache => 30 { 31 cache.DefaultSlidingExpireTime = TimeSpan.FromHours(2); 32 }); 33 34 //配置指定的Cache过期时间为10分钟 35 Configuration.Caching.Configure("BossAssistant", cache => 36 { 37 cache.DefaultSlidingExpireTime = TimeSpan.FromMinutes(10); 38 }); 39 40 Configuration.Authorization.Providers.Add<BossHelperAuthorizationProvider>(); 41 } 42 43 public override void Initialize() 44 { 45 var thisAssembly = typeof(BossHelperApplicationModule).GetAssembly(); 46 47 IocManager.RegisterAssemblyByConvention(thisAssembly); 48 49 Configuration.Modules.AbpAutoMapper().Configurators.Add( 50 // Scan the assembly for classes which inherit from AutoMapper.Profile 51 cfg => cfg.AddProfiles(thisAssembly) 52 ); 53 } 54 } 55 }? ? 最后使用
1)实例化
![abp框架里使用Redis - 文章图片](/upload/getfiles/0001/2021/5/9/20210509100842242.jpg)
![abp框架里使用Redis - 文章图片](/upload/getfiles/0001/2021/5/9/20210509100842367.jpg)
public ILogger Logger { get; set; } private readonly string AppId = ConfigHelper.GetAppSetting("App", "AppID"); private readonly string AppSecret = ConfigHelper.GetAppSetting("App", "AppSecret"); private readonly ICacheManager _cacheManage; private readonly IRepository<wxapp_user, long> _wxappUserRepository; private readonly IRepository<boss_admin, long> _bossAdminRepository; private readonly IRepository<BossQrcode, long> _bossQrCodeRepository; private readonly IRepository<boss_role, long> _bossRoleRepository; private readonly IRepository<shopinfo, long> _shopInfoRepository; public WxappUserService(IRepository<wxapp_user, long> wxappUserRepository, IRepository<boss_admin, long> bossAdminRepository, IRepository<BossQrcode, long> bossQrCodeRepository, IRepository<boss_role, long> bossRoleRepository, IRepository<shopinfo, long> shopInfoRepository, ICacheManager cacheManage) { _wxappUserRepository = wxappUserRepository; _bossAdminRepository = bossAdminRepository; _bossQrCodeRepository = bossQrCodeRepository; _bossRoleRepository = bossRoleRepository; _shopInfoRepository = shopInfoRepository; Logger = NullLogger.Instance; _cacheManage = cacheManage; }View Code
2)SET
_cacheManage.GetCache("BossAssistant").Set(codeResult.openid, codeResult.session_key);
3)GET
var sessionKey = _cacheManage.GetCache("BossAssistant").Get(model.openid, (val) => { return val; }) as string;
4)查看
内容总结
以上是互联网集市为您收集整理的abp框架里使用Redis全部内容,希望文章能够帮你解决abp框架里使用Redis所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。