using Znyc.CloudCar.Caching; using Znyc.CloudCar.Configuration; using Znyc.CloudCar.IServices.CaChe; using Znyc.CloudCar.Model.Dtos.Banner; using Znyc.CloudCar.Model.Dtos.CardIntro; using Znyc.CloudCar.Model.Dtos.Certification; using Znyc.CloudCar.Model.Dtos.Dictionary; using Znyc.CloudCar.Model.Dtos.Recharge; using Znyc.CloudCar.Model.Dtos.User; using Znyc.CloudCar.Model.Entities; namespace Znyc.CloudCar.Services.Cache { public class CacheService : ICacheService { private readonly IRedisOperationRepository _redisCache; public CacheService( IRedisOperationRepository redisCache) { _redisCache = redisCache; } #region Dictionary /// /// 设置数据字典缓存 /// /// /// public async Task SetDictionaryAsync(List output) { await _redisCache.SetAsync(GlobalCacheKeyVars.DictionaryList, output); } /// /// 获取数据字典缓存 /// /// public async Task> GetDictionaryAsync() { return await _redisCache.GetAsync>(GlobalCacheKeyVars.DictionaryList); } /// /// 删除数据字典缓存 /// /// public async Task RemoveDictionaryAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.DictionaryList); } #endregion #region User /// /// 设置用户缓存 /// /// /// /// public async Task SetUserAsync(long userId, UserOutput user) { string key = string.Format(GlobalCacheKeyVars.User, userId); await _redisCache.SetAsync(key, user); } /// /// 删除用户缓存 /// /// /// public async Task RemoveUserAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.User, userId); await _redisCache.DelAsync(key); } /// /// 获取用户缓存 /// /// /// public async Task GetUserAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.User, userId); return await _redisCache.GetAsync(key); } #endregion User #region PageView /// /// 同步浏览量缓存 /// /// /// public async Task SetPageViewAsync(string member, double score) { return await _redisCache.ZAddAsync(GlobalCacheKeyVars.PageView, member, score); } /// /// 浏览量自增 /// /// /// public async Task SetIncrPageViewAsync(long productId) { return await _redisCache.ZIncrByAsync(GlobalCacheKeyVars.PageView, productId.ToString()); } /// /// 删除浏览量缓存 /// /// public async Task RemovePageViewAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.PageView); } /// /// 获取浏览量缓存 /// /// /// /// public async Task> GetPageViewAsync() { return await _redisCache.ZRevRangeWithScoresAsync(GlobalCacheKeyVars.PageView); } /// /// 获取浏览量总条数缓存 /// /// public async Task GetPageViewCountAsync() { return await _redisCache.ZCardAsync(GlobalCacheKeyVars.PageView); } #endregion PageView #region Browse /// /// 获取浏览记录总条数缓存 /// /// /// public async Task GetBrowseCountAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.BrowseList, userId); return await _redisCache.ZCardAsync(key); } /// /// 设置浏览记录缓存 /// /// /// /// /// public async Task SetBrowseAsync(long userId, string member, double score) { string key = string.Format(GlobalCacheKeyVars.BrowseList, userId); return await _redisCache.ZAddAsync(key, member, score); } /// /// 获取浏览记录缓存 /// /// /// /// /// public async Task> GetBrowseAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.BrowseList, userId); return await _redisCache.ZRevRangeWithScoresAsync(key); } #endregion #region 实名认证 /// /// 设置实名认证缓存 /// /// /// /// public async Task SetCertificationAsync(long userId, CertificationOutput certificationOutput) { string key = string.Format(GlobalCacheKeyVars.Certification, userId); await _redisCache.SetAsync(key, certificationOutput); } /// /// 删除实名认证缓存 /// /// /// public async Task RemoveCertificationAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.Certification, userId); await _redisCache.DelAsync(key); } /// /// 获取实名认证缓存 /// /// /// public async Task GetCertificationAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.Certification, userId); return await _redisCache.GetAsync(key); } #endregion Certification #region UnreadMessage /// /// 同步未读信息缓存 /// /// /// /// public async Task SetUnreadMessageAsync(long userId, IDictionary list) { string key = string.Format(GlobalCacheKeyVars.UnreadMessage, userId); foreach (var item in list) { await _redisCache.HSetAsync(key, item.Key, item.Value); } } /// /// 修改未读信息缓存 /// /// /// /// /// public async Task UpdateUnreadMessageAsync(long userId, string filed, string value) { string key = string.Format(GlobalCacheKeyVars.UnreadMessage, userId); await _redisCache.HSetAsync(key, filed, value); } /// /// 删除未读信息缓存 /// /// /// public async Task RemoveUnreadMessageAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.UnreadMessage, userId); await _redisCache.DelAsync(key); } /// /// 获取未读信息缓存 /// /// public async Task> GetUnreadMessageAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.UnreadMessage, userId); return await _redisCache.HGetAllAsync(key); } #endregion UnreadMessage #region 用户注册信息滚动提示 /// /// 设置注册用户list /// /// /// public async Task SetRegistUserListAsync(string member, double score) { await _redisCache.ZAddAsync(GlobalCacheKeyVars.RegisteredUserlist, member, score); } /// /// 获取注册用户list /// /// public async Task> GetRegistUserListAsync(long start, long stop) { return await _redisCache.ZRemRangeByRankAsync(GlobalCacheKeyVars.RegisteredUserlist, start, stop); } #endregion #region Banner /// /// 设置广告缓存 /// /// /// public async Task SetBannerListAsync(List list) { await _redisCache.SetAsync(GlobalCacheKeyVars.BannerList, list, TimeSpan.FromDays(31)); } /// /// 获取广告缓存 /// /// public async Task> GetBannerListAsync() { return await _redisCache.GetAsync>(GlobalCacheKeyVars.BannerList); } /// /// 删除广告缓存 /// /// public async Task RemoveBannerListAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.BannerList); } #endregion #region Recharge充值活动 /// /// 设置充值活动缓存 /// /// /// public async Task SetRechargeAsync(RechargeOutput output) { await _redisCache.SetAsync(GlobalCacheKeyVars.RechargeList, output); } /// /// 获取充值活动缓存 /// /// public async Task GetRechargeAsync() { return await _redisCache.GetAsync(GlobalCacheKeyVars.RechargeList); } /// /// 删除充值活动缓存 /// /// public async Task RemoveRechargeAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.RechargeList); } #endregion ProductInfo #region 优惠卡信息 /// /// 设置优惠卡信息缓存 /// /// /// public async Task SetCardIntroListAsync(List list) { await _redisCache.SetAsync(GlobalCacheKeyVars.CardIntroList, list, TimeSpan.FromDays(31)); } /// /// 获取优惠卡信息缓存 /// /// public async Task> GetCardIntroListAsync() { return await _redisCache.GetAsync>(GlobalCacheKeyVars.CardIntroList); } /// /// 删除优惠卡信息缓存 /// /// public async Task RemoveCardIntroListAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.CardIntroList); } #endregion #region 用户修改次数 /// /// 同步用户修改次数缓存 /// /// /// public async Task SetUserUpdateCountAsync(string member, double score) { return await _redisCache.ZAddAsync(GlobalCacheKeyVars.UserUpdateCount, member, score); } /// /// 用户修改次数自增 /// /// /// public async Task SetIncrUserUpdateCountAsync(long userId) { return await _redisCache.ZIncrByAsync(GlobalCacheKeyVars.UserUpdateCount, userId.ToString()); } /// /// 删除用户修改次数缓存 /// /// public async Task RemoveUserUpdateCountAsync() { await _redisCache.DelAsync(GlobalCacheKeyVars.UserUpdateCount); } /// /// 获取用户修改次数缓存 /// /// public async Task> GetUserUpdateCountAsync() { return await _redisCache.ZRevRangeWithScoresAsync(GlobalCacheKeyVars.UserUpdateCount); } #endregion UserUpdateCount #region 设备管理 public async Task SetEquipmentAsync(EquipmentEntity equipment, long userId) { string key = string.Format(GlobalCacheKeyVars.UserEquipment, userId); await _redisCache.SetAsync(key, equipment); } public async Task GetEquipmentAsync(long userId) { string key = string.Format(GlobalCacheKeyVars.UserEquipment, userId); return await _redisCache.GetAsync(key); } #endregion } }