public async Task <List <PostInfo> > GetRecentPostAsync(int count) { using (MVCBlogContext Context = new MVCBlogContext()) { Func <List <int> > GetIds = () => { return(Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList()); }; //var res = Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList(); var res = await GetIds.StartAsync <List <int> >(); if (res != null && res.Count > 0) { List <PostInfo> list = new List <PostInfo>(); foreach (var item in res) { string key = RedisKeyHelper.GetPostKey(item); Func <PostInfo> GetDb = () => GetFromDB(item); PostInfo info = RedisHelper.GetEntity <PostInfo>(key, GetDb); list.Add(info); } return(list); } return(new List <PostInfo>()); } }
public static bool Update(PlayerbasisModel model) { string redisKey = RedisKeyHelper.GetRedisKeyName(RedisKeyConfig.Playerbasis, model.PlayerId.ToString()); redisCacheHelper.StringSet(redisKey, model, CommonConfig.DefRedisExpiry); return(Update(model, nameof(model.PlayerId))); }
public static bool InsertSuccess(AtlasscheduleModel model) { string redisKey = RedisKeyHelper.GetRedisKeyName(RedisKeyConfig.AtlasSchedule, model.PlayerId.ToString()); redisCacheHelper.StringSet(redisKey, model, CommonConfig.DefRedisExpiry); return(BaseBLL.InsertSuccess(model)); }
public static bool StartCacheRedisCheck() { bool canStart = false; try { RedisCacheHelper redisCacheHelper = new RedisCacheHelper(); //思路:getset使用单个redis,pubsub使用redis集群 //直接看redis官网 //百度搜索:ServiceStack.Redis.RedisResponseException //https://stackoverflow.com/questions/36436212/unexpected-reply-on-high-volume-scenario-using-servicestack-redis //https://stackoverflow.com/questions/30223105/moved-exception-with-redis-cluster-stackexchange-redis //ClusterConfiguration clusterConfiguration //ClusterNode //ConfigurationOptions //设置哨兵 sentinel //RedisSentinel //------------------------------- //▲百度搜索:redis 哨兵 主从 集群 //------------------------------- //RedisSentinelResolver // SentinelInfo string redisKey = RedisKeyHelper.GetRedisKeyName(RedisKeyConfig.Test, 1.ToString()); redisCacheHelper.StringSet(redisKey, new TestResp { PlayerId = 1 }, CommonConfig.DefRedisExpiry); var res = redisCacheHelper.StringGet <TestResp>(redisKey); canStart = true; } catch (Exception ex) { Console.WriteLine("【redis】异常23323:" + ex.ToString()); } return(canStart); }
public static List <GoodsModel> GetListAll(int playerId, int belongsTo, out bool fromCache) { fromCache = false; string redisKey = RedisKeyHelper.GetRedisKeyName(RedisKeyConfig.Goods, playerId.ToString(), belongsTo.ToString()); var list = redisCacheHelper.StringGet <List <GoodsModel> >(redisKey); if (list != null) { fromCache = true; return(list); } else { list = GoodsDAL.GetListAll(playerId, belongsTo); redisCacheHelper.StringSet(redisKey, list, CommonConfig.DefRedisExpiry); return(list); } }
public static PlayerbasisModel GetSingleOrDefault(int playerId, out bool fromCache) { fromCache = false; string redisKey = RedisKeyHelper.GetRedisKeyName(RedisKeyConfig.Playerbasis, playerId.ToString()); var cacheModel = redisCacheHelper.StringGet <PlayerbasisModel>(redisKey); if (cacheModel != null) { fromCache = true; return(cacheModel); } else { var model = new PlayerbasisModel(); model = GetSingleOrDefault(model, new KeyValue <int> { Key = nameof(model.PlayerId), Value = playerId }); redisCacheHelper.StringSet(redisKey, model, CommonConfig.DefRedisExpiry); return(model); } }
public override string GetModelKey(int id) { return(RedisKeyHelper.GetPostKey(id)); }